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

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word

Set your Twitter account name in your settings to use the TwitterBar Section.