I'm trying to use SSH Agent for a git authentication. My environment is Ubuntu Linux in Docker on ECS. I'm starting the SSH Agent when the container starts with a command:
runuser -l user -c 'ssh-agent -d'
That starts agent using user user
with debug. Right after that, I wrote SSH_AUTH_SOCK
and SSH_AGENT_PID
into /home/user/.profile
to make possible to connect to agent for the user
.
When I log in as a user
, I can see that my env variables are ok:
[user]$ echo $SSH_AUTH_SOCK && echo $SSH_AGENT_PID
/tmp/ssh-z5omIr4XkN49/agent.65
65
And the agent is running:
[user]$ ps -efal | grep ssh-agent
4 S root 62 59 0 80 0 - 37521 - 14:32 ? 00:00:00 /usr/bin/qemu-x86_64 /usr/sbin/runuser -l user -c ssh-agent -d
4 S user 65 62 0 80 0 - 37672 - 14:32 ? 00:00:00 /usr/bin/qemu-x86_64 /usr/bin/ssh-agent -d
And socket permissions are fine:
[user]$ ls -lh /tmp/ssh-FMgHCgorQ36E/agent.65
srw------- 1 user root 0 Mar 12 14:32 /tmp/ssh-FMgHCgorQ36E/agent.65
But when I'm trying to use the ssd-add
command, I'm getting a connection error:
[user]$ ssh-add -l
Could not open a connection to your authentication agent.
What am I doing wrong?
I checked out this answer (Could not open a connection to your authentication agent) but it does not work for me because I have to start SSH Agent in my script, without forcing the user
to do that.
--
UPDATE
I guess that ssh-add
does not read env variables for some reason.
The SSH_AUTH_SOCK
is set:
[user]$ echo $SSH_AUTH_SOCK
/tmp/ssh-FN4YayNM6fJ1/agent.65
But:
[user]$ ssh-add -l
Could not open a connection to your authentication agent.
But this works:
[user]$ SSH_AUTH_SOCK=/tmp/ssh-FN4YayNM6fJ1/agent.65 ssh-add -l
4096 SHA256:xvtWid6fm7C9LgyhosVOULo9HZQchve4rUVUgUO2zqE (stdin) (RSA)
CodePudding user response:
Your SSH_AGENT_PID (59) is not right, you should use 65.
CodePudding user response:
My bad. I was confused about the echo $SSH_AUTH_SOCK
result.
I missed the export
keyword when updating the .profile
file by my script.
SSH_AUTH_SOCK=/tmp/ssh-Y3YbbJ4ZTGyp/agent.59
SSH_AGENT_PID=59
should be:
export SSH_AUTH_SOCK=/tmp/ssh-Y3YbbJ4ZTGyp/agent.59
export SSH_AGENT_PID=59