Is it possible to specify a different ssh port whe

2019-01-29 14:42发布

I have been attempting the following command:

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

SSH is running on port 2222, but rsync still tries to use port 22 and then complains about not finding the path, cause of course it does not exist.

I would like to know if it is possible to rsync to a remote host on a non-standard ssh port.

标签: ssh rsync
8条回答
Anthone
2楼-- · 2019-01-29 15:14

when you need to send files through a specific SSH port:

rsync -azP -e "ssh -p PORT_NUMBER" source destination

example

rsync -azP -e "ssh -p 2121" /path/to/files/source user@remoteip:/path/to/files/destination
查看更多
对你真心纯属浪费
3楼-- · 2019-01-29 15:18

A bit offtopic but might help someone. If you need to pass password and port I suggest using sshpass package. Command line command would look like this: sshpass -p "password" rsync -avzh -e 'ssh -p PORT312' root@192.xx.xxx.xxx:/dir_on_host/

查看更多
ら.Afraid
4楼-- · 2019-01-29 15:28

Rsync runs as a daemon on TCP port 873, unprotected, has nothing to do with SSH

From Rsync man:

Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Leads you to believe your command is correct:

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

However, that is instructing it to connect to Rsync daemon on port 2222, which is not there.

As noted, the correct syntax is to tell Rsync to use a custom SSH command (adding -p 2222), which will continue to connect (on remote side) to TCP 873 for rsync (using secure SSH tunnel).

rsync -rvz --progress --remove-sent-files -e "ssh -p 2222" ./dir user@host/path

查看更多
Evening l夕情丶
5楼-- · 2019-01-29 15:30

Another option, in the host you run rsync from, set the port in the ssh config file, ie:

cat ~/.ssh/config
Host host
    Port 2222

Then rsync over ssh will talk to port 2222:

rsync -rvz --progress --remove-sent-files ./dir user@host:/path
查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-01-29 15:31

use the "rsh option" . e.g.:

rsync -avz --rsh='ssh -p3382' root@remote_server_name:/opt/backups

refer to: http://www.linuxquestions.org/questions/linux-software-2/rsync-ssh-on-different-port-448112/

查看更多
Rolldiameter
7楼-- · 2019-01-29 15:31

I was not able to get rsync to connect via ssh on a different port, but I wasn able to redirect the ssh connection to the computer I wanted via iptables. This is not the solution I was looking for, but it solved my problem.

查看更多
登录 后发表回答