Question

How to add new SSH KEY after formated PC

Posted November 16, 2017 3.4k views
SecurityDigitalOceanDokkuUbuntu 16.04

HI,

I use ubuntu 16.04 to work, but I needed to format my computer and now I can not access my droplets via SSH only through the Launch Console.

My droplet is with DOKKU and I need access to access the repositories.

I would like to know how I add new SSH keys so I can access my droplets again.

I have already tried to add a new key through the settings / security, but when I try to access my droplet through ssh root @ ipdroplet the Permission denied (publickey) message appears.

Please help me, I’m desperate !!!

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
2 answers

So you still have access to the server which is good.

If you have not, you need to generate some ssh-keys. Once you have done that you need to find your public key.

Which should look something like this example key, If your on windows your key might look different but needs to have this format.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7kGBwVKF0E54AZl/kGHEn9PgnfbGAbvNMebdSl3YNswRvW0bGdrL8KpW/BQZ76eZV9H5mdMgH6GPxLWhjFTz1jVWtW03s3c2q83xqXsyoXCnHp3NAEggwTHzkzd+OyMSSO2+fSc9ACGfpTvxZGvU5cRAeXkjTg1PQppxBv7lkG8HINYyYiEt6ck70aSUo2Fzck2IQrdTgD62riiUNOGusRGWXPB5thAd/1lNiAxQFu0dssiuDS8BwoU3DaaM0Vm5HH0NUp8Zzxkb7bcbatqs8Yd0F9NEJLtUAyjTxKjbaTcHCQLshtDi+WLMS3kUrJkYPsk/vAyPcLYqiPrvldMjj example@snapshooter.io

You then need to copy this and use the Launch console to access your droplet.

Once in run the following command to edit the authorized_keys file

nano /root/.ssh/authorized_keys

Then append your public key to the authorized keys file. Once this is complete you should be able to log in. This will give you root access, if you need access to a different user account it would be

nano /home/example/.ssh/authorized_keys

Hope this helps

Simon
SnapShooter.io - Better DigitalOcean Backups

Hello, all

The Copy/Paste functionality of our web console is a bit odd; the code backing it is custom due to the way the VNC window is implemented for accessing your Droplet. It isn’t a good idea, in my experience, to rely on the console for long copy/pasting like an SSH key.

My recommended method to get the key on the Droplet is over SSH itself. You can enable PasswordAuthentication for your Droplet by modifying your /etc/ssh/sshdconfig file. Once set to Yes restart the SSH service and connect via an SSH client for a more stable connection. You can then modify your ~/.ssh/authorizedkeys file to add the appropriate public key.

This should do the job for you as well.

The other option is to temporary enable the PasswordAuthentication from no to yes in order to access your droplet using password and then once you’ve entered your key to disable the PasswordAuthentication again. This way is considered more secure than uploading the key to a Dropbox in case you don’t have any other server to us.

  1. Login to the console on the DigitalOcean website.
  2. Type sudo nano /etc/ssh/sshd_config
  3. Change PasswordAuthentication from “no” to “yes” and save the file
  4. Open a terminal on your computer and type ssh username@[hostname or IP address] or if on a Windows box use PuTTY for password login making sure authentication parameters aren’t pointing to a private key
  5. Login with a password
  6. Type sudo nano ~/.ssh/authorized_keys
  7. Paste public key text here and save the file
  8. Type sudo nano /etc/ssh/sshd_config
  9. Change PasswordAuthentication from “yes” to “no” and save the file
  10. Log out and attempt to log back in (if using PuTTY make sure you set up auth parameters to point to your private key)

Hope that this helps!
Regards,
Alex