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
-akeeps permissions, times and links;-zcompresses on the way.--deleteremoves files at the destination that no longer exist at the source (test with-nfirst).--progressor--info=progress2shows 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
- 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.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
