It’s fairly common that server admins will change the port that the SSH daemon listens on, to something other than 22. It’s security by obscurity; adding just a little extra hard work for those nefarious people trying to access public-facing machines they don’t own.
Unfortunately this makes it a bit more tricky to use a number of ssh-enabled commands since it’s not always obvious how to pass the alternative port through. With rsync, it’s pretty easy once you know how.
A normal rsync command to sync files from a remote machine to a local machine—over port 22—would look something like this:
rsync -rav firstname.lastname@example.org:/home/nick/somedirectory .
So, if instead we wanted to use port 12345, we simply add the
--rsh= switch (or
-e, which is an alias) to our command. This allows us to specify a *r*emote *sh*ell to connect to; in other words, the parameters to pass to the ssh command. Here’s how it looks:
rsync -rav --rsh='ssh -p12345' email@example.com:/home/nick/somedirectory .
or using the
rsync -rav -e 'ssh -p12345' firstname.lastname@example.org:/home/nick/somedirectory .
Hopefully that saves a few headaches…