Skip to content

Instantly share code, notes, and snippets.

@treffynnon
Created April 26, 2011 10:24
Show Gist options
  • Save treffynnon/942082 to your computer and use it in GitHub Desktop.
Save treffynnon/942082 to your computer and use it in GitHub Desktop.
# File: ~/.bash_profile
# source ~/.profile, if available
if [[ -r ~/.profile ]]; then
. ~/.profile
fi
# start agent and set environment variables, if needed
agent_started=0
if ! env | grep -q SSH_AGENT_PID >/dev/null; then
echo "Starting ssh agent"
eval $(ssh-agent -s)
agent_started=1
fi
# ssh become a function, adding identity to agent when needed
ssh() {
if ! ssh-add -l >/dev/null 2>-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/ssh "$@"
}
git() {
if ! ssh-add -l >/dev/null 2>-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/git "$@"
}
export -f ssh
export -f git
simon@simon-ubuntu64:~ $ ssh staging
Linux staging-guest 2.6.35-27-server #48-Ubuntu SMP Tue Feb 22 21:53:16 UTC 2011 x86_64 GNU/Linux
Ubuntu 10.10
Welcome to the Ubuntu Server!
* Documentation: http://www.ubuntu.com/server/doc
53 packages can be updated.
29 updates are security updates.
Last login: Tue Apr 26 11:16:50 2011 from simon-ubuntu64.local
Starting ssh agent
Agent pid 11033
Enter passphrase for /home/simon/.ssh/id_rsa:
simon@staging-guest:~ $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment