From: Alex Dehnert Date: Fri, 25 Jun 2010 07:51:16 +0000 (-0400) Subject: sshroot: better handling of getting keys X-Git-Url: https://www.dehnerts.com/gitweb/?p=user%2Falex%2Fsoftware%2Fmy-snippets.git;a=commitdiff_plain;h=5ec775cdf19bf05c4948af3045fbf7abf17679f2 sshroot: better handling of getting keys * Rename with-keys to with-agent to better reflect what it does * Make a new with-keys that does the same thing as with-agent, except that it passes $keys to keychain so that those keys are actually unlocked * Divide between using with-keys and with-agent more-or-less reasonably --- diff --git a/sshroot b/sshroot index bac5534..6a0c4b5 100755 --- a/sshroot +++ b/sshroot @@ -9,6 +9,13 @@ hostopt="" keys=~/.ssh/id_rsa_root function with-keys +{ + unset SSH_AUTH_SOCK SSH_AGENT_PID + eval $(keychain --eval --host "$hostopt-root" $keys) + exec "$@" +} + +function with-agent { unset SSH_AUTH_SOCK SSH_AGENT_PID eval $(keychain --eval --host "$hostopt-root") @@ -21,17 +28,17 @@ shift case "$command" in init) echo "Loading default keys (lifetime $lifetime)..." - with-keys ssh-add -t $lifetime "$@" $keys + with-agent ssh-add -t $lifetime "$@" $keys ;; add) echo "Loading keys (lifetime $lifetime):" "$@" - with-keys ssh-add -t $lifetime "$@" + with-agent ssh-add -t $lifetime "$@" ;; list) - with-keys ssh-add -l + with-agent ssh-add -l ;; destroy) - with-keys ssh-add -D + with-agent ssh-add -D ;; shell) with-keys $SHELL @@ -50,7 +57,7 @@ case "$command" in echo " $0 [cmd]" >&2 else echo Executing: "$command" "$@" - with-keys "$command" "$@" + with-agent "$command" "$@" fi ;; esac