非 root 用户 Rsync 守护进程 rsync 错误:在 main.c(1675) [Receiver=3.1.3] 处启动客户端-服务器协议时出错(代码 5)

非 root 用户 Rsync 守护进程 rsync 错误:在 main.c(1675) [Receiver=3.1.3] 处启动客户端-服务器协议时出错(代码 5)

我在 Ubuntu 20.04 桌面上,并使用以下基本框架备份远程客户端 Ubuntu 20.04 服务器:

/etc/sudoers
non-root-username ALL= NOPASSWD:/usr/bin/rsync

从桌面终端我执行:
rsync -a -e "ssh -i /path/to/id_rsa" --rsync-path="sudo rsync" [email protected]::data /local/path

在远程客户端服务器上,我有以下内容/etc/rsyncd.conf

root@admin:~# cat /etc/rsyncd.conf 
# Global configuration of the rsync service
pid file = /var/run/rsyncd.pid
hosts allow = 123.123.123.123
log file = /var/log/rsync.log
# Username and group for working with backups
uid = non-root-username
gid = non-root-username
# Don't allow to modify the source files
read only = yes
# Data source information
[data]
use chroot = false
strict modes = false
path = /backups
list = yes
auth users = non-root-username
secrets file = /etc/rsyncd.passwd

在我的/etc/rsyncd.passwd档案里,我有:

root@admin:~# cat /etc/rsyncd.passwd 
non-root-username:password

我有以下权限/etc/rsyncd.conf

root@admin:~# stat /etc/rsyncd.conf 
  File: /etc/rsyncd.conf
  Size: 471         Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144028      Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: ( 1001/non-root-username)
Access: 2022-05-21 13:38:46.797769245 +0800
Modify: 2022-05-21 13:38:42.641735637 +0800
Change: 2022-05-21 13:55:52.384894170 +0800

并且,我对“/etc/rsyncd.passwd”具有以下权限

root@admin:~# stat /etc/rsyncd.passwd 
  File: /etc/rsyncd.passwd
  Size: 31          Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144040      Links: 1
Access: (0640/-rwxrwxr-x)  Uid: (    0/    root)   Gid: ( 1001/non-root-username)
Access: 2022-05-21 13:38:06.989448597 +0800
Modify: 2022-05-21 13:37:37.473212811 +0800
Change: 2022-05-21 13:37:37.473212811 +0800

但无论我尝试哪种 UID/GID 和权限组合,我总是收到相同的错误:

Ubuntu 20.04.4 LTS  <-- showing that it successfully connects, but doesn't authenticate
@ERROR: access denied to data from UNKNOWN (0.0.0.0)
rsync error: error starting client-server protocol (code 5) at main.c(1675) [Receiver=3.1.3]

我已经阅读了 rysnc 手册页并尝试了他们的故障排除建议...我不知道我错过了什么...

有什么建议么?

答案1

我回过头来想出了答案。核心问题是它hosts allow = 123.123.123.123 屏蔽了我的 IP(是的,我反复检查了 IP 地址是否正确,但这个功能似乎出了问题)

我对上述问题的最终解决方案是:

root@admin:~# cat /etc/rsyncd.conf 
# Global configuration of the rsync service
pid file = /var/run/rsyncd.pid
#hosts allow = 123.123.123.123  <-- hashed out
log file = /var/log/rsync.log
# Username and group for working with backups
uid = root
gid = root
# Don't allow to modify the source files
read only = yes
# Data source information
[data]
use chroot = false
#strict modes = false <-- (defaults to true)
path = /backups
list = yes
auth users = non-root-username
secrets file = /etc/rsyncd.passwd

在我的 /etc/rsyncd.passwd 文件中,我有:

root@admin:~# cat /etc/rsyncd.passwd 
non-root-username:password

我对 /etc/rsyncd.conf 具有以下权限:

root@admin:~# stat /etc/rsyncd.conf 
  File: /etc/rsyncd.conf
  Size: 471         Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144028      Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: ( 1001/root)
Access: 2022-05-21 13:38:46.797769245 +0800
Modify: 2022-05-21 13:38:42.641735637 +0800
Change: 2022-05-21 13:55:52.384894170 +0800

并且,我有以下权限/etc/rsyncd.passwd

root@admin:~# stat /etc/rsyncd.passwd 
  File: /etc/rsyncd.passwd
  Size: 31          Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 144040      Links: 1
Access: (0640/-rwxrwxr-x)  Uid: (    0/    root)   Gid: ( 1001/root)
Access: 2022-05-21 13:38:06.989448597 +0800
Modify: 2022-05-21 13:37:37.473212811 +0800
Change: 2022-05-21 13:37:37.473212811 +0800

从本地备份服务器返回的最终命令: rsync -a -e "ssh -i /path/to/id_rsa" --rsync-path="sudo rsync" [email protected]::data /local/path

相关内容