nixCraft Poll

Topics

Howto use multiple SSH keys for password less login

Posted by Vivek Gite [Last updated: May 7, 2008]


I've already written about howto log in, on your local system, and make passwordless ssh connections using ssh-keygen command. However, you cannot just follow these instructions over and over again, as you will overwrite the previous keys.

It is also possible to upload multiple public keys to your remote server, allowing one or more users to log in without a password from different computers.

Step # 1: Generate first ssh key

Type the following command to generate your first public and private key on a local workstation. Next provide the required input or accept the defaults. Please do not change the filename and directory location.
workstation#1 $ ssh-keygen -t rsa
Finally, copy your public key to your remote server using scp
workstation#1 $ scp ~/.ssh/id_rsa.pub user@remote.server.com:.ssh/authorized_keys

Step # 2: Generate next/multiple ssh key

a) Login to 2nd workstation

b) Download original the authorized_keys file from remote server using scp:
workstation#2 $ scp user@remote.server.com:.ssh/authorized_keys ~/.ssh

c) Now create the new pub/private key:
workstation#2 $ ssh-keygen -t rsa

d) Now you have new public key. APPEND this key to the downloaded authorized_keys file using cat command:
workstation#2 $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

e) Finally upload authorized_keys to remote server again:
workstation#2 $ scp ~/.ssh/authorized_keys user@remote.server.com:.ssh/

You can repeat step #2 for each user or workstations for remote server.

Step #3: Test your setup

Now try to login from Workstation #1, #2 and so on to remote server. You should not be asked for a password:
workstation#1 $ ssh user@remote.server.com
workstation#2 $ ssh user@remote.server.com

Updated for accuracy.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Dillip Says:

    Sir

    After creation of key in pc-1 (id_rsa.pub) copy to pc-2 as authorized_keys but I am not able to ssh username@pc-2, against it is now asking password.

    Kindly help

    Dillip Dhala
    dkdhal1@gmail.com

  2. ns Says:

    @Dillip

    It might be that you are using SSLv2 in which case you have to copy/append the key to authorized_keys2

  3. Malyadri Says:

    Good tutorial…..

  4. matt Says:

    I do something like this:

    cat .ssh/id_rsa.pub | ssh user@server “cat >> .ssh/authorized_keys”

  5. Mikko Says:

    e) Should be like

    workstation#2 $ scp ~/.ssh/authorized_keys user@remote.server.com:.ssh/

    instead of

    workstation#2 $ scp ~/.ssh/id_rsa.pub user@remote.server.com:.ssh/authorized_keys
    (this ruins the whole idea)

    :)

  6. vivek Says:

    Mikko,

    thanks for the heads up!

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.