Skip to content

Instantly share code, notes, and snippets.

@justinribeiro
Last active December 20, 2021 08:42
Show Gist options
  • Save justinribeiro/b4fd5039e3b8eb6463f9157a0fa066dd to your computer and use it in GitHub Desktop.
Save justinribeiro/b4fd5039e3b8eb6463f9157a0fa066dd to your computer and use it in GitHub Desktop.
ssh-agent-windows
  1. Open git-bash on Windows.
  2. Make sure you have a .profile: touch .profile
  3. Open .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
  1. Verify that you have your private key set at ~/.ssh/id_rsa.
  2. Re-open git-bash, you should be prompted for the passphrase for ~/.ssh/id_rsa
@lolmaus
Copy link

lolmaus commented Dec 1, 2020

Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment