Browse code

bashrc - v1.7 & bash_profile (cygwin) - v1.3

Update of bashrc and bash_profile to add ssh key lifetime (or any ssh-agent option) to the start_agent function and use it in the bash_profile on cygwin.

Fred authored on26/09/2014 00:02:01
Showing2 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 # Title: .bashrc
2 2
 # Author: Frédéric CHEVALIER <f15.chevalier@gmail.com>
3
-# Version: 1.6
3
+# Version: 1.7
4 4
 # Created in: 2012-05-26
5
-# Modified in: 2014-08-16
5
+# Modified in: 2014-09-25
6 6
 
7 7
 
8 8
 
... ...
@@ -19,6 +19,7 @@
19 19
 # Versions #
20 20
 #==========#
21 21
 
22
+# v1.7 - 2014-09-25: start_agent function improved
22 23
 # v1.6 - 2014-08-16: new history entries to ignore / screen and :q aliases
23 24
 # v1.5 - 2014-08-06: autocd set on / R alias added /bk function turned in a separate script / SSH environment setup moved in bash_profile
24 25
 # v1.4 - 2014-07-26: ssh_agent function for SSH key management added / ssh_agent called when used SSH connexion / wf alias updated
... ...
@@ -355,8 +356,8 @@ function start_agent {
355 356
     chmod 600 "${SSH_ENV}"
356 357
     source "${SSH_ENV}" > /dev/null
357 358
 
358
-    # SSH key add
359
-    ssh-add
359
+    # SSH key add ($@: useful to add ssh-add options like lifetime directly through start_agent)
360
+    ssh-add $@ 
360 361
 }
361 362
 
362 363
 
... ...
@@ -1,14 +1,15 @@
1 1
 # Title: .bash_profile
2 2
 # Author: Frédéric CHEVALIER <f15.chevalier@gmail.com>
3
-# Version: 1.2
3
+# Version: 1.3
4 4
 # Created in: 2014-01-07
5
-# Modified in: 2014-08-26
5
+# Modified in: 2014-09-25
6 6
 
7 7
 
8 8
 #==========#
9 9
 # Versions #
10 10
 #==========#
11 11
 
12
+# v1.3 - 2014-09-25: start_agent with limited ssh key lifetime added
12 13
 # v1.2 - 2014-08-26: CHERE_INVOKING variable added 
13 14
 # v1.1 - 2014-08-20: multiscreen remove because of .screenrc set up / Java variables added
14 15
 # v1.0 - 2014-08-11: rewriting for better interplay with .bashrc
... ...
@@ -60,3 +61,24 @@ export PATH=$PATH:$JAVA_HOME/bin
60 61
 
61 62
 # Chere variable (read by /etc/profile - important to start new shell session from current directory instead of $HOME)
62 63
 export CHERE_INVOKING=1
64
+
65
+# SSH environment setup
66
+lifetime=259200 # seconds => 3 days
67
+if [[ -f "${SSH_ENV}" ]]
68
+then
69
+    source "${SSH_ENV}" > /dev/null
70
+    
71
+    # Check if ssh-agent is active
72
+    #ps ${SSH_AGENT_PID} doesn't work under cywgin
73
+    if [[ ! $(ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$) ]]
74
+    then
75
+        start_agent -t $lifetime
76
+    # Check if the ssh key is still stored
77
+    elif [[ $(ssh-add -l &> /dev/null; echo $?) != 0 ]]
78
+    then
79
+        pkill ssh-agent
80
+        start_agent -t $lifetime
81
+    fi
82
+else
83
+    start_agent -t $lifetime
84
+fi