Using ssh-copy-id with an alternate SSH port

Josh Sherman
1 min read
Command-line Interface

If you’re anything like me, you’re somewhat paranoid security-minded.

Because of this, you’ve most likely moved the SSH port on your server(s) to something other than the standard port 22.

Nothing wrong with a little bit of security through obscurity on top of all of the other crap you’ve done to lock things down.

Unfortunately, one time I had locked myself out of a box because I had failed to copy over my private key before changing the port number.

Frustrating, but nothing a bit of digging around wouldn’t solve.

Prior to OpenSSH 6.2:

ssh-copy-id "[email protected] -p ####"

Since OpenSSH 6.2:

ssh-copy-id -p #### [email protected]

You could also go the route of adding the port to your ~/.ssh/config:

Host hostname
  HostName #.#.#.#
  Username username
  Port ####

Then use ssh-copy-id hostname as you normally would!

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, Engineering Manager 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