Howto use multiple SSH keys for password less login

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/

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 ~/.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/ >> ~/.ssh/authorized_keys

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

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
workstation#2 $ ssh

Updated for accuracy.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

20 comments… add one
  • Dillip Oct 17, 2007 @ 11:49


    After creation of key in pc-1 ( 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

  • ns Nov 5, 2007 @ 16:42


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

  • Malyadri Jan 27, 2008 @ 17:48

    Good tutorial…..

  • matt Feb 29, 2008 @ 17:00

    I do something like this:

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

  • Mikko May 7, 2008 @ 13:02

    e) Should be like

    workstation#2 $ scp ~/.ssh/authorized_keys

    instead of

    workstation#2 $ scp ~/.ssh/
    (this ruins the whole idea)


  • 🛡️ Vivek Gite (Author and Admin) nixCraft May 7, 2008 @ 13:34


    thanks for the heads up!

  • yh Mar 16, 2009 @ 8:40

    Can i know why need to append own public key to own authorized_keys?
    i thought own public key is used for others?
    web1 append to web2 authorized_keys (correct)
    web2 append to web1 authorized_keys (correct)
    web2 append to web2 authorized_keys (doubt)

  • pixeldoc Apr 2, 2009 @ 23:00

    if you have trouble login to your server, check if /etc/ssh/sshd_config contains Protocol 2
    PubkeyAuthentication yes

  • Ron Jul 24, 2009 @ 11:12

    Thanks. We have added this to our intranet wiki, just for future 😉

  • Matt Sep 8, 2009 @ 18:37

    Check out the ssh-copy-id command. It will take care of appending your public key onto the remote system.

  • jay Sep 24, 2011 @ 14:29

    Hi folks,

    Currently,for instance, many servers can do passwordless ssh to SERVER A
    Now,we are migrating all the stuff from Server A to Server B.
    all those servers which were connecting to Server A,now need to connect to Server B.
    Can i copy over the authorized_keys file from A to B ,so all those servers can connect to server B passwordlessly.
    The idea is to avoid all those servers keys addition to server B /etc/ssh/auth_keys/ file.

    Does it matter if platform(solaris to linux,vice versa)is different?

    2nd case:
    Server A connects to other servers using ssh which is passwordless. ServerA will be replaced by server B.
    do i need to send Servers’ B pub key to all those other servers have them add serverB pub key in their authorized key file?
    Or to avoid this, can i just copy over the pub key pair from server A to Server B,so other servers wont have to make any change on their side.

  • chika.tambun Apr 9, 2012 @ 6:14

    well how to enabling it from windows putty… is it possible?

    • Tom Apr 30, 2013 @ 20:38

      PuTTY comes with a utility called pageant (C:Program FilesPuTTYpageant.exe probably) that you load at startup– in your startup group. The icon there should read”C:Program FilesPuTTYpageant.exe” “C:Program FilesPuTTYid_rsa_putty.ppk” or something like that. Then your key is always available.

  • Viktor Feb 14, 2013 @ 15:00


    I have a question.
    I have two different servers, but they have the same home directory (it’s a network path that is mapped to the home dirrectory on each server).
    I want to be able to ssh without a password from one server to the other, I’ve tried these steps, but wasn’t successfull because I think both servers share the same files.

    Is there a way around this?

    Can I create a key and save it in some other area and use that during ssh command?


  • Viktor Feb 14, 2013 @ 15:13

    Nevermind, I figured it out. I guess somehow I deleted id file…

  • adq890 Dec 25, 2013 @ 14:51

    thanks for the guide…share in my blog.

  • Harish Jun 10, 2014 @ 6:37


    I have a problem with ssh password less login with nis users, when user login from client to server.

    i normally follow the steps below to fix ssh password less login and it works for few users but not for few, please help with steps to fix this issue.

    host:user1# ssh-keygen -t rsa
    host:user1# ssh-copy-id -i ~/.ssh/


  • arielCo Aug 20, 2014 @ 15:13

    You’re doing something terribly wrong in Step 2b. You don’t need to and must not copy the remote authorized_keys to any other .ssh/ (the workstation’s in this example); you’re effectively clobbering the workstation’s authorized_keys and granting access to your to every user with access to the server.

    A simpler, safer procedure, is appending every to the host’s .ssh/authorized_keys remotely:

    workstation1 $ cat ~/.ssh/ | ssh user@server “cat >> .ssh/authorized_keys”
    workstation2 $ cat ~/.ssh/ | ssh user@server “cat >> .ssh/authorized_keys”
    workstation3 $ cat ~/.ssh/ | ssh user@server “cat >> .ssh/authorized_keys”

  • Marco van Hulten Jan 21, 2015 @ 10:21

    While nixCraft’s method may work, it is complicated and insecure. Please, follow arielCo’s advice.

    Alternatively, I usually have at least two terminals open, say one on for the local workstation and one where I connected to the server. I simply copy and paste the content of to the authorized_keys file on the server.

    Two problems with nixCraft’s method:

    – there is the danger you unintentionally overwrite files, e.g. if the authorized_keys already had useful keys to begin with;
    – the side effect that you leave an authorized_keys file on workstation2 (arielCo’s point about clobbering).

  • Strong But Weak Feb 12, 2015 @ 5:44

    So when any new user runs ‘ssh-keygen -t rsa’ and then proceeds to create the respective priv/pub keys, must the user use a passphrase? Or should the new user ommit that (e.g: leave empty).

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.