Implement a simple module that automatically launches the ssh-agent when you login and
adds your default key.
Useful for anyone that does remote work and thus doesn't have access to a keychain tool.
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
0 |
+# Based on code from Joseph M. Reagle |
|
1 |
+# http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html |
|
2 |
+ |
|
3 |
+local SSH_ENV=$HOME/.ssh/environment |
|
4 |
+ |
|
5 |
+function start_agent { |
|
6 |
+ /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV} |
|
7 |
+ chmod 600 ${SSH_ENV} |
|
8 |
+ . ${SSH_ENV} > /dev/null |
|
9 |
+ /usr/bin/ssh-add; |
|
10 |
+} |
|
11 |
+ |
|
12 |
+# Source SSH settings, if applicable |
|
13 |
+ |
|
14 |
+if [ -f "${SSH_ENV}" ]; then |
|
15 |
+ . ${SSH_ENV} > /dev/null |
|
16 |
+ #ps ${SSH_AGENT_PID} doesn't work under cywgin |
|
17 |
+ ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { |
|
18 |
+ start_agent; |
|
19 |
+ } |
|
20 |
+else |
|
21 |
+ start_agent; |
|
22 |
+fi |
|
23 |
+ |