我一直在尝试以下命令:

rsync -rvz --progress --remove-sent-files ./dir user@host:2222/path

SSH在端口2222上运行,但是rsync仍然尝试使用端口22,然后抱怨找不到路径,因为它当然不存在。

我想知道是否有可能在非标准的ssh端口上rsync到远程主机。


当前回答

有点跑题了,但也许能帮到别人。如果你需要传递密码和端口,我建议使用sshpass包。命令行命令看起来像这样: sshpass -p "password" rsync -avzh -e 'ssh -p PORT312' root@192.xx.xxx.xxx:/dir_on_host/

其他回答

我在Mike Hike Hostetler的网站上找到了这个解决方案,它非常适合我。

# rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/

有点跑题了,但也许能帮到别人。如果你需要传递密码和端口,我建议使用sshpass包。命令行命令看起来像这样: sshpass -p "password" rsync -avzh -e 'ssh -p PORT312' root@192.xx.xxx.xxx:/dir_on_host/

运行Linux Ubuntu我使用以下命令

Rsync -rvz——rsh='ssh -p2222'——progress——remove-sent-files ./dir user@host:/path

这将把rsh环境变量作为端口2222上的ssh连接传递。这里的所有其他方法似乎都不适合我的linux风格,所以我想把我的方法提供给其他人。

您还可以通过使用-e命令行选项或设置RSYNC_RSH环境变量来指定您喜欢的任何远程shell。

Rsync文档: https://download.samba.org/pub/rsync/rsync.1

另一种选择,在你运行rsync的主机上,在ssh配置文件中设置端口,即:

cat ~/.ssh/config
Host host
    Port 2222

然后rsync将通过ssh与端口2222通信:

rsync -rvz --progress --remove-sent-files ./dir user@host:/path

我的2美分,在一个系统用户中,你可以在/etc/ssh/ssh_config上设置端口,然后rsync将使用这里设置的端口