Quick tip: Making ssh agent work in screen sessions
The only annoying this I find in the otherwise indispensable GNU Screen is the fact that once you have launched screen (not resume) and have detached and logged off the first time, ssh-agent magic stops working in the screen sessions.
Obviously this is because the next time you login, your ssh agent socket changes but the screen sessions still only have the location of the ssh-agent socket when you launched screen for the first time. The end result is that you start typing out passwords all over again, risking inadvertently revealing them to your colleague while you are showing him some stuff at your workstation.
There are scores of workarounds all over the net of how people have solved this problem. I just wanted to post here about how I work around this.
The work is actually done at the bottom of my .bashrc
which reads:
case "$TERM" in
screen)
source ~/.bashrc.ssh
;;
*)
echo "export SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" > ~/.bashrc.ssh
;;
esac
This will ensure that all new shell sessions in screen going forward will have the right ssh-agent socket info. For the sessions which are still open, just do a source ~/.bashrc.ssh
whenever you login next and resume screen.