How To Use SSH Keys to login console?

June 10, 2014 2.2k views
I have created droplet without key. How I can connect the added key to my actual droplets? BR
5 Answers
mkdir ~/.ssh && echo "ssh-rsa AAAAB..." >> ~/.ssh/authorized_keys
You simply need to copy the contents of your public key into the file ~/.ssh/authorized_keys on the server. On the local machine, run:
ssh-copy-id root@your.ip.address
If you don't have the ssh-copy-id command, you can use:
cat ~/.ssh/id_rsa.pub | ssh root@your.ip.address "cat >> ~/.ssh/authorized_keys"
I have followed the steps required in order to get my SSH key going - I created the directory .ssh and the file authorized_keys under home/usr - I copied the contents of the public key straight from PuttyGen and pasted it into the file home/usr/.ssh/authorized_keys - I configured putty to use the correct private key file located on my windows machine When attempting to log in I get the message "Server refused our key" and then I'm prompted with a login. I have no idea what I'm doing wrong here...
  • Make sure the folder and the file have the correct permissions set:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
Hi! Thank you for answer. I have done it, however still not works. Doing many times in on other servers, I always had successful result. Can it be assumed that not working because I have created the droplet without key? Might there a method to assign a key for the droplet?
  • It should be possible to add a key after the fact. Though if you want to add the key using the control panel, you could take a snapshot of the droplet. Then create a new droplet using that snapshot remembering to add you key.
Do not forget check permissions 700 on directory and 600 on files and check to right owner. Directory /.ssh/ and all files should have owner who is owner home directory. It is usually is a login name.
Have another answer? Share your knowledge.