blog/content/2015-01-09_ssh-agent-on-boot.rst
2022-10-16 21:59:22 -04:00

25 lines
853 B
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

SSH Agent on “boot”
###################
:date: 2015-01-09 04:03
:author: tyrel
:category: Linux
: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).