I am looking for a way to add my passphrase to ssh-agent using ssh-add once, and from thereonin, if I open a new shell to the machine where that ssh-agent is running, have my credentials previously added available, so I don't need to continually call ssh-add.
I am connecting from my home computer to a work vm over a vpn.
My work vm's ssh key has a passphrase, and I am finding I need to enter the passphrase in every shell I open, no matter if I've already added it using ssh-add in another shell.
On startup, the work vm is running ssh-agent:
$ ps -ef | grep ssh-agent
steve 1594 1537 0 17:17 ? 00:00:00 /usr/bin/ssh-agent /etc/X11/xinit/Xclients
steve 2686 2633 0 17:29 pts/1 00:00:00 grep --color=auto ssh-agent
However, the connection details are not present in my environment:
$ env | grep SSH
SSH_CONNECTION=10.0.20.73 40232 10.10.0.123 22
SSH_CLIENT=10.0.20.73 40232 22
SSH_TTY=/dev/pts/1
If I run eval $(ssh-agent), then I have a 2nd ssh-agent running, and the connection details for the 2nd instance are present in my environment:
$ eval $(ssh-agent)
Agent pid 2705
$ ps -ef | grep ssh-agent
steve 1594 1537 0 17:17 ? 00:00:00 /usr/bin/ssh-agent /etc/X11/xinit/Xclients
steve 2705 1 0 17:31 ? 00:00:00 ssh-agent
steve 2726 2633 0 17:31 pts/1 00:00:00 grep --color=auto ssh-agent
$ env | grep SSH
SSH_AUTH_SOCK=/tmp/ssh-ScGSgVMvxvS3/agent.2704
SSH_AGENT_PID=2705
SSH_CONNECTION=10.0.20.73 40232 10.10.0.123 22
SSH_CLIENT=10.0.20.73 40232 22
SSH_TTY=/dev/pts/1
I can now successfully add my passphrase to the agent using ssh-add.
$ ssh-add
Enter passphrase for /home/steve/.ssh/id_rsa:
Identity added: /home/steve/.ssh/id_rsa (steve@vm-foobar)
However, if I open a new shell connection to my work vm, I am back at square one again
$ ssh vm-foobar
Last login: Mon Aug 3 17:29:49 2020 from 10.0.20.73
$ env | grep SSH
SSH_CONNECTION=10.0.20.73 40306 10.10.0.123 22
SSH_CLIENT=10.0.20.73 40306 22
SSH_TTY=/dev/pts/2
$ ssh-add
Could not open a connection to your authentication agent.
Is it possible to configure my bash profile etc on my work vm so that if I add my passphrase in one shell, it will work if I open a new shell?