When setting up WSL, one of the first things I do is add the following snippet to the end of ~/.bashrc so all interactive shells have access to ssh-agent by default:
# Set up ssh-agent for WSL
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
touch $SSH_ENV
chmod 600 "${SSH_ENV}"
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >> "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
kill -0 $SSH_AGENT_PID 2>/dev/null || {
start_agent
}
else
start_agent
fi
Now, as discussed at https://stackoverflow.com/questions/18880024/start-ssh-agent-on-login this particular snippet has its drawbacks, but there still seems to be an opportunity here to have an off-by-default snippet in the default .bashrc that can be turned on with a simple flag like:
# Uncomment next line to automatically start ssh-agent when logging in to WSL
# AUTOSTART_SSH_AGENT=1
(Edit: I did consider proposing this to upstream Fedora instead, but I think the idea makes much less sense there, as Fedora Workstation already provides this functionality at the login manager level, and headless Fedora instances are far more likely to be server hosts than they are to be client development environments).
When setting up WSL, one of the first things I do is add the following snippet to the end of
~/.bashrc
so all interactive shells have access tossh-agent
by default:Now, as discussed at https://stackoverflow.com/questions/18880024/start-ssh-agent-on-login this particular snippet has its drawbacks, but there still seems to be an opportunity here to have an off-by-default snippet in the default
.bashrc
that can be turned on with a simple flag like:(Edit: I did consider proposing this to upstream Fedora instead, but I think the idea makes much less sense there, as Fedora Workstation already provides this functionality at the login manager level, and headless Fedora instances are far more likely to be server hosts than they are to be client development environments).