Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Digital Ocean - Add SSH key to droplet after creation

David Carr

VPS Tutorials 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


 

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.