blog/content/2015-01-09_ssh-agent-on-boot.rst

26 lines
870 B
ReStructuredText
Raw Normal View History

2022-10-17 01:59:22 +00:00
SSH Agent on “boot”
###################
:date: 2015-01-09 04:03
:author: tyrel
2022-10-17 03:02:04 +00:00
:category: Tech
:tags: linux, ssh
2022-10-17 01:59:22 +00:00
:slug: ssh-agent-on-boot
:status: published
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:
.. code-block:: bash
SSHKEYFILE=/path/to/your/ssh/key/file
ssh-add -l | grep -q $SSHKEYFILE
RC=$?
if [ $RC -eq 1 ]
then
ssh-add -t 86400 $SSHKEYFILE
echo "Added key internal to keychain."
fi
This will check every time your bash or zsh rc file is sourced for your key in the currently added keys, and if its 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).