This project provides a setup for enabling SSH agent forwarding for the Windows terminal SSH and also from Windows to WSL (Windows Subsystem for Linux) using Pageant and npiperelay.
It allows SSH keys loaded in Pageant on Windows to be accessible within WSL, making SSH authentication seamless for both the Windows terminal native SSH command and the SSH command within your WSL instances.
- Automatically starts Pageant only login with OpenSSH agent support on Windows.
- Configures WSL to forward the SSH agent from Windows.
- Uses npiperelay to bridge the Windows named pipe to a Unix socket in WSL.
- Supports different Linux distributions (Debian, RedHat, Alpine, Arch, etc.).
- Automates setup via systemd services in the WSL instance.
- Windows with PuTTY's Pageant installed (
C:\Program Files\PuTTY\pageant.exe
). - A private key in PuTTY's
.ppk
format. - WSL (Windows Subsystem for Linux) installed.
socat
,curl
, andunzip
installed in your WSL instance.
- Copy
start_pageant_with_socket.bat
to the%USERPROFILE%\.ssh
folder on your Windows system. - Edit the batch file to specify your private key path or paths (replace
%USERPROFILE%\.ssh\your.privkey.ppk
with your own key path/s). - Run
start_pageant_with_socket.bat
. - It will:
- Start Pageant and load your private key or keys.
- Create an SSH configuration file and set your SSH config to include the
pageant.conf
which specifies the named pipe required. - Set itself to automatically start up when you log in.
- Display the named pipe path from the
pageant.conf
file created by Pageant.
- Copy
setup_ssh_agent_forwarding_from_windows_to_wsl.sh
to your WSL home directory. - Run the script:
The script will:
chmod +x setup_ssh_agent_forwarding_from_windows_to_wsl.sh ./setup_ssh_agent_forwarding_from_windows_to_wsl.sh
- Install required dependencies if they are missing (
socat
,unzip
,curl
). - Download and extract
npiperelay.exe
to%USERPROFILE%\.ssh
. - Set up a systemd service to bridge the Windows/Pageant SSH agent to WSL.
- Configure your shell to use the SSH agent socket.
- Install required dependencies if they are missing (
- Restart your shell or run:
source ~/.bashrc
Once set up, SSH commands in WSL will automatically use the forwarded SSH agent from Windows. You can test it with:
ssh -T [email protected]
If everything is configured and running correctly, you should see:
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
Or if you don't have a Github account you can test it with:
ssh-add -L
If everything is configured and running correctly, you should see your key or keys printed to the screen.
echo $SSH_AUTH_SOCK
ls -l /tmp/ssh-agent.sock
systemctl --user restart ssh-agent-pageant.service
journalctl --user -u ssh-agent-pageant.service
If SSH authentication fails, please make sure Pageant is still running in Windows and contains your keys.
You can also try restarting the WSL Systemd service as above.
This project is licensed under the MIT License.