SSH

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/.ssh-agent.sh ]; then
ssh-agent -s > $HOME/.ssh-agent.sh
chmod o+x $HOME/.ssh-agent.sh
. $HOME/.ssh-agent.sh
# 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
else
. $HOME/.ssh-agent.sh
fi

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/.ssh-agent.sh ] ; 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/.ssh-agent.sh
fi

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.....

Comments

Popular posts from this blog

Kviknet and IPv6

Apple IOS cannot download song

Apple AirPort Express and Digital Jitter..