Using alternate SSH ports with rsync

Josh Sherman
1 min read
Command-line Interface

I live on the command-line.

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

And because I’m paranoid / 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 [email protected]:~/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 ;)

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

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.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles