Today here at Arzhost, our experts discuss how we Add SSH Key to Droplet in the Digital Ocean. My Digital Ocean (DO) droplet is configured so that a password cannot be used to access it. However, since I lost the private SSH Key when I changed my local PC, I can no longer access my droplet. Thankfully, I can still connect to the remote server through Web Console, but it’s too sluggish and choppy.

arz

I add my current ssh key to the droplet by following these steps:

1: Create a Fresh Set of SSH Keys on Your Current Local Machine.

Add SSH Key to Droplet, the following command can be used to create a new ssh key pair if there isn’t one already in the local system ($HOME/.ssh/):

  • keygen-ssh -t rsa

Alternatively, you can use this command to attach your email to the key:

  • keygen-ssh -t rsa -b 4096 -C "your email@example.com"

2: Store the Public Key in a Different File.

To copy id rsa.pub to key.txt, issue the following command to Add SSH Key to Droplet:

  • cd ~
  • if (cat /.ssh/id rsa.pub > key.txt)

3: Submit the Public Key to a Service for File Sharing.

Run the command line:

  • curl key.txt at https://bashupload.com —data-binary

The reply will provide a download link for the key. Save it for use in the following step to Add SSH Key to Droplet.

4: Launch the Following Command after Logging in to the DO Droplet Using the Web Console:

  • cd ~/.ssh
  • Link-from-Previous-Step: wget
  • cat key.txt >> authorized keys

Note: Use >> to guarantee that the key is appended to the authorized keys file rather than being overwritten when using the cat command.

5: Utilize the New Local Machine to Access the Droplet

To connect to a droplet via SSH, enter the following command:

  • Username@IP Address: ssh

Related Article

Share.