Skip to content

Commit 415543c

Browse files
authored
Merge pull request #20 from AtifChy/systemd
feat: add systemd user service file
2 parents 607f772 + c50be86 commit 415543c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ Put `wsl2-ssh-agent` binary in your favorite directory in WSL2, for example, `$H
1111
```
1212
curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent
1313
```
14+
1415
If you are under ARM64 architecture, download the `arm64` binary instead:
16+
1517
```
1618
curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent-arm64
1719
```
20+
1821
Change permisions so the binary is executable:
22+
1923
```
2024
chmod 755 wsl2-ssh-agent
2125
```
@@ -42,7 +46,29 @@ if status is-login
4246
end
4347
```
4448

45-
### 3. Reopen your terminal
49+
### 3. Systemd service (optional)
50+
51+
We also provide a [systemd service](extras/systemd/user/wsl2-ssh-agent.service). You can use it to automatically start `wsl2-ssh-agent` when you log in to WSL2. But if you are already using your shell's rc file to start `wsl2-ssh-agent`, you can safely skip this step.
52+
53+
* Copy the provided [`wsl2-ssh-agent.service`](extras/systemd/user/wsl2-ssh-agent.service) file to `~/.config/systemd/user/`.
54+
Make the directory if necessary.
55+
56+
* Enable and start the service:
57+
58+
```sh
59+
systemctl --user enable --now wsl2-ssh-agent.service
60+
```
61+
62+
**Note:** By default the service searches for `wsl2-ssh-agent` executable in `/usr/bin`;
63+
If you have it placed in a different location, you just need to modify the `ExecStart` line in the service file accordingly.
64+
65+
* Add the following to your shell's rc file (e.g., `.bashrc`, `.zshrc`):
66+
67+
```sh
68+
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/wsl2-ssh-agent.sock
69+
```
70+
71+
### 4. Reopen your terminal
4672

4773
Close and reopen the terminal and execute `ssh your-machine`.
4874
The command should communicate with ssh-agent.exe service.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=WSL2 SSH Agent Bridge
3+
After=network.target
4+
ConditionUser=!root
5+
6+
[Service]
7+
ExecStart=/usr/bin/wsl2-ssh-agent --verbose --foreground --socket=%t/wsl2-ssh-agent.sock
8+
Restart=on-failure
9+
10+
[Install]
11+
WantedBy=default.target

0 commit comments

Comments
 (0)