Using ssh-keygen & ssh-copy-id

      2 Comments on Using ssh-keygen & ssh-copy-id

Just because I always forget:

Step 1: Create public and private keys using ssh-keygen

[user@Host ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
0d:d2:94:07:93:a9:48:b9:33:73:fb:f1:6e:33:ce:d7 user@Host
The key's randomart image is:
+--[ RSA 2048]----+
|     .  +=       |
|    o  o+..      |
|   . o..o.       |
|    * o. o       |
|     = .S .      |
|      . .        |
|       . o   .   |
|        ..= . E  |
|         +++     |
+-----------------+

Step 2: Copy the public key to remote-host using ssh-copy-id

Now here comes the awesome part: You don’t have to scp the public key to your remote host and cat it into ~/.ssh/authorized_keys. Instead, you can use ssh-copy-id

[user@Host ~]$ ssh-copy-id -i .ssh/id_rsa.pub user@remote-host
user@remote-host's password: 
Now try logging into the machine, with "ssh 'user@remote-host'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

2 thoughts on “Using ssh-keygen & ssh-copy-id

  1. Pingback: /dev/blog » Non-interactive ssh with expect

  2. avatarTimT

    Thanks for documenting this – I always forget too!

    Do you have any suggestions for how I can copy my public key to a remote server where password authentication has been disabled (PasswordAuthentication no)?

Leave a Reply

Your email address will not be published.