How to set SSH key for multiple users?

Posted April 8, 2019 4.4k views
SecurityInitial Server SetupUbuntu 18.04

I currently have 3 accounts on my droplet, for this case I’ll be using the names “root”, “a”, and “b”.
I have my SSH key set up so that it currently applies to account a. How do I apply it to the root account as well, but not to account b?


1 answer


Great question. There are several ways to do this, but this is mine:

  1. Switch to the user:

    su a
  2. Generate SSH keys:

    {hit enter a few times}
  3. Create/edit authorized keys file:

    nano ~/.ssh/authorized_keys
  4. Paste your public key in that file and close it out.

  5. Rinse and repeat with each user.

Everyone has preferences, that one just fits my brain :)


  • I am currently using FileZilla to see my files and when I log in to each user separately, it shows authorized_keys is already created and owned by account a and therefore is only used by account a (so I can’t just create a new file on a different account), what I want to do is change that so that both root and account a use the same key, but not account b. I will also want to install a key just for account b later.

    After I typed out this response, I thought of using ssh-copy-id, but that did not work.
    I also thought about changing the sshd_config file so that it specifies key files to use with specific accounts, is that possible?

  • I was just looking around in my files and realized that each user actually does have their own folder for ssh keys, but for some reason, I had previously changed the owner of the root key to account a, I have changed the owner back to root and the same key is already in account a’s ssh folder, so the same key is now being used for root and a. Thank you for your assistance.

Submit an Answer