From 96086bf7840e4ea5148ee2520d47a504b2cc9d56 Mon Sep 17 00:00:00 2001 From: Atif Chowdhury Date: Sun, 25 May 2025 16:41:59 +0600 Subject: [PATCH 1/2] feat: add systemd user service --- extras/systemd/user/wsl2-ssh-agent.service | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 extras/systemd/user/wsl2-ssh-agent.service diff --git a/extras/systemd/user/wsl2-ssh-agent.service b/extras/systemd/user/wsl2-ssh-agent.service new file mode 100644 index 0000000..e85c7d5 --- /dev/null +++ b/extras/systemd/user/wsl2-ssh-agent.service @@ -0,0 +1,11 @@ +[Unit] +Description=WSL2 SSH Agent Bridge +After=network.target +ConditionUser=!root + +[Service] +ExecStart=/usr/bin/wsl2-ssh-agent --verbose --foreground --socket=%t/wsl2-ssh-agent.sock +Restart=on-failure + +[Install] +WantedBy=default.target From c50be86bf22f07df8a94734547eb988372200f42 Mon Sep 17 00:00:00 2001 From: Atif Chowdhury Date: Mon, 26 May 2025 03:21:34 +0600 Subject: [PATCH 2/2] update readme for systemd service --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b9f747..8e7d24f 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,15 @@ Put `wsl2-ssh-agent` binary in your favorite directory in WSL2, for example, `$H ``` curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent ``` + If you are under ARM64 architecture, download the `arm64` binary instead: + ``` curl -L -O https://github.com/mame/wsl2-ssh-agent/releases/latest/download/wsl2-ssh-agent-arm64 ``` + Change permisions so the binary is executable: + ``` chmod 755 wsl2-ssh-agent ``` @@ -42,7 +46,29 @@ if status is-login end ``` -### 3. Reopen your terminal +### 3. Systemd service (optional) + +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. + +* Copy the provided [`wsl2-ssh-agent.service`](extras/systemd/user/wsl2-ssh-agent.service) file to `~/.config/systemd/user/`. +Make the directory if necessary. + +* Enable and start the service: + + ```sh + systemctl --user enable --now wsl2-ssh-agent.service + ``` + + **Note:** By default the service searches for `wsl2-ssh-agent` executable in `/usr/bin`; + If you have it placed in a different location, you just need to modify the `ExecStart` line in the service file accordingly. + +* Add the following to your shell's rc file (e.g., `.bashrc`, `.zshrc`): + + ```sh + export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/wsl2-ssh-agent.sock + ``` + +### 4. Reopen your terminal Close and reopen the terminal and execute `ssh your-machine`. The command should communicate with ssh-agent.exe service.