Question

Adding a SSH key with new Recovery Console

I have a new laptop, so I wanted to update my SSH key that I use for my droplet. I generated a new key with ssh-keygen on the new PC, and initially followed a DigitalOcean tutorial to update my SSH Key in their Settings > Security menu on the Dashboard.

I found out later that this only affects new droplets, and that I needed to update ~/.ssh/authorized_keys on my droplet. However, I could not connect with any of my old accounts as I would get Permission denied (publickey). and no longer have access to that key.

The next advice I found was to use the web console on the Dashboard to update the keys file on my droplet. When I launched the Recovery Console (the only console I could find) I encountered strange red glitches you can see here and eventually a singular blinking cursor that did not respond to interaction or input.

But wait, this is where things get interesting! If I went to the Recovery tab on the droplet dashboard, selected Recovery ISO, rebooted, and was able to use the Recovery Console to do things like mount the disk, reset root password, update files, and more. I happily updated ~/.ssh/authorized_keys by using curl to grab my new ssh key I stored on a bin website then copying it into the file. I had to do that because pasting into the web console did not work correctly.

Finally, I restarted my droplet, making sure to boot to disk directly instead of the Recovery ISO. The exact same problem still happens.

Strangely, I can connect using the new ssh key while I am still in recovery mode, although I get a WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! that if I push through I can log on like normal. I am guessing that the recovery ISO does not save changes to the disk for this reason.

So, I don’t know what to do. If the web console worked outside of Recovery ISO, I could fix it, but I cannot. Any ideas to fix this would be amazing!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted Answer

I finally got this working by:

  1. Adding my new SSH Key in Settings > Security > SSH Keys on the Dashboard.
  2. Stopped my original droplet and created a Snapshot.
  3. Created a new droplet from the Snapshot.
  4. Updated A records to point towards new droplet.
  5. Logged in with root without needing to go into recovery, created the /home/username/.ssh/authorized_keys file for my day to day user.
  6. Also set permissions as so:
chown -R username:username /home/username/.ssh
chmod 700 /home/username/.ssh
chmod 600 /home/username/.ssh/authorized_keys

And voila! Logging in with ssh username@droplet worked! The only downside was the DNS downtime. I would hate to do this on a production server, so I’ll create backups of my SSH key this time.

KFSys
Site Moderator
Site Moderator badge
July 28, 2021

Hi @coachsyncinbox,

What I’ll suggest is to turn on PasswordAuthentication in your /etc/ssh/sshd_config while in Recovery Console. Don’t forger to restart the sshd service after you make the change.

service sshd restart

Once you do, you’ll be able to use your Regular Terminal to enter your Droplet using your root password.

Once you enter, you can easily copy your SSH key to the ~/.ssh/authorized_keys file.

Once you do remember to set PasswordAuthentication to Off and again restart the sshd service.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel