I’ve been wrestling with SSH key management in WSL for way longer than I care to admit. The problem? I had my SSH keys set up perfectly in Windows with the SSH agent running, but WSL insisted on using its own SSH client that couldn’t talk to the Windows agent. I’m honestly surprised it isn’t baked into WSL at this point. I stumbled on this blog post (and just read the tldr honestly), and this is my approach.

The Problem

WSL has its own SSH client, but if you’re like me and have your keys managed by the Windows SSH agent, you’re stuck entering passphrases constantly. It’s annoying and defeats the whole point of having an SSH agent in the first place.

The Solution

Here’s what actually works (and I wish I’d known this months ago):

Step 1: Alias SSH to use Windows

Add this to your .bashrc or .zshrc:

alias ssh='ssh.exe'

Step 2: Tell Git to use Windows SSH too

Next, we tell git which SSH client to use:

git config --global core.sshCommand "ssh.exe"

That’s it!

Why This Works

You can run windows commands from within WSL, so if we run ssh.exe instead of ssh, it runs the Windows SSH client instead of the Linux SSH client, and the Windows client knows how to talk to the agent.

The Git configuration ensures that when Git needs SSH (for cloning, pushing, etc.), it uses the same Windows SSH that can talk to your Windows SSH agent.

Testing It

You can verify everything’s working:

# Should show Windows SSH version
ssh -V

# Should return "ssh.exe"
git config --get core.sshCommand

# The real test - should work without prompting for passwords
git -T [email protected]

If you want something more permanent than aliases, you can create a symlink:

mkdir -p ~/bin
ln -s $(which ssh.exe) ~/bin/ssh
export PATH="$HOME/bin:$PATH"  # Add this to your shell profile

But honestly? The alias + Git config approach is simpler and works just as well for me, so far…

Leave a comment

Your email address will not be published. Required fields are marked *

Loading...