Tyrel's Blog

Code, Flying, Tech, Automation

Jan 09, 2015

SSH Agent on "boot"

I had a friend complain that he had to keep adding his ssh key to his ssh-agent every time he rebooted. I have a really easy bit of shell code you can put into your .bashrc or your .zshrc file:

ssh-add -l | grep -q $SSHKEYFILE
if [ $RC -eq 1 ]
    ssh-add -t 86400 $SSHKEYFILE
echo "Added key internal to keychain."

This will check every time your bash or zsh rc file is sourced for your key in the currently added keys, and if it's not, it will add it.

This has the benefit of not requiring you to put in your password every time you connect to a remote machine if you password your ssh keys (which you should).

 · · ·  linux  ssh