ssh-add over ssh

ssh-add picks up the agent fine when using X11, but when logged into a remote ssh session:

michael@apollo:~$ ssh-add
Could not open a connection to your authentication agent.

Ah, we have to fire up ssh-agent and cut/paste the env variables…

michael@apollo:~$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-erlzEU7907/agent.7907; export SSH_AUTH_SOCK;
SSH_AGENT_PID=7908; export SSH_AGENT_PID;
echo Agent pid 7908;
michael@apollo:~$ SSH_AUTH_SOCK=/tmp/ssh-erlzEU7907/agent.7907; export SSH_AUTH_SOCK; SSH_AGENT_PID=7908; export SSH_AGENT_PID;
michael@apollo:~$ ssh-add
Enter passphrase for /home/michael/.ssh/id_dsa:
Identity added: /home/michael/.ssh/id_dsa (/home/michael/.ssh/id_dsa)
michael@apollo:~$

Thanks, Brandon! 😉

One thought on “ssh-add over ssh”

  1. Here’s an even easier way in bash:

    drift@dalek:~$ eval `ssh-agent`
    Agent pid 22896

    Assuming you run an ssh-agent nearly all the time like I do, it makes a nice addition to your .bashrc.

Comments are closed.