Guest User

Untitled

a guest
Nov 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. # Place this in git_root/etc/profile to have your passphrase only required once per session.
  2. # This used to be part of the help.github docs; for whatever reason it was removed when their new app come out. =/
  3.  
  4.  
  5. SSH_ENV="$HOME/.ssh/environment"
  6.  
  7. # start the ssh-agent
  8. function start_agent {
  9. echo "Initializing new SSH agent..."
  10. # spawn ssh-agent
  11. ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
  12. echo succeeded
  13. chmod 600 "$SSH_ENV"
  14. . "$SSH_ENV" > /dev/null
  15. ssh-add
  16. }
  17.  
  18. # test for identities
  19. function test_identities {
  20. # test whether standard identities have been added to the agent already
  21. ssh-add -l | grep "The agent has no identities" > /dev/null
  22. if [ $? -eq 0 ]; then
  23. ssh-add
  24. # $SSH_AUTH_SOCK broken so we start a new proper agent
  25. if [ $? -eq 2 ];then
  26. start_agent
  27. fi
  28. fi
  29. }
  30.  
  31. # check for running ssh-agent with proper $SSH_AGENT_PID
  32. if [ -n "$SSH_AGENT_PID" ]; then
  33. ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
  34. if [ $? -eq 0 ]; then
  35. test_identities
  36. fi
  37. # if $SSH_AGENT_PID is not properly set, we might be able to load one from
  38. # $SSH_ENV
  39. else
  40. if [ -f "$SSH_ENV" ]; then
  41. . "$SSH_ENV" > /dev/null
  42. fi
  43. ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent > /dev/null
  44. if [ $? -eq 0 ]; then
  45. test_identities
  46. else
  47. start_agent
  48. fi
  49. fi
Add Comment
Please, Sign In to add comment