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.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)