Skip to content

Instantly share code, notes, and snippets.

@debojyoti
Created January 23, 2019 16:16
Show Gist options
  • Save debojyoti/2eb6acaa1c2ba2323dadda1a41a5fd02 to your computer and use it in GitHub Desktop.
Save debojyoti/2eb6acaa1c2ba2323dadda1a41a5fd02 to your computer and use it in GitHub Desktop.

Steps to setup ssh access to a droplet

Step-1: Generate keys in your local machine

1.1) Run the following commands in your local machine to generate (public and private) key pair

ssh-keygen -t rsa

1.2) It will ask for the path to save the keys, and will also show the default path

Enter file in which to save the key (/home/demo/.ssh/id_rsa):

Press enter key to use the suggested default path or you can enter a custom path followed by enter key

1.3) Next it will ask for a passphrase.

Enter passphrase (empty for no passphrase):

Passphrase is nothing but a secondary password which will be used while logging through ssh. You can keep it blank if you don't want to use (Press enter to skip).

At the end the two keys will get saved in that particular path mentioned in step 1.2 The private key will get saved as id_rsa and the public key as id_rsa.pub

Step-2: Copy the public key in your droplet

Login into your droplet using normal login (Using username and password) and copy the file from your local machine

cat ~/.ssh/id_rsa.pub | ssh demo@your_droplet_ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Note: Replace key path (~/.ssh/id_rsa.pub ) if you have used any other path in step 1.2 This will ask for your login password.

Done!

Now login without password

ssh root@your_droplet_ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment