Created
March 20, 2017 17:30
-
-
Save grosscol/a39a4b906563c80baa8f549b1240a0e8 to your computer and use it in GitHub Desktop.
Auto add identity to ssh-agent
This file contains hidden or 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
# 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