forced ssh-add?

Posted October 8, 2017 1.2k views
Linux BasicsUbuntu

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?

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.

Submit an Answer
3 answers

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/ | ssh demo@ "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?



The issue was I wasn’t using I had a key that was named id_rsa_someidentifier. I used my on the 2nd account which is why I got in. ssh by default only uses idrsa if you use a key that has a name other than idrsa 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.