Updated: 28 September 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

rsync uses SSH to copy files between servers. If the SSH server listens on another port than 22, tell rsync which one.

Give the port on the command line

rsync -avz -e "ssh -p 2222" /var/www/ user@192.0.2.10:/var/www/
rsync -avz -e "ssh -p 2222" user@192.0.2.10:/backup/ /restore/      # the other direction

Or save it in your SSH config

In ~/.ssh/config:

Host backupserver
    HostName 192.0.2.10
    Port 2222
    User user
    IdentityFile ~/.ssh/id_ed25519

Now rsync -avz /var/www/ backupserver:/var/www/ uses the right port and key automatically, and so do ssh backupserver and scp.

Useful options

  • -a keeps permissions, times and links; -z compresses on the way.
  • --delete removes files at the destination that no longer exist at the source (test with -n first).
  • --progress or --info=progress2 shows progress.

Note: If you changed the SSH port, the firewall and (on AlmaLinux/Rocky) SELinux must allow it: semanage port -a -t ssh_port_t -p tcp 2222.

Tip: To change the port the SSH server listens on, edit Port in /etc/ssh/sshd_config, allow the new port in the firewall first, then restart SSH and test a new connection before closing the old one.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $131.99 a month.

Was this answer helpful?

Still stuck? Open a ticket