Using ssh-agent in a screen session
If you want to connect to your ssh-agent in a re-attached screen session, so that the ssh-add command can find the agent read the following.
When the ssh-agent ist started it sets the environment variable SSH_AUTH_SOCK where the path to the socket is saved, e.g. /tmp/ssh-ST7m8fro3T/agent.89828. Because the socket changes everytime you start a new ssh-agent session, create a symbolic link:
ln -sf "$SSH_AUTH_SOCK" "/tmp/ssh-agent-$USER-screen"
and place this line in your .tcshrc or whatever config file your shell
uses.
Next, add the line setenv SSH_AUTH_SOCK "$SSH_AUTH_SOCK"
into your ~/.screenrc so that screen knows where to find the agent's
socket.
Start a screen session, launch a ssh-agent inside of it and detach the screen session.
Re-attach it and try the ssh-add command. If it all worked, you should be abled to enter your passphrase and use public key authentication everytime you re-attach your screen without typing the passphrase.
With this nice trick it's possible for example to use the amarok_ssh script for irssi that connects to your locally running amaroK session via ssh and take control of it.
For the impatient:
- echo ln -sf "$SSH_AUTH_SOCK" "/tmp/ssh-agent-$USER-screen" >> ~/.tcshrc
- echo setenv SSH_AUTH_SOCK "$SSH_AUTH_SOCK" >> ~/.screenrc
- source .tcshrc
- screen
- e.g.: ssh-agent irssi
- ctrl+a d
- screen -r
- in irssi: /exec ssh-add