On my Linux system, I decrypt a private ssh key every time when I boot the system. Once booted I open a terminal and issue:

ssh-add ~/.ssh/id_rsa_some_key

and I am ready to perform git operations, like git clone <git-url>, git pull -a and so on. When I open another terminal and issue such commands again, no prompt will pop up that asks to enter the password of the encrypted ssh-key. In summary, on my linux system I only have to enter the password once.


On my work I have a Windows system. Once booted, I open git-bash and issue:

eval $(ssh-agent)

and ssh-add ~/.ssh/private_key, enter the password and issue git commands that are able to communicate with the git repository. In contrast to my Linux system, when I open a new git-bash and issue git commands, then a prompt appears that asks to enter the password. In summary, when the private key has been decrypted in a git-bash terminal, then it is possible to interact with git repository, but when a new terminal is opened the ssh-key should be decrypted again.

What did I try

I tried to use pageant. This first problem is that the id_rsa was not suitable. A new key had to be created using puttygen, but then it turned out that it will not be possible to use the ssh git url that starts with git@. It had to be replaced with the https url, but that is not what I want.

What answer do I prefer

I prefer an answer that satisfies the following criteria:

  1. Ssh key has to be decrypted once when the Windows system has been booted and a terminal is opened to perform git actions
  2. When a new terminal is opened, one could continue to interact with the git repository, i.e. no prompt will pop up that requests to enter the password.
  3. I am not devoted to git-bash. If there is another terminal on windows that matches the first two criteria then it is fine by me.

The command

eval $(ssh-agent)

starts the SSH agent process (equivalent to Pageant), and creates typically two environment variables: SSH_AUTH_SOCK and SSH_AGENT_PID (at least on Linux, don't know if Windows git-bash makes any difference here; probably not).

If the SSH_AUTH_SOCK variable is set and points to a valid authentication agent socket, any process that can read the variable can use it. So you just need a way to have the value of this variable propagate from one git-bash session to another. The SSH_AGENT_PID variable is just a convenience, to allow the agent to be easily killed of if/when needed.

If you can store those environment variables (or even just SSH_AUTH_SOCK) in a file, so that your subsequent git-bash windows can read it, you can script it in this way:

Whenever a new git-bash is started (i.e. with the .bashrc script or its git-bash equivalent)

  • check for the existence of the SSH agent environment variable file
  • if the file exists:
    • read it
    • if the agent socket (and optionally the process) listed in the file still exists, use the variables as-is in your current session
  • else (i.e. if the file was not there or its information was stale):
    • run eval $(ssh-agent)
    • create a new SSH agent environment variable file
  • done!

Also, you might need to enter the SSH git URL in full form, that is, instead of just git@server.name/project.git, you should type it like this:


Technically, the form without the ssh:// prefix is just a short-hand that is more convenient to type on the command line.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.