sshdigital-oceanssh-keys

DigitalOcean Permission denied (publickey) when adding new ssh keys to an existing droplet?


Having issue adding new ssh keys to an existing droplet on Digital Ocean Ubuntu VM. SSH key is added via Digial Ocean portal via browser.

When added SSH key first time from local Ubuntu machine it is working fine.

Next time trying to add SSH from MacOS machine, and unable to login even though 2nd SSH key was added successfully, and keep getting Permission denied (publickey) error.

Checking on the remote Ubuntu droplet nano /etc/ssh/sshd_config can see PubkeyAuthenthication yes


Solution

  • There seem to be an issue with Digital Ocean web portal when adding 2nd SSH key. The portal show there are 2 SSH keys (Settings\Security\SSH keys).

    However, checking authorized_keys file (nano .ssh/authorized_keys), only the 1st SSH key was there and the 2nd SSH key was not found.

    Work a round fix was to login the Ubuntu server/droplet (using the working local Ubuntu machine for my case), and manually add 2nd SSH key (for MacOS machine) to authorized_keys file.

    1. Server/Droplet Ubuntu: nano ~/.ssh/authorized_keys

    2. MacOS local machine: cat .ssh/id_ed25519.pub ( I used ed25519 type in this instance, change to whatever yours pub key is).

    3. Paste the SSH pub key to authorized_key file.

    4. Reload ssh on Ubuntu server/droplet: systemctl reload ssh

    image of authorized_keys file in nano editor