Hosting » DigitalOcean » How do I add a new SSH key to a DigitalOcean droplet?

How do I add a new SSH key to a DigitalOcean droplet?

Last updated on December 20, 2022 @ 5:15 pm

If you are a new user of DigitalOcean, you may want to create an SSH key to access your droplet. You can do this by following these steps:

1. Visit the DigitalOcean Account page.

2. Click on the ” Keys” link in the top right corner.

3. Click on the “Add new key” button.

4. Provide a name for your key, and click on the “Generate” button.

5. Copy the key’s public key to your clipboard.

6. Go to your droplet’s root directory (i.e. /home/ on a droplet with 3GB of disk space).

7. Create a file called .ssh/authorized_keys with the following contents:

  • ssh-rsa [key] [user]@[host]

The [key] part of the string is the actual RSA key, which is a long string of characters that represents the key. It is typically encoded in base64 and begins with AAAAB3NzaC1yc2E.

The [user] and [host] parts of the string are optional and can be used to identify the user and host associated with the key. These values can be any string, but it is common to use the username and hostname of the machine where the key was generated.

Here is an example of a valid RSA public key:

  • ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9… john@example.com
PRO TIP: If you are adding a new SSH key to a DigitalOcean droplet, be sure to first generate the key pair on your local machine.

8. Put the public key you copied earlier in this file. Save the file. Restart your droplet.

9. When you log in, your new key will be automatically loaded.

Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.