Skip to content

Commit ef86d8e

Browse files
committed
Merge branch 'master' of github.com:rupor-github/wsl-ssh-agent
2 parents 766878e + d57f220 commit ef86d8e

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
@@ -52,7 +52,8 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
5252
## Usage
5353

5454
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):
55-
```
55+
56+
```powershell
5657
Start-Service ssh-agent
5758
Set-Service -StartupType Automatic ssh-agent
5859
```
@@ -62,12 +63,12 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
6263
* Using `-socket` option specify "well known" path on Windows side and then properly specify the same path in every WSL session:
6364

6465
Windows:
65-
```
66+
```cmd
6667
wsl-ssh-agent-gui.exe -socket c:\wsl-ssh-agent\ssh-agent.sock
6768
```
6869

6970
WSL:
70-
```
71+
```bash
7172
export SSH_AUTH_SOCK=/mnt/c/wsl-ssh-agent/ssh-agent.sock
7273
```
7374

@@ -85,12 +86,14 @@ Starting with v1.5.1 releases are packed with zip and signed with [minisign](htt
8586
```
8687

8788
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:
88-
```
89+
90+
```bash
8991
export SSH_AUTH_SOCK=${<<YOUR-NAME-HERE>>}
9092
```
9193

9294
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:
93-
```
95+
96+
```terminal
9497
Socket path:
9598
C:\Users\rupor\AppData\Local\Temp\ssh-273683143.sock
9699
Pipe name:
@@ -105,7 +108,7 @@ For security reasons unless `-nolock` argument is specified program will refuse
105108

106109
Run `wsl-ssh-agent-gui.exe -help`
107110

108-
```
111+
```terminal
109112
---------------------------
110113
wsl-ssh-agent-gui
111114
---------------------------
@@ -144,15 +147,16 @@ Options:
144147

145148
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:
146149

147-
```
150+
```bash
148151
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
149152
ss -a | grep -q $SSH_AUTH_SOCK
150153
if [ $? -ne 0 ]; then
151154
rm -f $SSH_AUTH_SOCK
152155
( 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
153156
fi
154157
```
155-
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.
158+
159+
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`.
156160

157161
## Example
158162

@@ -161,26 +165,35 @@ Putting it all together nicely - `remote` here refers to your wsl shell or some
161165
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).
162166

163167
I auto-start `wsl-ssh-agent-gui.exe` on logon on my Windows box using following command line:
164-
```
168+
169+
```terminal
165170
wsl-ssh-agent-gui.exe -setenv -envname=WSL_AUTH_SOCK
166171
```
172+
167173
In my .bashrc I have:
168-
```
174+
175+
```bash
169176
[ -n ${WSL_AUTH_SOCK} ] && export SSH_AUTH_SOCK=${WSL_AUTH_SOCK}
170177
```
178+
171179
and my `.ssh/config` entries used to `ssh` to `remote` have port forwarding enabled:
180+
172181
```
173182
RemoteForward 2850 127.0.0.1:2850
174183
```
184+
175185
On `remote` my `tmux.conf` includes following lines:
176-
```
186+
187+
```tmux
177188
set -g set-clipboard off
178189
if-shell 'if [ -n ${WSL_DISTRO_NAME} ]; then true; else false; fi' \
179190
'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"' \
180191
'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"'
181192
```
193+
182194
And my `neovim` configuration file `init.vim` on `remote` has following lines:
183-
```
195+
196+
```vim
184197
set clipboard+=unnamedplus
185198
if has("unix")
186199
" ----- on UNIX ask lemonade to translate line-endings

0 commit comments

Comments
 (0)