How do I add ssh keys to an existing droplet when getting Permission denied (publickey).

October 21, 2019 1.6k views
One-Click Install Apps Ubuntu 16.04

I provisioned a One-Click Install Gitlab instance a while ago. Since then, I lost the machine I used to provision the box due to a power surge, thus lost the SSH keys as well.

I am now trying to access the box but I am getting a Permission denied (publickey). I have tried a lot of solutions based on what I could get off the internet but to no success.

Can you please help.

2 Answers

Hello, @ditjhabas

You can follow this tutorial in order to upload your ssh key to an existing droplet.

https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/to-existing-droplet/

Let me know how it goes.

  • Thanks @alexdo

    I’ve tried this but I am still experiencing the same issue.

    ➜ ~ cat .ssh/idrsa.pub | ssh root@git.khabane.co.za “mkdir -p ~/.ssh && cat >> ~/.ssh/authorizedkeys”
    root@git.khabane.co.za: Permission denied (publickey).
    ➜ ~ ll .ssh
    total 32
    -rw——- 1 ditjhaba staff 1.8K Jun 26 15:18 idrsa
    -rw-r–r– 1 ditjhaba staff 423B Jun 26 15:18 id
    rsa.pub
    -rw-r–r– 1 ditjhaba staff 4.4K Oct 21 09:36 known_hosts

  • Thanks @alexdo

    I have tried this but I am still getting the Permission denied (public key)

    root@git.khabane.co.za: Permission denied (publickey).

    Please note that this is instance is a few years old and I haven’t used a password to access the box ever.

You would need to add the key using the DigitalOcean’s console since you’re not able to connect from your local machine.

What you can do is copy the content of your idrsa.pub to the /root/.ssh/authorizedkeys file and then you’ll be able to connect to your droplet.

Let me know how it goes.

  • I have tried logging in using the console on the digitalocean portal but it won’t accept my login credentials, this is even after I have reset the password multiple times.

    • Exactly the same problem here!

      • Can you please check your email and see if the you’ve received the login details? Also please check your SPAM/Junk folders as well. If you haven’t received any emails then I would suggest you to contact our support team.

        Hope this helps.

        Regards,
        Alex

    • Can you please check your email and see if the you’ve received the login details? Also please check your SPAM/Junk folders as well. If you haven’t received any emails then I would suggest you to contact our support team.

      Hope this helps.

      Regards,
      Alex

Have another answer? Share your knowledge.