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).
24
26
25
27
### 2. Modify your shell's rc file
26
28
@@ -44,74 +46,85 @@ end
44
46
45
47
### 3. Reopen your terminal
46
48
47
-
Close and reopen the terminal and execute `ssh your-machine`.
48
-
The command should communicate with ssh-agent.exe service.
49
+
Close and reopen the terminal.
50
+
You should now be able to run `ssh your-server` and connect using the keys managed by the Windows ssh-agent.exe service.
49
51
50
-
## Tip: For pageant.exe
52
+
## Tip: Using with pageant.exe
51
53
52
-
If you want to use with the named pipe provided by pageant.exe, you can use the `-pipename` option.
53
-
You can configure wsl2-ssh-agent as follows:
54
+
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.>
97
-
[L] 2023/02/10 20:30:05 ssh -> [L] (5 B)
98
-
[L] 2023/02/10 20:30:05 [L] -> [W] (5 B)
99
-
[W] 2023/02/10 21:51:12 [L] -> [W] -> ssh-agent.exe (5 B)
100
-
[W] 2023/02/10 21:51:12 [L] <- [W] <- ssh-agent.exe (XXX B)
101
-
[L] 2023/02/10 20:30:05 [L] <- [W] (XXX B)
102
-
[L] 2023/02/10 20:30:05 ssh <- [L] (XXX B)
103
-
[L] 2023/02/10 20:30:05 ssh -> [L] (XXX B)
104
-
[L] 2023/02/10 20:30:05 [L] -> [W] (XXX B)
105
-
[W] 2023/02/10 21:51:12 [L] -> [W] -> ssh-agent.exe (XXX B)
106
-
[W] 2023/02/10 21:51:12 [L] <- [W] <- ssh-agent.exe (XXX B)
107
-
[L] 2023/02/10 20:30:05 [L] <- [W] (XXX B)
108
-
[L] 2023/02/10 20:30:05 ssh <- [L] (XXX B)
109
-
[L] 2023/02/10 20:30:05 ssh: closed
110
-
```
111
-
112
-
## How wsl2-ssh-agent works
113
-
114
-
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.
89
+
[L] 2025/07/29 19:51:27 start listening on /path/to/wsl2-ssh-agent.sock
90
+
[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
95
+
[L] 2025/07/29 19:51:33 ssh: connected
96
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
97
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
98
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
99
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
100
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
101
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
102
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
103
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
104
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
105
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
106
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
107
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
108
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
109
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
110
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
111
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
112
+
[L] 2025/07/29 19:51:33 ssh -> [L] (XXX B)
113
+
[L] 2025/07/29 19:51:33 [L] -> [W] (XXX B)
114
+
[W] 2025/07/29 19:51:33 [W] named pipe: connected
115
+
[W] 2025/07/29 19:51:33 [L] -> [W] -> ssh-agent.exe (XXX B)
116
+
[L] 2025/07/29 19:51:33 [L] <- [W] (XXX B)
117
+
[L] 2025/07/29 19:51:33 ssh <- [L] (XXX B)
118
+
[W] 2025/07/29 19:51:33 [L] <- [W] <- ssh-agent.exe (XXX B)
119
+
[W] 2025/07/29 19:51:33 [W] named pipe: disconnected
120
+
[L] 2025/07/29 19:51:33 ssh: closed
121
+
[L] 2025/07/29 19:51:33 ssh: connected
122
+
[L] 2025/07/29 19:51:33 ssh: closed
123
+
```
124
+
125
+
## How It Works
126
+
127
+
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:
115
128
116
129
```mermaid
117
130
graph TB
@@ -124,14 +137,14 @@ subgraph Windows
124
137
end
125
138
```
126
139
127
-
* wsl2-ssh-agent listens on a UNIX domain socket (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
128
-
*wsl2-ssh-agent invokes PowerShell.exe as a child process, which can communicate with ssh-agent.exe service via a named pipe.
129
-
* wsl2-ssh-agent and PowerShell.exe communicates via stdin/stdout thanks to WSL2 interop.
140
+
* wsl2-ssh-agent starts a server that listens on a UNIX domain socket in WSL2 (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
141
+
*It then invokes a PowerShell.exe child process on the Windows host.
142
+
*The wsl2-ssh-agent process in WSL2 and the PowerShell process in Windows communicate via their stdin/stdout streams, which are connected by the WSL interop layer. The PowerShell process then forwards communication to the Windows ssh-agent.exe service via its named pipe.
130
143
131
-
## Note
144
+
## Note on Windows OpenSSH Compatibility
132
145
133
-
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).
146
+
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))
134
147
135
-
[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))
148
+
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.
136
149
137
-
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.
150
+
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