When you first setup a droplet if you added a ssh public key to the server in order to log in to the server you must use ssh-add <path-to-key> in order to log in as root. However if I create a new user, and dump that same key (or even a different one) into it’s authorized_keys file then I am able to ssh in directly to that new user without using ssh-add. Can someone explain to me why I can log into one but not the other without using ssh-add?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Alex,
The issue was I wasn’t using id_rsa.pub I had a key that was named id_rsa_someidentifier. I used my id_rsa.pub on the 2nd account which is why I got in. ssh by default only uses id_rsa if you use a key that has a name other than id_rsa you have to use ssh-add to tell ssh about the key.
Hello, @thenetimp
Thanks for confirming this. It may help other users experiencing the same issue.
Regards, Alex
Hello, @thenetimp
If you add your ssh pub key in the authorized_keys file then you will be able to ssh to that user without using the ssh-add command that is correct. Using ssh to paste your key is one of the most used ways to do that. You can use the following command to do it:
cat ~/.ssh/id_rsa.pub | ssh demo@198.51.100.0 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
As far as I understand you can’t access the other username for which you’ve used the ssh-add command to add the key?
Regards, Alex
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.