Skip to content

Instantly share code, notes, and snippets.

@janosgyerik
Created April 29, 2012 07:10
Show Gist options
  • Save janosgyerik/06217445c76729e05297 to your computer and use it in GitHub Desktop.
Save janosgyerik/06217445c76729e05297 to your computer and use it in GitHub Desktop.
Setup ssh agent automatically on login
# ssh agent setup
SSH_ENV=$HOME/.ssh/env
start_ssh_agent() {
ssh-agent > $SSH_ENV
. $SSH_ENV
}
check_ssh_agent() {
. $SSH_ENV && test "$SSH_AGENT_PID" && ps -p $SSH_AGENT_PID >/dev/null
}
check_ssh_identity() {
ssh-add -L >/dev/null
}
add_ssh_identity() {
ssh-add
}
ssh_agent_setup() {
check_ssh_agent || start_ssh_agent && check_ssh_identity || add_ssh_identity
}
ssh_agent_setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment