Tutorials, Bash, Digital Ocean

When creating a droplet you can add an SSH key during setup, later if your key changes you won’t be able to SSH into the server.

The advice is to login to the droplet and add the SSH key to:

~/.ssh/authorized_keys

I found trying to copy and paste the key difficult.

Another approach is to turn on password authentication by editing sshd_config.

vi /etc/ssh/sshd_config

Change PasswordAuthentication from "no" to "yes".

Restart the server.

service sshd restart

Exit the server.

From your computer, copy the ssh key.

cat ~/.ssh/id_rsa.pub

Now ssh in from your computer.

ssh root@ip

Enter the password

Paste the ssh key.

~/.ssh/authorized_keys

You will now be able to login without using the password, at this point you can turn PasswordAuthentication from yes to no to disable password authentication inside

vi /etc/ssh/sshd_config

Restart the server.

service sshd restart

To add a SSH key to a user, add a .ssh folder.

mkdir -p /home/username/.ssh

Make authorized_keys file and add the id_rsa.pub.

touch /home/username/.ssh/authorized_keys