Created
December 13, 2018 23:32
-
-
Save kg6zjl/3cbc08ce9a71fdac2cf160fd04e13d65 to your computer and use it in GitHub Desktop.
Bash/Expect to add password protected ssh keys to agent, using creds from credstash
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
| #!/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