Add new SSH keys to a Droplet on Digital Ocean
When we create a Droplet on Digital Ocean and configure access via SSH, access with our RSA key is automatically guaranteed. However, when we try to enter a new SSH key from the administration panel, even after this, it is not possible to log in with the RSA private key to the Droplet. This is because although access was authorized from the panel, it must also be authorized from the same Droplet, which implies that you must enter from the web console or from the first access you configured with SSH.
In summary, you must follow these steps to add another RSA key and authorize access.
Step 1
Of course, step number one is to create a new RSA key. For this, you can use the following command from the new machine.
ssh-keygen -t rsa
At this point, it is advisable to type a passphrase, that is, to create the encrypted key. The product of this command will be the private key and the public key which will generally be id_rsa
and id_rsa.pub
.
Step 2
The second step will be to enter the Digital Ocean panel, and go to the Account > Security menu. In the SSH Keys section, you must add the public key created in step 1.
Step 3
The third step will be to access the server from the administrative console or from your first machine configured with SSH and add the same public key from step 2 to the authorized_keys
file. For this, you can use the editor of your choice.
vim ~/.ssh/authorized_keys
Step 4
After this, you can already log in to your Droplet. Keep in mind that you must replace the IP shown with the IP of your Droplet.
ssh root@203.0.113.0
If you have several SSH private keys, you need to explicitly specify the key you will use with the -i
option.
ssh -i /path/to/private/key root@203.0.113.0