在两个远程服务器之间 rsync 文件时,出现错误,指出在远程服务器上找不到 rsync 命令
我尝试在两台服务器之间 rsync 文件,
rsync -avlzp /source user@server:/destination
但收到错误消息,指出
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(635) [sender=3.0.2]
两台服务器上都安装了 rsync is。 我究竟做错了什么? 我也尝试过
rsync -av -e "ssh -l ssh-user" /source server:/destination
同样的结果。
我主要尝试使用 rsync,以便它只复制存在的差异...
谢谢
I'm trying to rsync files between two servers with
rsync -avlzp /source user@server:/destination
but instead I get errors stating
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(635) [sender=3.0.2]
but rsync is installed on both servers. What am I doing wrong? I've also tried
rsync -av -e "ssh -l ssh-user" /source server:/destination
with the same result.
I'm mainly trying to use rsync so that it only copies over differences if they exist...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于这个问题有很多好的信息,包括上面的答案。 但就我而言,我是源计算机和目标计算机的管理员,我希望了解发生了什么以及哪些“正确”的配置选项可以使这个问题消失。 我还没有完全成功,但其他人可能会发现这些信息很有用。
正如上面的答案所述,运行交互式 shell 时,rsync 可能位于远程计算机上的路径中,但通过 ssh 运行 rsync 时则不然。 正如 Siddesh 在 http:// 式指定远程 rsync 的路径来解决:
siddesh-bg.blogspot.com/2009/02/rsync-command-not-found-error-even.html 这可以通过从本地 shell显 管理员 我想解决问题,而不仅仅是解决问题。 OldSchool 在 https:/ 上发布了有用的故障排除方法/groups.google.com/group/comp.unix.solaris/browse_thread/thread/0a06a4d382d752d8?pli=1
他建议你找出远程计算机上正在为你运行的 shell,然后 PATH 是什么在那里建立:
Tom Feiner 在 为什么SSH远程命令比手动运行获得的环境变量少?讨论了SSH命令执行shell的环境搭建。
OldSchool 还指出,“man sshd_config”提供了一些有关 ssh 会话如何获取环境的信息。 sshd_config 设置“PermitUserEnvironment”可以设置为允许 sshd 处理服务器端用户的 ~/.ssh/environment 以及 AuthorizedKeysFile 文件中的环境选项。 默认为否。
因此,使用默认的 sshd_config 设置,路径将由默认 shell 构建。 如果您的 ssh 命令请求交互式会话 (ssh user@host),则远程服务器上的默认 shell 将执行交互式登录,这可能会产生您期望的 PATH。 但是,如果您正在启动 rsync 的 ssh 会话(rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination),那么远程服务器会给出您是一个 SSH 命令执行 shell,它是一个非交互式 shell。 就我而言,远程非交互式 shell (bash) 不执行 /etc/profile,因为它仅对交互式 shell 或带有 --login 选项的非交互式 shell 执行此操作。 我可以这样强迫:
我还研究了丹尼尔·巴雷特和丹尼尔·巴雷特。 Richard Silverman 的“SSH The Secure Shell”(O'Reilly 2001),并在 /etc/ssh/sshrc 中设置一个 PATH,我希望这将使 rsync 可用于 SSH 命令执行 shell,但是,/etc/ssh/sshrc 在用户 shell 或命令被调用,显然它的环境没有传递给该 shell 或命令。
此时,我将对 rsync 命令行选项感到满意,即:
因为我担心如果我更改 sshd_config 设置“PermitUserEnvironment”,那么我可能会无法通过服务器的安全审核。 当我对我们组织的安全审计有了更多的经验后,我可能会重新考虑这一点。
There is a lot of good information around about this problem, including the answer above. But in my case, I am an administrator on both the source and destination machines, and I wished to understand what was going on and what "right" configuration options would make this problem go away. I haven't been entirely successful but it seems likely that others may find this information useful.
As the answer above states, rsync may be in the path on the remote machine when running an interactive shell, but not when running rsync by ssh. As Siddesh notes at http://siddesh-bg.blogspot.com/2009/02/rsync-command-not-found-error-even.html this can be solved by explicitly specifying the path to the remote rsync from your local shell:
But as an administrator I wanted to fix the problem, not just work around it. OldSchool posted a useful troubleshooting approach at https://groups.google.com/group/comp.unix.solaris/browse_thread/thread/0a06a4d382d752d8?pli=1
He suggest you find out what shell is being run for you on the remote machine, then what PATH has been established there:
Tom Feiner has a nice post at Why does an SSH remote command get fewer environment variables then when run manually? that discusses the environment establishment of the SSH command execution shell.
OldSchool also noted that "man sshd_config" provides some information about how an ssh session gets an environment. The sshd_config setting "PermitUserEnvironment" can be set to allow a user's ~/.ssh/environment on the server side and environment options in the AuthorizedKeysFile file to be processed by sshd. The default is no.
So with default sshd_config settings the path is going to be built by your default shell. If your ssh command requests an interactive session (ssh user@host) then on the remote server the default shell will do an interactive login, which will probably result in the PATH that you expect. But if you are initiating an ssh session for rsync (rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination) then the remote server gives you a SSH command execution shell that is a non-interactive shell. In my case, the remote non-interactive shell (bash) is not executing /etc/profile, because it only does that for interactive shells or non-interactive shells with the --login option. I could force it like this:
I also studied Daniel Barrett & Richard Silverman's "SSH The Secure Shell" (O'Reilly 2001) and set a PATH in /etc/ssh/sshrc that I hoped would make rsync available to SSH command execution shells, but, /etc/ssh/sshrc is executed before the users shell or command is invoked, and apparently it's environment is not passed on to that shell or command.
At this point I am going to be satisfied with the rsync command line option, i.e.:
because I am concerned that if I change the sshd_config setting "PermitUserEnvironment" then I will probably fail a security audit on my servers. I may revisit this after I have more experience with our organization's security audits.
运行交互式 shell 时,rsync 可能位于远程计算机上的路径中,但通过 ssh 运行 rsync(使用非交互式 shell)时则不会。 例如,.bashrc 通常仅针对交互式 shell 运行,因此如果您的路径在那里定义,则在远程端运行 rsync --server 时不会对其进行解析。 尝试/etc/profile。 有关更多详细信息,请参阅 bash(1)。
您可以使用
--rsync-path
来指定远程计算机上 rsync 二进制文件的路径。rsync may be in the path on the remote machine when running an interactive shell, but not when running rsync by ssh (with a non-interactive shell). .bashrc is normally only run for interactive shells, for example, so if your path is defined there, it will not be parsed when running
rsync --server
on the remote end. Try /etc/profile. See bash(1) for more details.You can use
--rsync-path
to specify the path to the rsync binary on the remote machine.