I have created file ssh-start.sh which contains:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
I'm running it and have output:
Agent pid 1234
Identity added: ~/.ssh/id_rsa (~/.ssh/id_rsa)
but when I run
ssh-add -l
I'm getting:
Could not open a connection to your authentication agent.
What am I doing wrong and how to fix that?
(when I run commands from ssh-start.sh file directly in terminal it works fine)
ssh command needs to know how to talk to the ssh-agent. They know that from the SSH_AUTH_SOCK environment variable.
[gc@slave4 ~]$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-ln4RuPajkE2A/agent.11091; export SSH_AUTH_SOCK;
SSH_AGENT_PID=11092; export SSH_AGENT_PID;
echo Agent pid 11092;
If you run ssh-add -l after the script, neither ssh nor ssh-add will be able to see that the SSH_AUTH_SOCK environment variable is set. So run all commands as part of a script or all from the command prompt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With