Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created August 24, 2020 14:15
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 wpsmith/de9ae587d9be6ab08d1f86baba4f3b7f to your computer and use it in GitHub Desktop.
Save wpsmith/de9ae587d9be6ab08d1f86baba4f3b7f to your computer and use it in GitHub Desktop.
Shell: Adds ssh keys to ssh agent.
#!/usr/bin/env bash
function ssh-keys () {
if ssh-add -l | grep -q "$1"; then
echo "$1 key is ready"
else
/usr/bin/expect -c "
spawn /usr/bin/ssh-add $1;
expect 'Enter passphrase';
send $2\r;
expect eof;"
fi
}
#get passwords from credstash
prod_pass=$(credstash -p prod get prod-key-password)
eng_pass=$(credstash -p dev get eng-key-password)
#call function that to add them. example: ssh-keys [path to key] [password]
ssh-keys $HOME/.ssh/production $prod_pass
ssh-keys $HOME/.ssh/engineering $eng_pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment