我一直在尝试以下命令:
rsync -rvz --progress --remove-sent-files ./dir user@host:2222/path
SSH在端口2222上运行,但是rsync仍然尝试使用端口22,然后抱怨找不到路径,因为它当然不存在。
我想知道是否有可能在非标准的ssh端口上rsync到远程主机。
我一直在尝试以下命令:
rsync -rvz --progress --remove-sent-files ./dir user@host:2222/path
SSH在端口2222上运行,但是rsync仍然尝试使用端口22,然后抱怨找不到路径,因为它当然不存在。
我想知道是否有可能在非标准的ssh端口上rsync到远程主机。
当前回答
另一种选择,在你运行rsync的主机上,在ssh配置文件中设置端口,即:
cat ~/.ssh/config
Host host
Port 2222
然后rsync将通过ssh与端口2222通信:
rsync -rvz --progress --remove-sent-files ./dir user@host:/path
其他回答
运行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
我在Mike Hike Hostetler的网站上找到了这个解决方案,它非常适合我。
# rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/
另一种选择,在你运行rsync的主机上,在ssh配置文件中设置端口,即:
cat ~/.ssh/config
Host host
Port 2222
然后rsync将通过ssh与端口2222通信:
rsync -rvz --progress --remove-sent-files ./dir user@host:/path
你的命令行应该是这样的:
rsync -rvz -e 'ssh -p 2222' --progress ./dir user@host:/path
这很好-我一直在使用它,不需要任何新的防火墙规则-只是注意SSH命令本身是用引号括起来的。
使用“rsh选项”。例如:
rsync -avz --rsh='ssh -p3382' root@remote_server_name:/opt/backups
参考网址:http://www.linuxquestions.org/questions/linux-software-2/rsync-ssh-on-different-port-448112/