Rsync over SSH with a custom port (BASH)

It's not at all uncommon nowadays for SSH not to be listening on TCP 22, but to instead be bound to another port - primarily to prevent brute force attacks by the various dumbest-of-the-dumb bots out there

Occasionally, though, you then want to use rsync over an SSH tunnel, and need to specify the port to use so that rsync uses the custom SSH port instead of port 22

It's pretty straightforward, but is one of those things I use infrequently enough to need to look it up from time to time

Details

  • Language: BASH

Snippet

rsync -avz -e "ssh -p [port number]" /local/path [user]@[remotehost]:/path/to/dest/dir/

Usage Example

rsync -uavz -e "ssh -p 8822" /mnt/imagestore foo@images.example.com:/var/www/html/images/