I am very keen user of ssh, and what can frustrate me, is that I have to type passwords again and again. So after some digging around I found a solution.

Add the following to you .bash_profile
if [ ! -f $HOME/ ]; then
ssh-agent -s > $HOME/
chmod o+x $HOME/
. $HOME/
# I don't have the ssh-add myself as I don't always need to have a password
# (don't ask me why)
# ssh-add
. $HOME/

trap "$HOME/.bash_logout" 0

And this to your .bash_logout
if [ "`ps aux | grep $UID | grep @pts | grep -v grep | wc -l | xargs printf "%d"`" -le 1 -a -f $HOME/ ] ; then
echo "This appears to be your last login on this machine, removing agent"
ssh-add -D 2>&1 > /dev/null
ssh-agent -k 2>&1 > /dev/null
rm $HOME/

I know that it could be done with 'who' but as I have usernames which are longer than 8 characters this was what I could come up with.

Happy hacking.....


Popular posts from this blog

Kviknet and IPv6

Apple AirPort Express and Digital Jitter..

Apple IOS cannot download song