Rsync Ssh using Non-standard Port in Linux

Rsync is a tool for copying files locally, to/from another host over any remote shell, or to/from a remote rsync daemon. Rsync is widely used for backing up the data.

This tutorial describes how we can connect to ssh to copy data using rsync, if ssh is running on a different port.

Rsync syntax

The basic usage of rsync command is:

rsync [options] src [dest]

By default, rsync command will just list the files at source if no destination is provided. For example,

$ rsync /usr/
drwxr-xr-x 4096 2011/04/26 04:26:48 .
drwxr-xr-x 53248 2012/09/26 23:05:59 bin
drwxr-xr-x 4096 2011/04/26 04:27:37 games
drwxr-xr-x 20480 2012/09/08 19:17:32 include
drwxr-xr-x 69632 2012/09/26 23:05:50 lib
drwxr-xr-x 4096 2011/04/26 04:26:48 lib64
drwxr-xr-x 4096 2011/11/16 13:02:25 local
drwxr-xr-x 12288 2012/09/26 23:05:51 sbin
drwxr-xr-x 12288 2012/09/22 14:25:28 share
drwxrwsr-x 4096 2012/09/08 19:46:27 src

Now, to copy locally, we can issue the following command

$ rsync -av file1 dir1/
sending incremental file list
sent 45 bytes received 12 bytes 114.00 bytes/sec
total size is 0 speedup is 0.00

This will copy the file named 'file1' to the directory 'dir1'. The -v option here is just for verbose output.

Rsync Ssh to specific port

If we want to connect to a machine running ssh on some specific port using rsync, then we can run the following syntax

$ rsync --rsh='ssh -p1234' <sourcefile> user@host:/path/to/destination/directory

The port on which ssh is running is specified using -p option as specified above. Here, port 1234 should be changed with the port at which the ssh server is running. An example of working of the above syntax is

$ rsync -av --rsh='ssh -p22' file1 root@
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is fe:44:85:8c:2c:63:fb:d7:df:dd:27:17:45:04:28:9b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (ECDSA) to the list of known hosts.
root@'s password:
sending incremental file list

sent 84 bytes received 31 bytes 10.95 bytes/sec
total size is 0 speedup is 0.00

This will copy the file using rsync+ssh, and ssh is not running on its default port (although in the above example, the port is default, i.e. 22).

Read Also:

2 Comments... add one

  1. when i try this:
    root@debian:/etc/ssh# rsync -av --rsh='ssh -p22' /home/giorgio/.../xxx.mp4 debian_remote_serveur@x.x.x.x:~/home/newhome/judofusion/videos/
    Permission denied (publickey).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]

    but when I try this ;
    ssh -i ~/.ssh/authorized_keys/SHAHJAR2/id_rsa debian@x.x.x.x
    ssh is OK


Leave a Comment