Copy ssh keys to user@host to enable password-less ssh logins.

$ssh-copy-id user@host
To generate the keys use the command ssh-keygen

By: senthil
2009-02-07 04:58:11

13 Alternatives + Submit Alt

What Others Think

If you need change default port ssh, you can use: ssh-copy-id 'user@host -p2233'
irraz · 676 weeks and 2 days ago
I think this isn't normally found outside Ubuntu or Debian systems.
mlambie · 675 weeks and 5 days ago
Alternativly you can use ?cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'? on such systems.
DASKAjA · 675 weeks and 4 days ago
... without the question marks (?) of course.
DASKAjA · 675 weeks and 4 days ago
Beware : without arguments it copies your file, which is by default a RSA1 pub key (obsolete), unless you have already executed ssh-agent, added your keys, so that ssh-add -L returns something.
jmcoursi · 675 weeks and 1 day ago
Works on RedHat-like systems
jmcoursi · 675 weeks and 1 day ago
Also works on Gentoo, it's contained in openssh package.
xupeng · 673 weeks and 6 days ago
doesn't work across all unix OS. Or is there some installation needed?
rommelsharma · 673 weeks ago
cat ~/.ssh/ | ssh user@remotehost 'cat >> ~/.ssh/authorized_keys
juddmaltin · 670 weeks and 4 days ago
ssh-copy-id is just a script. If you don't have it you can google it easily ehough. Using the above cat is easier though. OS X doesn't bundle ssh-copy-id so I always use the cat version.
qubyte · 669 weeks and 4 days ago
This does not work on CentOS 5.3: ssh-add -L The agent has no identities. So, this tip requires at least some readme on setting up said ssh-copy-id Quick reading of man ssh-agent did not result in much enlightenment for me. On the other hand the cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys' is easy to understand and certainly works....
vleolml · 663 weeks and 4 days ago
vleolml, ssh-copy-id does exist on both Ubuntu 8.x and CentOS 5.x.
bassu · 656 weeks and 6 days ago
As always, read the man page carefully before using this command. It does a bit more than just copying your public key. It also modifies the permissions of ~ and ~/.ssh, which may not be what you want if for example the recipient of your key is user postgres on the remote box.
lorenzocabrini · 591 weeks ago
For OSX using Homebrew: there is a Formula for this:
unixmonkey24450 · 546 weeks and 1 day ago
thanks man this will help me :)
techie · 459 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: