Advertisement
vstraylight

Bash function to reset SSH_AUTH_SOCK

Nov 8th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.72 KB | None | 0 0
  1. # This is a mashup of two solutions I found to the problem of connecting old screen sessions to the
  2. # current ssh-agent.
  3. #
  4. # I got the find command from: http://www.tolaris.com/2011/07/12/reconnecting-your-ssh-agent-to-a-detached-gnu-screen-session/
  5. #
  6. # I got the original ssh-reagent function from: http://sweetjesus26.livejournal.com/16782.html
  7.  
  8. # Find a usable agent
  9. function ssh-reagent () {
  10.   export SSH_AUTH_SOCK=$(find /tmp/ssh-* -user `whoami` -name agent\* -printf '%T@ %p\n' 2>/dev/null | sort -k 1nr | sed 's/^[^ ]* //' | head -n 1)
  11.   if $(ssh-add -l > /dev/null) ; then
  12.     echo Found working SSH Agent:
  13.     ssh-add -l
  14.     return
  15.   fi
  16.   echo Cannot find ssh agent - maybe you should reconnect and forward it?
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement