Created
August 8, 2011 21:47
-
-
Save statico/1132839 to your computer and use it in GitHub Desktop.
Starting an ssh-agent once and restoring the session later. A really lightweight version of the `keychain` script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function which restarts the ssh-agent, saves the output to a file which can | |
# be sourced later, and adds the default ssh key. | |
sshenv=$HOME/.sshlocal | |
function init-ssh-agent() { | |
# Kill the agent if it's running. | |
if [ -n "$SSH_AGENT_PID" ]; then | |
echo "Killing existing agent $SSH_AGENT_PID..." | |
kill $SSH_AGENT_PID | |
fi | |
# Run the agent and add the key. | |
ssh-agent -s > $sshenv | |
. $sshenv | |
ssh-add | |
} | |
if [ "$(hostname)" == "xxxx" ]; then | |
if [ -e $sshenv ]; then | |
echo "Restoring ssh-agent environment..." | |
. $sshenv | |
fi | |
# If there is no ssh-agent PID or it's set but not running, restart it. | |
if [ -z "$SSH_AGENT_PID" -o ! -e /proc/$SSH_AGENT_PID ]; then | |
echo "SSH agent doesn't seem to be running. Restarting..." | |
init-ssh-agent | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm an idiot. Just use Keychain. http://docs.funtoo.org/wiki/Keychain