Skip to content

Instantly share code, notes, and snippets.

@grosscol
Created March 20, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosscol/a39a4b906563c80baa8f549b1240a0e8 to your computer and use it in GitHub Desktop.
Save grosscol/a39a4b906563c80baa8f549b1240a0e8 to your computer and use it in GitHub Desktop.
Auto add identity to ssh-agent
# If logging into mimosa
# start ssh-agent and add key(s)
BASTION_HOST='bastion.example.com'
if [[ ${HOSTNAME} = ${BASTION_HOST} ]]; then
# start ssh-agent if not running
if [ -z "$SSH_AUTH_SOCK" ]; then
eval `/usr/bin/ssh-agent -s`
fi
# Add ssh-key if not present
FINGERPRINT=$(ssh-keygen -lf /l/local/ssh/${USER}/id_ecdsa.pub)
if [[ `ssh-add -l` == ${FINGERPRINT} ]]; then
echo 'admin identity aldready added.'
else
/usr/bin/ssh-add -t 8h /l/local/ssh/${USER}/id_ecdsa
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment