Skip to content

Commit d57f220

Browse files
authored
Merge pull request #25 from koppor/patch-1
Add hint on socat - and add some markdown highlighting
2 parents 34a7b3f + 584de56 commit d57f220

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
4040
## Usage
4141

4242
1. Ensure that on Windows side `ssh-agent.exe` service (OpenSSH Authentication Agent) is started and has your keys. (After adding keys to Windows `ssh-agent.exe` you may remove them from your wsl home .ssh directory - just do not forget to adjust `IdentitiesOnly` directive in your ssh config accordingly. Keys are securely persisted in Windows registry, available for your account only). You may also want to switch its startup mode to "automatic". Using powershell with elevated privileges (admin mode):
43-
```
43+
44+
```powershell
4445
Start-Service ssh-agent
4546
Set-Service -StartupType Automatic ssh-agent
4647
```
@@ -50,12 +51,12 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
5051
* Using `-socket` option specify "well known" path on Windows side and then properly specify the same path in every WSL session:
5152

5253
Windows:
53-
```
54+
```cmd
5455
wsl-ssh-agent-gui.exe -socket c:\wsl-ssh-agent\ssh-agent.sock
5556
```
5657

5758
WSL:
58-
```
59+
```bash
5960
export SSH_AUTH_SOCK=/mnt/c/wsl-ssh-agent/ssh-agent.sock
6061
```
6162

@@ -73,12 +74,14 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
7374
```
7475

7576
To avoid this and still be able to use `-setenv` and automatically generated socket path use `-envname` to specify variable name to set. Later on WSL side you could use:
76-
```
77+
78+
```bash
7779
export SSH_AUTH_SOCK=${<<YOUR-NAME-HERE>>}
7880
```
7981

8082
When `wsl-ssh-agent-gui.exe` is running you could see what it is connected to by clicking on its icon in notification tray area and selecting `About`. At the bottom of the message you would see something like:
81-
```
83+
84+
```terminal
8285
Socket path:
8386
C:\Users\rupor\AppData\Local\Temp\ssh-273683143.sock
8487
Pipe name:
@@ -93,7 +96,7 @@ For security reasons unless `-nolock` argument is specified program will refuse
9396

9497
Run `wsl-ssh-agent-gui.exe -help`
9598

96-
```
99+
```terminal
97100
---------------------------
98101
wsl-ssh-agent-gui
99102
---------------------------
@@ -132,15 +135,16 @@ Options:
132135

133136
At the moment AF_UNIX interop does not seems to be working with WSL2 VMs. Hopefully this will be sorted out eventually. Meantime there is an easy workaround (proposed by multiple people) which does not use wsl-ssh-agent.exe at all and relies on combination of linux socat tool from your distribution and [npiperelay.exe](https://github.com/jstarks/npiperelay). Put npiperelay.exe somewhere on devfs for interop to work its magic (I have `winhome ⇒ /mnt/c/Users/rupor` in my $HOME directory for that) and add following lines in your .bashrc/.zshrc:
134137

135-
```
138+
```bash
136139
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
137140
ss -a | grep -q $SSH_AUTH_SOCK
138141
if [ $? -ne 0 ]; then
139142
rm -f $SSH_AUTH_SOCK
140143
( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$HOME/winhome/.wsl/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
141144
fi
142145
```
143-
You *really* have to be on WSL 2 in order for this to work - if you see errors like `Cannot open netlink socket: Protocol not supported` - you probably are under WSL 1 and should not use this workaround. Run `wsl.exe -l --all -v` to check what is going on. When on WSL 2 make sure that socat is installed and npiperelay.exe is on windows partition and path is right. For convinience I will be packing pre-build npiperelay.exe with wsl-ssh-agent.
146+
147+
You *really* have to be on WSL 2 in order for this to work - if you see errors like `Cannot open netlink socket: Protocol not supported` - you probably are under WSL 1 and should not use this workaround. Run `wsl.exe -l --all -v` to check what is going on. When on WSL 2 make sure that socat is installed and npiperelay.exe is on windows partition and path is right. For convinience I will be packing pre-build npiperelay.exe with wsl-ssh-agent. Please also ensure that `socat` is installed: `sudo apt install socat`.
144148

145149
## Example
146150

@@ -149,26 +153,35 @@ Putting it all together nicely - `remote` here refers to your wsl shell or some
149153
For my WSL installations I always create `~/winhome` and link it to my Windows home directory (where I have `.wsl` directory with various interoperability tools from Windows side). I am assuming that [gclpr](https://github.com/rupor-github/gclpr) is in your path on `remote` and you installed it's Windows counterpart somewhere in `drvfs` location (~/winhome/.wsl is a good place).
150154

151155
I auto-start `wsl-ssh-agent-gui.exe` on logon on my Windows box using following command line:
152-
```
156+
157+
```terminal
153158
wsl-ssh-agent-gui.exe -setenv -envname=WSL_AUTH_SOCK
154159
```
160+
155161
In my .bashrc I have:
156-
```
162+
163+
```bash
157164
[ -n ${WSL_AUTH_SOCK} ] && export SSH_AUTH_SOCK=${WSL_AUTH_SOCK}
158165
```
166+
159167
and my `.ssh/config` entries used to `ssh` to `remote` have port forwarding enabled:
168+
160169
```
161170
RemoteForward 2850 127.0.0.1:2850
162171
```
172+
163173
On `remote` my `tmux.conf` includes following lines:
164-
```
174+
175+
```tmux
165176
set -g set-clipboard off
166177
if-shell 'if [ -n ${WSL_DISTRO_NAME} ]; then true; else false; fi' \
167178
'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "~/winhome/.wsl/gclpr.exe copy" ; bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "~/winhome/.wsl/gclpr.exe copy"' \
168179
'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "gclpr copy" ; bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "gclpr copy"'
169180
```
181+
170182
And my `neovim` configuration file `init.vim` on `remote` has following lines:
171-
```
183+
184+
```vim
172185
set clipboard+=unnamedplus
173186
if has("unix")
174187
" ----- on UNIX ask lemonade to translate line-endings

0 commit comments

Comments
 (0)