You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**If you are using ArchLinux, you can install the [wsl2-ssh-agent](https://aur.archlinux.org/packages/wsl2-ssh-agent) package from the AUR (maintained by @Hill-98).**
25
+
Note for Arch Linux users: You can install the [wsl2-ssh-agent](https://aur.archlinux.org/packages/wsl2-ssh-agent) package from the AUR (maintained by @Hill-98).
28
26
29
27
### 2. Modify your shell's rc file
30
28
@@ -70,74 +68,85 @@ Make the directory if necessary.
70
68
71
69
### 4. Reopen your terminal
72
70
73
-
Close and reopen the terminal and execute `ssh your-machine`.
74
-
The command should communicate with ssh-agent.exe service.
71
+
Close and reopen the terminal.
72
+
You should now be able to run `ssh your-server` and connect using the SSH keys managed by the Windows ssh-agent.exe service.
75
73
76
-
## Tip: For pageant.exe
74
+
## Tip: Using with pageant.exe
77
75
78
-
If you want to use with the named pipe provided by pageant.exe, you can use the `-pipename` option.
79
-
You can configure wsl2-ssh-agent as follows:
76
+
If you want to use the named pipe provided by pageant.exe, you can use the `-pipename` option.
[L] 2023/02/10 20:30:05 ssh <- [L] (5 B) <dummy for OpenSSH ext.>
123
-
[L] 2023/02/10 20:30:05 ssh -> [L] (5 B)
124
-
[L] 2023/02/10 20:30:05 [L] -> [W] (5 B)
125
-
[W] 2023/02/10 21:51:12 [L] -> [W] -> ssh-agent.exe (5 B)
126
-
[W] 2023/02/10 21:51:12 [L] <- [W] <- ssh-agent.exe (XXX B)
127
-
[L] 2023/02/10 20:30:05 [L] <- [W] (XXX B)
128
-
[L] 2023/02/10 20:30:05 ssh <- [L] (XXX B)
129
-
[L] 2023/02/10 20:30:05 ssh -> [L] (XXX B)
130
-
[L] 2023/02/10 20:30:05 [L] -> [W] (XXX B)
131
-
[W] 2023/02/10 21:51:12 [L] -> [W] -> ssh-agent.exe (XXX B)
132
-
[W] 2023/02/10 21:51:12 [L] <- [W] <- ssh-agent.exe (XXX B)
133
-
[L] 2023/02/10 20:30:05 [L] <- [W] (XXX B)
134
-
[L] 2023/02/10 20:30:05 ssh <- [L] (XXX B)
135
-
[L] 2023/02/10 20:30:05 ssh: closed
136
-
```
137
-
138
-
## How wsl2-ssh-agent works
139
-
140
-
Linux ssh client connects to ssh-agent via a UNIX domain socket, while ssh-agent.exe service on Windows is listening on a named pipe. This command connects those two in the following mechanism.
111
+
[L] 2025/07/29 19:51:27 start listening on /path/to/wsl2-ssh-agent.sock
112
+
[L] 2025/07/29 19:51:27 invoking [W] in PowerShell.exe
[W] 2025/07/29 19:51:28 [W] named pipe: openssh-ssh-agent
117
+
[L] 2025/07/29 19:51:33 ssh: connected
118
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
119
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
120
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
121
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
122
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
123
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
124
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
125
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
126
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
127
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
128
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
129
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
130
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
131
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
132
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
133
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
134
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
135
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
136
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
137
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
138
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
139
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
140
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
141
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
142
+
[L] 2025/07/29 19:51:33 ssh: closed
143
+
[L] 2025/07/29 19:51:33 ssh: connected
144
+
[L] 2025/07/29 19:51:33 ssh: closed
145
+
```
146
+
147
+
## How It Works
148
+
149
+
The SSH client in Linux communicates with an agent via a UNIX domain socket, while the ssh-agent.exe service on Windows listens on a named pipe. This tool connects the two using the following mechanism:
141
150
142
151
```mermaid
143
152
graph TB
@@ -150,14 +159,14 @@ subgraph Windows
150
159
end
151
160
```
152
161
153
-
* wsl2-ssh-agent listens on a UNIX domain socket (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
154
-
*wsl2-ssh-agent invokes PowerShell.exe as a child process, which can communicate with ssh-agent.exe service via a named pipe.
155
-
* wsl2-ssh-agent and PowerShell.exe communicates via stdin/stdout thanks to WSL2 interop.
162
+
* wsl2-ssh-agent starts a server that listens on a UNIX domain socket in WSL2 (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
163
+
*It then invokes a PowerShell.exe child process on the Windows host.
164
+
*The wsl2-ssh-agent process in WSL2 and the PowerShell process in Windows communicate via their stdin/stdout streams. These streams are connected by the WSL interop layer. The PowerShell process then forwards communication to the Windows ssh-agent.exe service via its named pipe.
156
165
157
-
## Note
166
+
## Note on Windows OpenSSH Compatibility
158
167
159
-
Usually, ssh and ssh-agent should be the same version. However, OpenSSH on Ubuntu 22.04 is 8.9, while Windows bundles OpenSSH 8.6 (on my machine, as of this writing).
168
+
My motivation for creating wsl2-ssh-agent was to work around a compatibility issue in OpenSSH. [The newer SSH client (version 8.9+) sends an extended protocol message](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.agent) that the older Windows agent (before 8.9) doesn't understand, which can cause the connection to fail. ([Japanese article](https://zenn.dev/qnighy/articles/8b992970b86653))
160
169
161
-
[OpenSSH has extended the ssh-agent protocol since 8.9](https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.agent). However, ssh-agent.exe does not understand the extended message and will not communicate properly. ([Japanese article](https://zenn.dev/qnighy/articles/8b992970b86653))
170
+
To fix this, wsl2-ssh-agent checks your Windows OpenSSH version. When it detects an older version (before 8.9), it intercepts these unsupported messages and sends a valid, compatible response back to the client. This prevents the old agent from failing and allows the connection to work.
162
171
163
-
To address this issue, wsl2-ssh-agent does not pass the extended message to ssh-agent.exe. Instead, it swallows the message and reply a dummy SSH_AGENT_SUCCESS message to ssh client. Note that this may reduce the security strength. Please use this tool at your own risk.
172
+
Modern Windows now includes an updated OpenSSH (9.5 or newer), so this problem no longer exists on up-to-date systems. The fix is automatically applied only when necessary, so you can use this tool on any system without changing your settings.
0 commit comments