代码之家  ›  专栏  ›  技术社区  ›  Silfheed

在两个远程服务器之间执行rsync文件时,出现错误,说明在远程服务器上找不到rsync命令

  •  9
  • Silfheed  · 技术社区  · 17 年前

    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 是 安装在两台服务器上。我做错了什么?我也试过了

    rsync -av -e "ssh -l ssh-user" /source server:/destination
    

    我主要尝试使用rsync,这样它只复制差异,如果它们存在的话。。。

    2 回复  |  直到 17 年前
        1
  •  17
  •   crb    17 年前

    在运行交互式shell时,rsync可能位于远程计算机上的路径中,但在通过ssh运行rsync(使用非交互式shell)时,rsync可能不在路径中。例如,bashrc通常只针对交互式shell运行,因此如果在其中定义了路径,则在运行时不会对其进行解析 rsync --server 在远端。试试/etc/profile。看见 bash(1) 更多细节。

    --rsync-path 指定远程计算机上rsync二进制文件的路径。

        2
  •  7
  •   Community Mohan Dere    9 年前

    如上所述,当运行交互式shell时,rsync可能位于远程计算机上的路径中,但当通过ssh运行rsync时,rsync可能不在路径中。正如Siddesh在 http://siddesh-bg.blogspot.com/2009/02/rsync-command-not-found-error-even.html

    rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination
    

    但作为一名管理员,我想解决这个问题,而不仅仅是解决它。OldSchool在网站上发布了一个有用的故障排除方法 https://groups.google.com/group/comp.unix.solaris/browse_thread/thread/0a06a4d382d752d8?pli=1

    他建议您找出在远程计算机上为您运行的shell,然后在那里建立了什么路径:

    ssh user@host 'echo $SHELL' 
    ssh user@host 'echo $PATH' 
    

    汤姆·费纳在纽约有一个不错的职位 Why does an SSH remote command get fewer environment variables then when run manually?

    OldSchool还指出,“mansshd_config”提供了一些关于ssh会话如何获得环境的信息。sshd_config设置“PermitUserEnvironment”可以设置为允许用户在服务器端的~/.ssh/环境和AuthorizedKeysFile文件中的环境选项由sshd处理。默认值为否。

    因此,使用默认的sshd_配置设置,路径将由默认shell构建。如果您的ssh命令请求交互式会话(sshuser@host)然后,在远程服务器上,默认shell将进行交互式登录,这可能会产生您期望的路径。但是,如果您正在为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执行该操作。我可以这样强迫它:

    ssh user@host 'echo $PATH;source /etc/profile;echo $PATH' 
    

    我还研究了丹尼尔·巴雷特&Richard Silverman的“SSH The Secure Shell”(O'Reilly 2001),并在/etc/SSH/sshrc中设置了一个路径,我希望该路径能够使rsync可用于SSH命令执行Shell,但是,/etc/SSH/sshrc是在调用用户Shell或命令之前执行的,显然它的环境并没有传递给该Shell或命令。

    此时,我将对rsync命令行选项感到满意,即:

    rsync-av--rsync path=/usr/local/bin/rsync-e“ssh-l ssh user”/source server:/destination
    

    因为我担心如果我更改sshd_config设置“PermitUserEnvironment”,那么我的服务器上的安全审计可能会失败。在我对我们组织的安全审计有了更多的经验之后,我可能会再次讨论这个问题。

    推荐文章