在 ubuntu 服务器之间使用 rsync:// 协议时 rsync 权限被拒绝

在 ubuntu 服务器之间使用 rsync:// 协议时 rsync 权限被拒绝

我正在尝试使用该协议将文件从 host2 同步到 host1(均运行 Ubuntu Server 20.04),而无需输入任何密码rsync://

在主机2上:

$ cat /etc/rsyncd.conf
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock

[folder]
    path = /home/username
    comment = rsync folder
    read only = false
    list = yes

然后我跑sudo systemctl start rsync

$ cat /var/log/rsyncd.log 
2021/03/25 01:07:51 [8035] rsyncd version 3.1.3 starting, listening on port 873

在主机1上:

$ rsync /home/username/test.txt rsync://host2:/folder
rsync: mkstemp "/.test.txt.UHerWZ" (in folder) failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]

在主机2上:

$ tail -F /var/log/rsyncd.log
2021/03/25 03:13:00 [9212] name lookup failed for host1: Name or service not known
2021/03/25 03:13:00 [9212] connect from UNKNOWN (host1)
2021/03/25 03:13:00 [9212] rsync to folder/ from UNKNOWN (host1)
2021/03/25 03:13:00 [9212] receiving file list
2021/03/25 03:13:00 [9212] rsync: mkstemp "/.test.txt.KRLgUO" (in folder) failed: Permission denied (13)
2021/03/25 03:13:00 [9212] sent 122 bytes  received 95 bytes  total size 5

是什么导致许可被拒绝?我需要在 中定义用户名和密码吗/etc/rsyncd.conf

答案1

nobody默认情况下,当 rsyncd 以 root 身份运行时,它会在进行传输之前更改为用户。如果你的路径/home/username不属于这个id,等等,你会得到错误。通常,您需要添加一个 id 以在您的节中运行(通常还将组 id 设置为该用户的默认值),如下所示:

[folder]
    path = /home/username
    uid = username
    gid = *
    ...

相关内容