Skip to content

Commit e7dcc6a

Browse files
authored
Update README.md (#21)
Update README.md
1 parent 415543c commit e7dcc6a

File tree

1 file changed

+63
-54
lines changed

1 file changed

+63
-54
lines changed

README.md

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ This tool allows from WSL2 to use the ssh-agent service on Windows host.
99
Put `wsl2-ssh-agent` binary in your favorite directory in WSL2, for example, `$HOME/`.
1010

1111
```
12+
# For x86-64 architecture
1213
curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent
13-
```
14-
15-
If you are under ARM64 architecture, download the `arm64` binary instead:
1614
17-
```
15+
# For ARM64 architecture
1816
curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent-arm64
1917
```
2018

21-
Change permisions so the binary is executable:
19+
Then, make the binary executable:
2220

2321
```
2422
chmod 755 wsl2-ssh-agent
2523
```
2624

27-
**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).
2826

2927
### 2. Modify your shell's rc file
3028

@@ -70,74 +68,85 @@ Make the directory if necessary.
7068

7169
### 4. Reopen your terminal
7270

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.
7573

76-
## Tip: For pageant.exe
74+
## Tip: Using with pageant.exe
7775

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.
77+
For example:
8078

8179
```
8280
eval $($HOME/wsl2-ssh-agent -pipename $(grep -oP "IdentityAgent \"//\./pipe/\K[^\"]+" /mnt/c/.../pageant.conf))
8381
```
8482

85-
(The author does not use pageant.exe. Let me know if it does not work.)
83+
(Note: The author does not use pageant.exe. If this doesn't work, please open an issue.)
8684

8785
## Troubleshooting
8886

89-
### Make sure that ssh-agent.exe is working properly
87+
### Confirm ssh-agent.exe is working
9088

91-
* Open the "Services" app and check that "OpenSSH Authentication Agent" service is installed and running.
92-
* Check that `ssh your-machine` works perfect on cmd.exe or PowerShell, not on WSL2.
89+
* Open the "Services" app on Windows and confirm the "OpenSSH Authentication Agent" service is installed and running.
90+
* Check that `ssh your-server` works perfectly from cmd.exe or PowerShell (i.e., outside of WSL2).
9391

94-
### Check the log of ssh
92+
### Check the ssh client log
9593

96-
* You may want to run `ssh -v your-machine` and read the log. If everything is good, you should see the following log.
94+
* You may want to run `ssh -v your-server` and read the log. If everything is working correctly, you should see lines similar to these.
9795

9896
```
9997
debug1: get_agent_identities: bound agent to hostkey
10098
debug1: get_agent_identities: agent returned XXX keys
10199
```
102100

103-
### Check the log of wsl2-ssh-agent
101+
### Check the wsl2-ssh-agent log
104102

105-
* Run `wsl2-ssh-agent` in verbose and foreground mode and read the log. This is an example output.
103+
To see detailed logs, stop the agent and restart it in verbose foreground mode.
106104

107105
```
108106
# Stop the existing server if any
109107
$ $HOME/wsl2-ssh-agent -stop
110108
111109
# Run in foreground mode
112110
$ $HOME/wsl2-ssh-agent --verbose --foreground
113-
[L] 2023/02/10 20:30:00 check the version of ssh.exe
114-
[L] 2023/02/10 20:30:01 the version of ssh.exe: "OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3"
115-
[L] 2023/02/10 20:30:01 ssh-agent.exe seems to be old; ignore OpenSSH extension messages
116-
[L] 2023/02/10 20:30:01 start listening on /home/mame/.ssh/wsl2-ssh-agent.sock
117-
[L] 2023/02/10 20:30:01 invoking [W] in PowerShell.exe
118-
[W] 2023/02/10 21:51:09 ready: PSVersion 5.1.22621.963
119-
[L] 2023/02/10 20:30:02 [W] invoked successfully
120-
[L] 2023/02/10 20:30:05 ssh: connected
121-
[L] 2023/02/10 20:30:05 ssh -> [L] (XXX B)
122-
[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
113+
[W] 2025/07/29 19:51:28 ssh-agent.exe version: 9.5.4.1 (ignoreOpenSSHExtensions: False)
114+
[L] 2025/07/29 19:51:28 [W] invoked successfully
115+
[W] 2025/07/29 19:51:28 ready: PSVersion 5.1.22621.5624
116+
[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:
141150

142151
```mermaid
143152
graph TB
@@ -150,14 +159,14 @@ subgraph Windows
150159
end
151160
```
152161

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.
156165

157-
## Note
166+
## Note on Windows OpenSSH Compatibility
158167

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))
160169

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.
162171

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

Comments
 (0)