Skip to content

Instantly share code, notes, and snippets.

@tyru
Last active August 24, 2020 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/61307ae2dedc58fb53c0 to your computer and use it in GitHub Desktop.
Save tyru/61307ae2dedc58fb53c0 to your computer and use it in GitHub Desktop.
ssh-agent configuration
#!/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
#!/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