SSH与SCP可正常使用,但通过SSH的Rsync同步失败求助
问题描述
从Linux机器向群晖(Synology)执行rsync同步时失败,但SSH和SCP均可通过密钥认证正常访问,权限配置无异常。
正常执行的SCP命令
~# scp /tmp/foo.bar backupch:/tmp foo.bar 100% 9 0.5KB/s 00:00
失败的Rsync命令
rsync /tmp/foo.bar backupch:/tmp -e 'ssh -v'
Rsync调试输出
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022 debug1: Reading configuration data /root/.ssh/config debug1: /root/.ssh/config line 14: Applying options for backupch debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to myhost.mydomain [*.*.*.*] port 2222. debug1: Connection established. debug1: identity file /root/.ssh/ipdch.backup.key type -1 debug1: identity file /root/.ssh/ipdch.backup.key-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2 debug1: compat_banner: match: OpenSSH_8.2 pat OpenSSH* compat 0x04000000 debug1: Authenticating to myhost.mydomain:2222 as 'backup' debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ssh-ed25519 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: SSH2_MSG_KEX_ECDH_REPLY received debug1: Server host key: ssh-ed25519 SHA256:bbl6asZ3Qc+DnOV8hKPDWdlnJtE2yXMQxb1jyInlc+c debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: Host '[myhost.mydomain]:2222' is known and matches the ED25519 host key. debug1: Found key in /root/.ssh/known_hosts:1 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: Will attempt key: /root/.ssh/ipdch.backup.key explicit debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/ipdch.backup.key Authenticated to myhost.mydomain ([*.*.*.*]:2222) using "publickey". debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: filesystem debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0 debug1: client_input_hostkeys: searching /root/.ssh/known_hosts for [myhost.mydomain]:2222 / (none) debug1: client_input_hostkeys: searching /root/.ssh/known_hosts2 for [myhost.mydomain]:2222 / (none) debug1: client_input_hostkeys: hostkeys file /root/.ssh/known_hosts2 does not exist debug1: Remote: /var/services/homes/backup/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding debug1: Sending environment. debug1: channel 0: setting env LANG = "en_US.UTF-8" debug1: Sending command: rsync --server -e.LsfxCIvu . /tmp debug1: client_global_hostkeys_private_confirm: server used untrusted RSA signature algorithm ssh-rsa for key 0, disregarding debug1: update_known_hosts: known hosts file /root/.ssh/known_hosts2 does not exist Permission denied, please try again. debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0 debug1: channel 0: free: client-session, nchannels 1 rsync: connection unexpectedly closed (0 bytes received so far) [sender] Transferred: sent 3412, received 2716 bytes, in 0.1 seconds Bytes per second: sent 56899.8, received 45293.1 debug1: Exit status 1 rsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]
原因分析与解决方案
从日志可见,SSH已成功完成认证,但执行服务器端命令rsync --server -e.LsfxCIvu . /tmp时返回Permission denied,核心原因是群晖端的backup用户无权限执行rsync服务器端命令,或rsync路径被限制。
具体原因:
- 群晖默认对非管理员用户的SSH可执行命令范围有限制,SCP仅需基础文件传输权限,而rsync需要执行服务器端的
rsync --server命令,该操作可能不在允许列表内。 backup用户未被授予群晖RSync应用权限。- rsync的绝对路径未被正确识别,或用户环境变量未包含rsync所在路径。
解决步骤:
- 方法1:开启用户RSync权限
登录群晖DSM,进入控制面板 > 用户与群组 > 用户,编辑backup用户,在应用程序权限中找到RSync并勾选允许。 - 方法2:指定rsync绝对路径
在rsync命令中显式指定服务器端rsync的路径,示例:rsync /tmp/foo.bar backupch:/tmp -e 'ssh -v --rsync-path=/usr/bin/rsync' - 方法3:检查authorized_keys限制
查看群晖端/var/services/homes/backup/.ssh/authorized_keys文件,若存在command=限制规则,需确保允许执行rsync命令,或在安全前提下移除该限制。
内容的提问来源于stack exchange,提问作者klodoma
相关产品推荐
相关产品推荐

