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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
$NetBSD: patch-aa,v 1.2 2001/09/19 13:48:01 wiz Exp $
--- keychain.orig Mon Sep 10 04:42:47 2001
+++ keychain Wed Sep 19 13:17:34 2001
@@ -6,7 +6,7 @@
version=1.2
-trap "" INT
+trap "" 2
PATH="/sbin:/usr/sbin:${PATH}"; export PATH;
KEYCHAIN_KEYS=""
for x in ${*}
@@ -19,10 +19,11 @@
fi
done
-BLUE="\033[34;01m"
-GREEN="\033[32;01m"
-OFF="\033[0m"
-CYAN="\033[36;01m"
+# Some terminals don't support colors
+BLUE=
+GREEN=
+OFF=
+CYAN=
echo
echo -e "${GREEN}KeyChain ${version}; ${BLUE}http://www.gentoo.org/projects/keychain${OFF}\n Copyright 2001 Gentoo Technologies, Inc.; Distributed under the GPL"
@@ -46,20 +47,20 @@
Keychain is an OpenSSH key manager, typically run from ~/.bash_profile. When
run, it will make sure ssh-agent is running; if not, it will start ssh-agent.
- It will redirect ssh-agent's output to ~/.ssh-agent, so that cron jobs that
- need to use ssh-agent keys can simply source this file and make the necessary
- passwordless ssh connections. In addition, when keychain runs, it will check
- with ssh-agent and make sure that the ssh RSA/DSA keys that you specified on
- the keychain command line have actually been added to ssh-agent. If not, you
- are prompted for the appropriate passphrases so that they can be added by
- keychain.
+ It will redirect ssh-agent's output to ~/.ssh-agent-\`hostname\`, so that cron
+ jobs that need to use ssh-agent keys can simply source this file and make the
+ necessary passwordless ssh connections. In addition, when keychain runs, it
+ will check with ssh-agent and make sure that the ssh RSA/DSA keys that you
+ specified on the keychain command line have actually been added to ssh-agent.
+ If not, you are prompted for the appropriate passphrases so that they can be
+ added by keychain.
Typically, one uses keychain by adding the following to the top of their
~/.bash_profile (or ~/.zshrc, in case of zsh):
EOHELP
echo -e " ${CYAN}keychain ~/.ssh/id_rsa ~/.ssh/id_dsa"
-echo -e " source ~/.ssh-agent > /dev/null${OFF}"
+echo -e " . ~/.ssh-agent-\`hostname\` > /dev/null${OFF}"
echo -e " # the > /dev/null eliminates the redundant agent PID output"
echo
cat <<EOHELP
@@ -86,8 +87,9 @@
echo
cat <<EOHELP
This option tells keychain do everything it normally does (ensure ssh-agent is
- running, set up the ~/.ssh-agent file) except that it will not prompt you to
- add any of the keys you specified if they haven't yet been added to ssh-agent.
+ running, set up the ~/.ssh-agent-\`hostname\` file) except that it will not
+ prompt you to add any of the keys you specified if they haven't yet been
+ added to ssh-agent.
EOHELP
echo -e " ${GREEN}--stop${OFF}"
@@ -102,14 +104,14 @@
fi
-if [ ! -f ~/.ssh-agent ]
+if [ ! -f ~/.ssh-agent-`hostname` ]
then
- echo -e " ${GREEN}*${OFF} Initializing ~/.ssh-agent file..."
- touch ~/.ssh-agent || ( echo "$0: Cannot create ~/.ssh-agent, exiting." 1>&2 && exit 1 )
- chmod 0600 ~/.ssh-agent
+ echo -e " ${GREEN}*${OFF} Initializing ~/.ssh-agent-`hostname` file..."
+ touch ~/.ssh-agent-`hostname` || ( echo "$0: Cannot create ~/.ssh-agent-`hostname`, exiting." 1>&2 && exit 1 )
+ chmod 0600 ~/.ssh-agent-`hostname`
SSH_AGENT_PID="NULL"
else
- source ~/.ssh-agent > /dev/null
+ . ~/.ssh-agent-`hostname` > /dev/null
fi
match="no"
@@ -127,10 +129,10 @@
if [ "$match" = "no" ]
then
- chmod 0600 ~/.ssh-agent
+ chmod 0600 ~/.ssh-agent-`hostname`
echo -e " ${GREEN}*${OFF} starting new ssh-agent"
- nohup ssh-agent > ~/.ssh-agent
- source ~/.ssh-agent > /dev/null
+ nohup ssh-agent > ~/.ssh-agent-`hostname`
+ . ~/.ssh-agent-`hostname` > /dev/null
fi
if [ -n "`echo $* | grep '\-\-clear'`" ]
|