Using alternate SSH ports with rsync

I live on the command-line.

I also use the hell out of rsync to move files around.

And because I’m security conscious, I run sshd on an alternate port
to provide an additional layer of obscurity to things.

While providing me with some piece of mind, using an alternate port with SSH
does come with some issues, specifically around needing to specify which port to
use when using other apps that leverage ssh.

This is actually something I documented before in regard to using
ssh-copy-id. Similarly, getting rsync to play nice with an alternate SSH
port just requires some additional command-line arguments.

To get things working, you will need to pass -e to rsync. The -e argument
is short for --rsh which is an option that allows you to set your “remote
shell”.

In this instance, our remote shell is SSH with our alternate port:

rsync -avz -e "ssh -p 6789" some-file.txt user@server:~/some-path

This tells rsync “hey, instead of just using ssh, let’s use this other
string in it’s place.

Pretty powerful stuff as it’s not limited to just specifying a port, you can
feed it any additional ssh arguments you’d like!

And for the record, I don’t use port 6789 for sshd</code> ;)

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.