Question

forced ssh-add?

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?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, @thenetimp

Thanks for confirming this. It may help other users experiencing the same issue.

Regards, Alex

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

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