If you're looking to manage your DigitalOcean droplets securely, you'll need to set up SSH Keys. SSH Keys are a digital key-pair that allows you to securely access your droplets, without needing to enter a password each time.
Below, we'll provide a step-by-step guide on how to add SSH Keys to an existing DigitalOcean Droplet.
Step-by-Step Guide
Generate an ssh-key pair on your local machine, using the command line
$ ssh-keygen -t rsa -b 4096
This will generate a public SSH key (id_rsa.pub
) and a private SSH key (id_rsa
). Note that these keys should not be shared or exposed to any third-parties.
Log in to your DigitalOcean account, and select the droplet you want to add the SSH key to
Under the Settings
menu of your droplet, click on the Security
tab
Under the Security
tab, click on the Add SSH Key
button
Paste the contents of your id_rsa.pub
file in the text box. You may get an optional Error message here, if your pasted key is invalid.
Optional: You can also add a name to the SSH candidate key, for better manageability.
- Finally, click the
Add SSH Key
button to add the SSH key to your DigitalOcean Droplet.
FAQ
Q. How do I generate a public/private key-pair for SSH?
A. To generate a public/private key pair for SSH, input the following command in the command line:$ ssh-keygen -t rsa -b 4096
This will generate a public SSH key (id_rsa.pub
) and a private SSH key (id_rsa
) in the current folder.
Q. How do I view the content of the id_rsa.pub
file I just generated?
A. You can view the content of the id_rsa.pub
file (which is a plain text file) by opening it in your text editor.
Q. Do I need to paste the content of my id_rsa
file when adding SSH Keys to my DigitalOcean Droplet?
A. No. The id_rsa
file is the private SSH key, which is only used when connecting to a remote server. The public ssh key (id_rsa.pub
) is the one that needs to be Added to the DigitalOcean Droplet, by pasting its content.