Adding additional SSH key to existing Droplet

Posted May 25, 2021 512 views
Ubuntu 18.04DigitalOcean Droplets

I have a droplet with no-password ssh access. I would like to provide access to my colleague.

I had him generate a key-pair on his linux machine, and got his public key. Then, I added his key to the ~/.ssh/authorized_keys file along with my key, following the tutorial here:

I did set the permissions afterwards as instructed.

I’m still able to ssh in, but he cannot: Error Permission denied (publickey)

I tried service sshd restart, but to no effect.

Similarly, I tried to set myself up from a different machine, but again I’m getting the same permission denied error.

I read some other tutorials that suggested to set a password authentication, but that’s not what I want to do. Need ssh login.

Any tips?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hello, @geochanto

You can make sure that the correct ssh-key is used for the connection. If you’re using ssh-client (terminal) you can use ssh -i to specify the exact ssh-key you want to use for the connection. An example is:

  • ssh -i ~/.ssh/id_rsa root@DropletIP

You can also use the -v argument in order to get a more verbose output:

  • ssh -vvv -i ~/.ssh/id_rsa root@DropletIP

You can also check our tutorial on How to Connect to Droplets with SSH:

You can also make sure that the file/folder permissions are okay

  • Your home directory ~, your ~/.sshdirectory and the ~/.ssh/authorized_keys file on the remote machine must be writable only by you: rwx------ and rwxr-xr-x are fine, but rwxrwx--- is no good, even if you are the only user in your group (if you prefer numeric modes: 700 or 755, not 775).

  • If ~/.ssh or authorized_keys is a symbolic link, the canonical path (with symbolic links expanded) is checked.

  • Your ~/.ssh/authorized_keys file (on the remote machine) must be readable (at least 400), but you’ll need it to be also writable (600) if you will add any more keys to it.

  • Your private key file (on the local machine) must be readable and writable only by you: rw——- , i.e. 600.