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.
Best Answer
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:
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.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.