My server is currently running Ubuntu 20.04.4. I work in an environment where most users use their login password to encrypt their ssh keys. (Yes, I am aware this is not as secure as possible. This is the point we've chosen on the convenience/security spectrum.) I would like to configure sshd on my server so that when users log in, it automatically launches ssh-agent, and adds their ssh keys to ssh-agent (as if they had typed ssh-add just after logging in), without the user having to type their password twice when they login. Is this possible, and if so, how do I do it?

(To be clear, I want to do this so that, once a user is logged into the machine running the sshd server, they can then do passwordless ssh into other machines in the building.)

  • @user68186 Once the user logs into the remote, they may then want to ssh into other remote computers, so they want to add their ssh keys in ~/.ssh on the remote to an ssh-agent running on the remote. In fact this is pretty common in the environment I'm talking about. Jun 13 at 21:48
  • Basically because of all the reasons listed here: security.stackexchange.com/questions/58457/… Jun 14 at 1:56

1 Answer 1


The most obvious answer is to remove the password required to access the ssh key so you can simply add the key in your login shell script. Which would make your system less secure and any other systems that are you use the ssh key to access.

Which is what I had to do on one system. Oddly, my ssh keys load on Ubuntu immediately upon login without the addition to my login shell script. I didn’t implement the secondary authorization requirement when generating the key, however. It really depends on how secure you need your system(s) to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.