Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,52 @@ 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
```

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

### 2. Modify `.bashrc` (or `.zshrc` if you are using `zsh`)
### 2. Modify your shell's rc file

Bash or Zsh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Bash or Zsh
#### Bash or Zsh

Add the following line to `.bashrc` (or `.zshrc` if you are using `zsh`).

```
eval $($HOME/wsl2-ssh-agent)
```

Fish
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fish
#### Fish

Add the following lines to config.fish

```
if status is-login
$HOME/wsl2-ssh-agent | source
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be $HOME/wsl2-ssh-agent --shell fish | source ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good catch. Will fix.

end
```

Close and reopen the terminal and execute `ssh your-machine`.
The command should communicate with ssh-agent.exe service.

## Troubleshooting

### Make sure that ssh-agent.exe is working properly

* Open the "Services" app and check that "OpenSSH Authentication Agent" service is installed and running.
* Check that `ssh your-machine` works perfect on cmd.exe or PowerShell, not on WSL2.
- Open the "Services" app and check that "OpenSSH Authentication Agent" service is installed and running.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no particular reason, please do not change these.

Copy link
Contributor Author

@chksome chksome Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, yeah, I'll fix.
EDIT: So it seems Prettier is a fan of using - for unordered lists instead of *, hence how this change sneaked in on me. I'll change it back if you want, or keep it to be "more standards compliant". I don't really care either way, but if it stays this way you'll be good to go if you decide to start using it for formatting.

- Check that `ssh your-machine` works perfect on cmd.exe or PowerShell, not on WSL2.

### Check the log of ssh

* You may want to run `ssh -v your-machine` and read the log. If everything is good, you should see the following log.
- You may want to run `ssh -v your-machine` and read the log. If everything is good, you should see the following log.

```
debug1: get_agent_identities: bound agent to hostkey
Expand All @@ -51,7 +65,7 @@ debug1: get_agent_identities: agent returned XXX keys

### Check the log of wsl2-ssh-agent

* Run `wsl2-ssh-agent` in verbose and foreground mode and read the log. This is an example output.
- Run `wsl2-ssh-agent` in verbose and foreground mode and read the log. This is an example output.

```
# Stop the existing server if any
Expand Down Expand Up @@ -99,9 +113,9 @@ subgraph Windows
end
```

* wsl2-ssh-agent listens on a UNIX domain socket (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
* wsl2-ssh-agent invokes PowerShell.exe as a child process, which can communicate with ssh-agent.exe service via a named pipe.
* wsl2-ssh-agent and PowerShell.exe communicates via stdin/stdout thanks to WSL2 interop.
- wsl2-ssh-agent listens on a UNIX domain socket (by default, $HOME/.ssh/wsl2-ssh-agent.sock).
- wsl2-ssh-agent invokes PowerShell.exe as a child process, which can communicate with ssh-agent.exe service via a named pipe.
- wsl2-ssh-agent and PowerShell.exe communicates via stdin/stdout thanks to WSL2 interop.

## Note

Expand Down
25 changes: 18 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (
)

type config struct {
socketPath string
foreground bool
verbose bool
stop bool
logFile string
version bool
socketPath string
foreground bool
verbose bool
stop bool
logFile string
version bool
shellOutput string
}

var version = "(development version)"
Expand All @@ -44,6 +45,7 @@ func newConfig() *config {
flag.StringVar(&c.logFile, "log", "", "a file path to write the log")
flag.BoolVar(&c.stop, "stop", false, "stop the daemon and exit")
flag.BoolVar(&c.version, "version", false, "print version and exit")
flag.StringVar(&c.shellOutput, "shell", "bash", "socket output format. bash, zsh, or fish")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "usage: wsl2-ssh-agent\n")
Expand All @@ -65,7 +67,15 @@ func (c *config) start() (context.Context, bool) {
parent := checkDaemonMode()

// script output
output := fmt.Sprintf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;", c.socketPath)
output := ""
switch c.shellOutput {
case "bash", "zsh":
output = fmt.Sprintf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;", c.socketPath)
case "fish":
output = fmt.Sprintf("set -Ux SSH_AUTH_SOCK %s", c.socketPath)
default:
output = fmt.Sprintf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;", c.socketPath)
}

// set up the log file
c.setupLogFile()
Expand Down Expand Up @@ -99,6 +109,7 @@ func (c *config) start() (context.Context, bool) {
if c.logFile != "" {
args = append(args, "-log", c.logFile)
}
args = append(args, "-shell", c.shellOutput)
startDaemonizing(args...)
} else {
completeDaemonizing(output)
Expand Down