Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Window Subsystem for Linux ssh-agent Configuraton
# ... more above ...
# wsfl bash is not a login shell
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# ssh-agent configuration
if [ -z "$(pgrep ssh-agent)" ]; then
rm -rf /tmp/ssh-*
eval $(ssh-agent -s) > /dev/null
else
export SSH_AGENT_PID=$(pgrep ssh-agent)
export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.*)
fi
if [ "$(ssh-add -l)" == "The agent has no identities." ]; then
ssh-add
fi
@copperlight

This comment has been minimized.

Copy link
Owner Author

commented Aug 11, 2016

When you start the first instance of Bash on Ubuntu for Windows, it will request the passhphrase for your key.

Subsequent instances of Bash will use the running ssh-agent process and set the proper environment variables.

Test the configuration like so:

env |grep SSH
ssh-add -l

Shutting down all instances of Bash will shut down all processes and start the cycle again.

@ironland

This comment has been minimized.

Copy link

commented Aug 3, 2017

Thanks! One minor detail: You have to have double quotes around the agent.* value for the -name flag.

@jiggneshhgohel

This comment has been minimized.

Copy link

commented Aug 8, 2017

Just in case anybody ends up here and finds that his problem is not resolved I would request you to refer the following related gist Windows 10 Linux Subsystem SSH-agent issues

Thanks.

@Mattosx

This comment has been minimized.

Copy link

commented Nov 10, 2017

wsfl bash is not a login shell

if [ -d "$HOME/bin" ] ; then
export PATH="$HOME/bin:$PATH"
fi

ssh-agent configuration

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

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

语法有报错修正了下, 在本地wsl-terminal + zsh 环境, 添加到.zshrc 可以运行通过, 效果挺好的

@gomker

This comment has been minimized.

Copy link

commented Jul 5, 2018

FYI this is broken in in 18.04 Ubuntu on Windows 10 WSL
microsoft/WSL#3183

@beeven

This comment has been minimized.

Copy link

commented Jul 9, 2018

@gomker Fixed in Windows 10 build 17711. But characters not in ASCII display as squares in this build. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.