29 - April - 2013

Terminal Tuesday - ssh-copy-id

Post by Chris H
Ixis Service

I was quite surprised recently to speak to a few people who still weren't aware of ssh-copy-id 

They were still doing something laborious like:

cat ~/.ssh/id_rsa.pub
(copy key to clipboard)
ssh yourbox vi ~/.ssh/authorized_keys
(paste key and save)
chmod 400 ~/.ssh/authorized_keys

Or a one-liner:
cat ~/.ssh/id_rsa.pub | ssh yourbox 'cat >> ~/.ssh/authorized_keys'
Although you still may also need to chmod authorized_keys to ensure it isn't world read/writable depending if 'StrictModes yes' is set in sshd_config

This is where ssh-copy-id comes in use, it transfers and appends your key to the remote host whilst also changing the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability.

ssh-copy-id user@yourbox

If you have multiple keys and need to specify a certain key you can use:
ssh-copy-id -i ~/.ssh/amazon.pub user@yourbox

For those of you using OSX whilst ssh / ssh-keygen are included ssh-copy-id isn't, to quickly get it check out this blogpost.

Picture of Chris H

Chris H

Commercial Director

Add new comment

Share this article

Sign up to our newsletter!

Our thoughts

Let's work together

Get in touch and find out how we can empower your organisation.
Back to top