I am running Ubuntu 16.04 within a Windows Subsystem for Linux (WSL) shell on Windows 10. From within a terminal I can start ssh-agent and use it many times over the life of that terminal. I can see the ssh-agent running from ps, and also from the Windows 10 task manager.

However, if I start a 2nd WSL bash terminal from the start menu, it is unaware of the ssh-agent. Oddly, if I start a 2nd terminal from the windows command line, it works. A possible workaround would be to open new bash windows from the existing one, but I don't know how to do that either.

Is there any solution to this?


Perhaps not: it sounds as if ssh-agent is being run in the usual way, where it is the parent process of your shell. That other window has its own hierarchy of process parent/child which doesn't tie into the window that you are using.

One way to work with this feature of ssh-agent is to run screen (or tmux) within the window where you have started the agent. Those screen/tmux windows are also children of the ssh-agent process, and can talk to it without problems.


You can modify your .bashrc to find an existing running ssh-agent.

I use something based on the gist

# ssh-agent configuration
if [ -z "$(pgrep ssh-agent)" ]; then
    rm -rf /tmp/ssh-*
    eval $(ssh-agent -s) > /dev/null
    export SSH_AGENT_PID=$(pgrep ssh-agent)
    export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.*)

# optional... potentially annoying
#if [ "$(ssh-add -l)" == "The agent has no identities." ]; then
#    ssh-add

I prefer this script that use ssh-add to find if your keys has already been added

ssh-add -l &>/dev/null
if [ "$?" == 2 ]; then
  test -r ~/.ssh-agent && \
    eval "$(<~/.ssh-agent)" >/dev/null

  ssh-add -l &>/dev/null
  if [ "$?" == 2 ]; then
    (umask 066; ssh-agent > ~/.ssh-agent)
    eval "$(<~/.ssh-agent)" >/dev/null

You can read more about it on: http://rabexc.org/posts/pitfalls-of-ssh-agents


There is now. Install the latest version of OpenSSH for windows, and then get the ssh-agent-wsl helper. Follow the instructions, and you'll very easily get a working way to share credentials across WSL and Windows! It works like a charm!

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.