Adding SSH Keys to a Droplet for Secure Access on DigitalOcean

Coding Posted on Mar 23, 2023
To add your SSH keys to the Droplet, follow these steps:

  1. Generate an SSH key pair on your local machine if you haven't already. On Linux or macOS, you can use the following command:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" 

On Windows, you can use a tool like PuTTYgen (https://www.puttygen.com/) to generate an SSH key pair.

  1. Copy the public key to your clipboard. On Linux or macOS, you can use the following command:

$ cat ~/.ssh/id_rsa.pub | pbcopy

On Windows, you can open the public key file (usually id_rsa.pub) with a text editor, and copy its contents.

  1. Log in to your DigitalOcean account, and navigate to the "Security" section under your account settings.
  2. Click "Add SSH Key" and paste your public key into the "SSH key content" field. Give the key a meaningful name to identify it, then click "Add SSH Key."
  3. When creating a new Droplet, under the "Authentication" section, select the "SSH keys" option. Choose the SSH key you just added to your DigitalOcean account. This will automatically add the public key to the authorized_keys file on your new Droplet.
  4. Once your Droplet is provisioned, you can access it using your SSH key pair. On Linux or macOS, use the following command:

$ ssh -i ~/.ssh/id_rsa root@your_droplet_ip_address

On Windows, you can use a tool like PuTTY (https://www.putty.org/) to connect to your Droplet using your private key.

Leave a comment:

Comments (0)