1

I have ssh-agent running on my desktop, and it works normally. That means I can use my ssh key without password.

When I connect to my desktop via ssh, I suddenly cannot use my ssh-agent - ssh asks me for password.

I can see with ps that ssh-agent is running.

When I do eval $(ssh-agent -s) && ssh-add, it will ask me for password and ssh-agent will work in current ssh session. As soon as I log out, and log in again, it no longer works.

Also, I see with ps that it has started new instance of ssh-agent. So I have multiple instances running.

Why does the agent not work when i connect via ssh? Why do I have to start new one each time?

I am using openssh-client version 1:7.9p1-10+deb10u2 on Debian 10, which is on both the client and server.

0
2

The ssh client uses a shell variable SSH_AUTH_SOCK to communicate with the ssh agent. This variable contains the socket where the agent listens. If it is not set, or not set correctly, your ssh client can't communicate with the agent.

I think this is what happens in your case:

  1. When you log on to your computer, SSH_AUTH_SOCK is not set. The ssh client doesn't know that there is an ssh agent.
  2. eval $(ssh-agent -s) launches another ssh agent and sets SSH_AUTH_SOCK in your current shell. The ssh client can communicate with the new agent.
  3. Then you log out and back in again, and SSH_AUTH_SOCK is, again, not set.

You could set SSH_AUTH_SOCK in your .bashrc so that all future bash sessions will get this variable set. You'd have to remember to update .bashrc each time you kill the ssh agent and run a new one.

1
  • You are right. SSH_AUTH_SOCK was not set in my shell. Exporting it solved the problem. Thank you Jul 22 at 11:16

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.