Skip to content

Instantly share code, notes, and snippets.

@Peregrinox
Last active August 27, 2024 03:13
Show Gist options
  • Save Peregrinox/1bbec6ba5d02f93b977be597907d72a0 to your computer and use it in GitHub Desktop.
Save Peregrinox/1bbec6ba5d02f93b977be597907d72a0 to your computer and use it in GitHub Desktop.

Revisions

  1. Peregrinox revised this gist Apr 10, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git bash ssh agent.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@ https://stackoverflow.com/questions/18404272/running-ssh-agent-when-starting-git

    https://help.github.com/articles/working-with-ssh-key-passphrases/#auto-launching-ssh-agent-on-git-for-windows

    I needed this to launch the ssh agent on my windows git bash sessions.

    edit or create .profile and add:

    env=~/.ssh/agent.env
  2. Peregrinox created this gist Apr 10, 2018.
    29 changes: 29 additions & 0 deletions git bash ssh agent.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    https://stackoverflow.com/questions/18404272/running-ssh-agent-when-starting-git-bash-on-windows

    https://help.github.com/articles/working-with-ssh-key-passphrases/#auto-launching-ssh-agent-on-git-for-windows

    edit or create .profile and add:

    env=~/.ssh/agent.env

    agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

    agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

    agent_load_env

    # agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
    agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

    if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
    elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
    fi

    unset env

    and restart your shell