To change the SSH port number when using rsync
for backups, you need to specify the new port number in the rsync
command using the -e
option. The -e
option allows you to specify a custom command to use for establishing the connection.
For example, to change the SSH port to 2222
, you could use the following rsync
command:
rsync -avz -e "ssh -p 2222" [user@]source_host:source_directory destination
This will connect to the source host using the specified port number (2222
) and transfer the files from the source directory to the destination directory.
You can also specify the new port number in the ~/.ssh/config
file on the source machine. This allows you to set the default port number for all ssh
connections from the source machine, without having to specify it every time you run rsync
. To do this, add the following lines to the ~/.ssh/config
file on the source machine:
Host *
Port 2222
This sets the default port number to 2222
for all ssh
connections. With this configuration in place, you can use the following rsync
command:
rsync -avz [user@]source_host:source_directory destination
This will connect to the source host using the default port number (2222
) specified in the ~/.ssh/config
file and transfer the files from the source directory to the destination directory.