Hosting » DigitalOcean » How do I use SSH keys in DigitalOcean droplets?

How do I use SSH keys in DigitalOcean droplets?

Last updated on September 25, 2022 @ 1:42 pm

SSH keys are a great way to secure your droplet session and keep your data safe. Before you can use SSH keys, you first need to generate a key pair. To do this, open the SSH client on your computer and type the following command:

ssh-keygen

Next, save the public key by typing the following command:

ssh-copy-id public_key_name

Finally, save the private key by typing the following command:

ssh-copy-id private_key_name

Now you need to add the public key to your droplet. To do this, open the droplet’s settings panel and click on “SSH keys.” Next, click on the “Add” button and paste the public key into the “Public key” field.

Click on the “Add” button again and paste the private key into the “Private key” field. Click on the “Save” button to finish.

PRO TIP: If you are using SSH keys in DigitalOcean droplets, be sure to keep your private key safe and secure. Do not store it in a public location or share it with anyone. If your private key is compromised, someone could gain access to your droplet and all of its contents.

Now you can use SSH keys to log in to your droplet. To do this, open the SSH client on your computer and type the following command:

ssh username@droplet_name

where username is the username you use to log in to your droplet, and droplet_name is the name of your droplet. If you’re using a public key, you’ll need to type the following command:

ssh-keygen -t rsa

Next, type the following command to save the key pair:

Finally, type the following command to log in to your droplet:

You can also use the “ssh” command to open a shell on your droplet. To do this, type the following command:

where username is the username you use to log in to your droplet, and droplet_name is the name of your droplet.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.