Last active
August 24, 2020 14:14
-
-
Save tyru/61307ae2dedc58fb53c0 to your computer and use it in GitHub Desktop.
ssh-agent configuration
This file contains 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
#!/bin/bash | |
# Based on http://www.snowelm.com/~t/doc/tips/20030625.ja.html | |
[[ -f ~/.ssh-agent-info ]] && source ~/.ssh-agent-info >/dev/null | |
ssh-add -l >&/dev/null | |
if [ $? == 2 ]; then | |
# unable to contact the authentication agent | |
echo -n "ssh-agent: Restarted..." | |
ssh-agent >~/.ssh-agent-info | |
source ~/.ssh-agent-info | |
else | |
echo "ssh-agent: Running (pid $SSH_AGENT_PID)" | |
fi | |
if ssh-add -l >&/dev/null; then | |
echo "ssh-agent: Identity is already stored." | |
else | |
[ -x $HOME/bin/ssh-add-keys.exp ] && $HOME/bin/ssh-add-keys.exp >/dev/null | |
echo "ssh-agent: Added identities." | |
fi |
This file contains 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/expect | |
set github_id_rsa "$env(HOME)/.ssh/github_id_rsa" | |
set github_pass "xxxxxxxxxxxx" | |
set bitbucket_id_rsa "$env(HOME)/.ssh/bitbucket_id_rsa" | |
set bitbucket_pass "xxxxxxxxxxxxxxxx" | |
set timeout 10 | |
# GitHub | |
spawn ssh-add $github_id_rsa | |
expect "Enter passphrase for" { | |
send "$github_pass\r" | |
} | |
expect { | |
"denied" { | |
exit 1 | |
} | |
eof { | |
# exit 0 | |
} | |
} | |
# BitBucket | |
spawn ssh-add $bitbucket_id_rsa | |
expect "Enter passphrase for" { | |
send "$bitbucket_pass\r" | |
} | |
expect { | |
"denied" { | |
exit 1 | |
} | |
eof { | |
exit 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment