-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotbash_keys
54 lines (50 loc) · 1.41 KB
/
dotbash_keys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# Alex's .bashrc_keys
#
# Generic handling for all keys, possibly using keychain if we have it.
#
KEYCHAIN=$(find_alternatives keychain)
KEYMSG=""
if shopt -q login_shell; then
if [[ -x ${KEYCHAIN} ]]; then
if [[ -S ${SSH_AUTH_SOCK} ]]; then
keychain -q -k all --inherit any --agents ssh --systemd
KEYMSG+="forwarded ssh"
else
keychain -q -k others --clear --agents ssh --systemd
KEYMSG+="local ssh"
fi
# ensure we flush
keychain -q --inherit any --agents ssh
else
# delete default ids
ssh-add -d
KEYMSG+="missing keychain"
fi
else
# non-login shell, don't attempt to start anything
if [[ -x ${KEYCHAIN} ]]; then
eval `keychain -q --inherit any --eval`
KEYMSG+="keychain agents"
else
KEYMSG+="missing keychain"
fi
fi
#
# When I log on remotely I only have console mode and as such I need to reset
# gpg-agent so it won't leave passphrase prompts on the X session. The killalls
# unwedge any gpg passphrase requests that might be running before reloading.
#
function reset_gpg_agent
{
if [[ -x ${KEYCHAIN} ]]; then
keychain --agents gpg --stop all
killall -9 gpg2 pinentry 2> /dev/null
sleep 1
killall -9 gpg2 pinentry 2> /dev/null
. ~/.bash_keys
fi
}
alias .keys=". ~/.bash_keys"
echo "loading .bash_keys ($KEYMSG)"