Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate PowerShell Script for Stable and Fast Communication with Windows OpenSSH ssh-agent from WSL2 #54

Merged
merged 21 commits into from
Oct 5, 2024
46 changes: 39 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,65 @@ jobs:
run: |
wails build -nsis
go build -o build/bin/omni-socat.exe ./cmd/omni-socat
go build -o build/bin/agent-bench.exe ./cmd/agent-bench
powershell Compress-Archive -Path build/bin/omni-socat.exe -DestinationPath build/bin/omni-socat.zip
rm build/bin/omni-socat.exe
powershell Compress-Archive -Path build/bin/agent-bench.exe -DestinationPath build/bin/agent-bench.zip
rm build/bin/agent-bench.exe
powershell Compress-Archive -Path build/bin/OmniSSHAgent.exe -DestinationPath build/bin/OmniSSHAgent.zip
rm build/bin/OmniSSHAgent.exe

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: build-files
name: build-files-windows
path: |
${{ github.workspace }}\build\bin\*.exe
${{ github.workspace }}\build\bin\*.zip
- name: show info
run: |
echo "ls build/bin" >> $env:GITHUB_STEP_SUMMARY
ls "build/bin">> $env:GITHUB_STEP_SUMMARY
build-unix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: build
run: |
CGO_ENABLED=0 go build -o build/bin/wsl2-ssh-agent-proxy ./cmd/wsl2-ssh-agent-proxy
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/bin/agent-bench-linux-arm64 ./cmd/agent-bench
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/agent-bench-linux-amd64 ./cmd/agent-bench
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o build/bin/agent-bench-mac-arm64 ./cmd/agent-bench
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/bin/agent-bench-mac-amd64 ./cmd/agent-bench
gzip build/bin/wsl2-ssh-agent-proxy
gzip build/bin/agent-bench-linux-arm64
gzip build/bin/agent-bench-linux-amd64
gzip build/bin/agent-bench-mac-arm64
gzip build/bin/agent-bench-mac-amd64
- uses: actions/upload-artifact@v4
with:
name: build-files-linux
path: |
${{ github.workspace }}/build/bin/*.gz
- name: show info
run: |
echo "ls build/bin" >> $env:GITHUB_STEP_SUMMARY
ls "build/bin">> $env:GITHUB_STEP_SUMMARY
create-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
needs: [build-exe]
needs: [build-exe, build-unix]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v3
- uses: softprops/action-gh-release@v1
uses: actions/download-artifact@v4
- uses: softprops/action-gh-release@v2
with:
prerelease: true
fail_on_unmatched_files: true
generate_release_notes: true
files: |
./build-files/*
./build-files-*/*
137 changes: 60 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,147 +7,130 @@
Unifies the chaotic ssh-agent state under Windows.

### The Chaotic State of SSH-Agent on Windows
There are several different communication methods for ssh-agent in Windows, and it is very complicated to use and configure them.
The following diagram shows the current communication methods for Windows ssh-agent.
On Windows, there are multiple communication methods for SSH agents, leading to complexity in usage and configuration. The following diagram illustrates the current SSH agent communication landscape on Windows.
![windows-ssh-agent-chaosmap](https://github.com/masahide/OmniSSHAgent/blob/main/doc/windows-ssh-agent-chaosmap.png?raw=true)


### Connection diagram of OmniSSHAgent
OmniSSHAgent is a program to simplify what used to be a chaotic situation, as shown in the following figure.
### OmniSSHAgent Connection Diagram
OmniSSHAgent simplifies this chaotic situation, as shown in the diagram below.
![OmniSSHAgentmap](https://github.com/masahide/OmniSSHAgent/blob/main/doc/OmniSSHAgent.png?raw=true)

## Required environment for operation
## System Requirements

- Windows10
- Windows 11
- [Microsoft Edge WebView2](https://developer.microsoft.com/en-us/microsoft-edge/webview2/)

## The following interfaces are supported
- pageant.exe(PuTTY) shared memory
## Supported Interfaces
- Pageant.exe (PuTTY) shared memory
- Unix domain socket for WSL2
- NamedPipe on Windows
- Unix domain socket for WSL1
- Unix domain socket for MSYS2(Cygwin) ( [#1](https://github.com/masahide/OmniSSHAgent/issues/1) )
- Unix domain socket for MSYS2 (Cygwin) ([#1](https://github.com/masahide/OmniSSHAgent/issues/1))

## Usage

1. Download `OmniSSHAgent.zip` from https://github.com/masahide/OmniSSHAgent/releases/latest, unzip it, and place it in a folder of your choice.
2. If you are using Windows native ssh-agent, you'll need to stop and disable it. Open powershell with administrator privileges and execute the following commands.
```bash
1. Download `OmniSSHAgent-amd64-installer.exe` from [the latest release](https://github.com/masahide/OmniSSHAgent/releases/latest), and run the installer.
2. If you are using the native Windows SSH agent, you will need to stop and disable it. Open PowerShell with administrator privileges and run the following commands:
```powershell
Stop-Service ssh-agent
Set-Service -StartupType Disabled ssh-agent
```
- Alternatively, you can set it through the GUI if you prefer.Bring up the start menu and type Services. You’ll see the Services app listed.
Once the Services app is open, find the `OpenSSH Authentication Agent` service and set the `Service Status` to `Stop` and the `Startup Type` to `Disabled`.

3. If you are using [PuTTY Pageant](https://www.chiark.greenend.org.uk/~sgtatham/putty/index.html) - stop it.
- Alternatively, you can do this through the GUI: open the Start menu, type "Services," and select the Services app.
Once open, find the `OpenSSH Authentication Agent` service, set `Service Status` to `Stop`, and `Startup Type` to `Disabled`.

4. Launch `OmniSSHAgent.exe` by double-clicking.
5. Press the `Open new file` button to add a private key file. Or you can use `ssh-add` command or [KeePassXC](https://keepassxc.org/) to add your private key.
3. If you are using [PuTTY Pageant](https://www.chiark.greenend.org.uk/~sgtatham/putty/index.html), stop it.

### Registering for launch on boot
4. Launch `OmniSSHAgent.exe` by double-clicking it.
5. Press the `Open new file` button to add a private key file, or use the `ssh-add` command or [KeePassXC](https://keepassxc.org/) to add your private key.

OmniSSHAgent does not have an installer, nor registers itself to start upon boot. You'll need to do the following to register it:
### Registering for Startup

- Press the Windows logo key + R, type shell:startup, then click OK. This opens the Startup folder.
- Copy and paste the shortcut to the OmniSSHAgent.exe from the file location to the Startup
OmniSSHAgent does not have an installer to register itself for startup automatically. To add it manually:

- Press the Windows logo key + R, type `shell:startup`, and click OK. This opens the Startup folder.
- Copy and paste a shortcut to `OmniSSHAgent.exe` into the Startup folder.

### Using with WSL2
#### Setting up socat pipe in Ubuntu(WSL2).
Choose the instructions for your favourite shell below. If your shell isn't listed here you can convert the bash script to your shell syntax and send a PR to add it to the repo.
#### Setting up wsl2-ssh-agent-proxy in Ubuntu or Rocky (WSL2)
Choose the instructions for your preferred shell below. If your shell is not listed, you can convert the Bash script syntax and submit a pull request to add it to the repository.

##### Bash (and all POSIX-compliant shells)
1. Download [ubuntu.setup.sh](hack/ubuntu.setup.sh) with the following command:
1. Download [ubuntu.wsl2-ssh-agent-proxy.sh](hack/ubuntu.wsl2-ssh-agent-proxy.sh) using the following command:
```bash
mkdir -p $HOME/omni-socat
curl -sL https://raw.githubusercontent.com/masahide/OmniSSHAgent/main/hack/ubuntu.setup.sh -o $HOME/omni-socat/ubuntu.setup.sh
mkdir -p $HOME/wsl2-ssh-agent-proxy
curl -sL https://raw.githubusercontent.com/masahide/OmniSSHAgent/wsl2-ssh-agent-proxy/hack/ubuntu.wsl2-ssh-agent-proxy.sh -o $HOME/wsl2-ssh-agent-proxy/ubuntu.wsl2-ssh-agent-proxy.sh
```
2. Add the following line to `~/.bashrc`, `~/.zshrc`, or whatever file is applicable to your shell:
2. Add the following line to `~/.bashrc`, `~/.zshrc`, or the appropriate file for your shell:
```bash
source $HOME/omni-socat/ubuntu.setup.sh
source $HOME/wsl2-ssh-agent-proxy/ubuntu.wsl2-ssh-agent-proxy.sh
```

##### Fish
1. Download [ubuntu-fish.setup.fish](hack/ubuntu-fish.setup.fish) with the following command:
1. Download [ubuntu.wsl2-ssh-agent-proxy.fish](hack/ubuntu.wsl2-ssh-agent-proxy.fish) using the following command:
```fish
mkdir -p $HOME/omni-socat
curl -sL https://raw.githubusercontent.com/masahide/OmniSSHAgent/main/hack/ubuntu-fish.setup.fish -o $HOME/omni-socat/ubuntu-fish.setup.fish
mkdir -p $HOME/wsl2-ssh-agent-proxy
curl -sL https://raw.githubusercontent.com/masahide/OmniSSHAgent/wsl2-ssh-agent-proxy/hack/ubuntu.wsl2-ssh-agent-proxy.fish -o $HOME/wsl2-ssh-agent-proxy/ubuntu.wsl2-ssh-agent-proxy.fish
```
2. Add the following line to `~/.config/fish/config.fish`:
```fish
. $HOME/omni-socat/ubuntu-fish.setup.fish
```

#### Setting up socat pipe in rocky linux.

1. Download [rocky.setup.sh](hack/rocky.setup.sh) with the following command
```bash
mkdir -p $HOME/omni-socat
curl -sL https://raw.githubusercontent.com/masahide/OmniSSHAgent/main/hack/rocky.setup.sh -o $HOME/omni-socat/rocky.setup.sh
```
2. Add the following line to `~/.bashrc`, `~/.zshrc`, or whatever file is applicable to your shell:
```bash
source $HOME/omni-socat/rocky.setup.sh
. $HOME/wsl2-ssh-agent-proxy/ubuntu.wsl2-ssh-agent-proxy.fish
```

### Using with WSL1
Setting up Unix doman socket in ubuntu environment.
Setting up a Unix domain socket in the Ubuntu environment:


1. Check the setting of `Unix domain socket file path(WSL1):` in OmniSSHAgent.
For example, if you have the following settings.. (`UserName` varies depending on your environment)
1. Check the setting for `Unix domain socket file path (WSL1)` in OmniSSHAgent.
For example, if the path is set as follows (`UserName` will vary based on your environment):
`C:\Users\<UserName>\OmniSSHAgent.sock`
The WSL1 path will be `/mnt/c/Users/<UserName>/OmniSSHAgent.sock`.
The WSL1 path would be `/mnt/c/Users/<UserName>/OmniSSHAgent.sock`.

2. Add the following line to `~/.bashrc`
2. Add the following line to `~/.bashrc`:
```bash
export SSH_AUTH_SOCK=/mnt/c/Users/<UserName>/OmniSSHAgent.sock
```

### Using with Cygwin/MSYS2/Git for windows/(GitBash)
1. Check the setting of `Cygwin Unix domain socket file path(MSYS2):` in OmniSSHAgent.
* For example, if you have the following settings.(`UserName` varies depending on your environment).
* `C:\Users\<UserName>\OmniSSHCygwin.sock`.
* The Cygwin path will be `/mnt/c/Users/<UserName>/OmniSSHCygwin.sock`.
### Using with Cygwin/MSYS2/Git for Windows (Git Bash)
1. Check the setting for `Cygwin Unix domain socket file path (MSYS2)` in OmniSSHAgent.
* For example, if the path is (`UserName` will vary based on your environment):
* `C:\Users\<UserName>\OmniSSHCygwin.sock`
* The Cygwin path would be `/mnt/c/Users/<UserName>/OmniSSHCygwin.sock`.

2. On the Windows taskbar, right-click the Windows icon and select System.
In the Settings window, under Related Settings, click Advanced system settings.
2. To set the `SSH_AUTH_SOCK` variable:
* On the Windows taskbar, right-click the Windows icon and select System.
* In the Settings window, under Related Settings, click Advanced system settings.
* On the Advanced tab, click Environment Variables.
* `Users variables` Click on `Create new` to create a new environment variable.
* Set the following values(`UserName` varies depending on your environment).
* In `User variables`, click `New` to create a new environment variable:
```
Variable name: SSH_AUTH_SOCK
Variable Value: /mnt/c/Users/<UserName>/OmniSSHAgent.sock
Variable value: /mnt/c/Users/<UserName>/OmniSSHAgent.sock
```

## Using with 1Password proxy mode
## Using with OpenSSH ssh-agent NamedPipe (1Password, etc.) in Proxy Mode

This is a mode using [1Password's ssh-agent function](https://developer.1password.com/docs/ssh/) as a backend as shown in the following figure.
![1Password-Proxy-mode](https://github.com/masahide/OmniSSHAgent/blob/main/doc/1passwordProxyMode.png?raw=true)
This mode uses [OpenSSH ssh-agent NamedPipe](https://learn.microsoft.com/windows-server/administration/openssh/openssh_keymanagement) or [1Password's ssh-agent function](https://developer.1password.com/docs/ssh/agent/) as a backend, as shown in the diagram below.
![NamedPipe-Proxy-mode](https://github.com/masahide/OmniSSHAgent/blob/main/doc/NamedPipeProxyMode.png?raw=true)

By setting "Enable proxy mode for 1Password key-agent" in the configuration, OmniSSHAgent becomes a Proxy that works with 1Password's ssh-agent as a backend.
By enabling "Proxy mode for 1Password key-agent" in the configuration, OmniSSHAgent functions as a proxy for 1Password or OpenSSH's NamedPipe SSH agent.

When "Enable proxy mode for 1Password key-agent" is enabled, OmniSSHAgent operates as a mere proxy, and therefore, private keys cannot be added.
Note: When "Proxy mode for 1Password key-agent" is enabled, OmniSSHAgent operates solely as a proxy, meaning private keys cannot be added.

## Supported key file formats
- PuTTY private key file (.ppk) file format
## Supported Key File Formats
- PuTTY private key file (.ppk)
- OpenSSH format

## Supported key formats
- rsa
- ecdsa
- ed25519

(dsa, ecdsa-sk, ed25519-sk are not supported)
## Supported Key Types
- RSA
- ECDSA
- ED25519

(DSA, ECDSA-SK, ED25519-SK are not supported)

## FAQ

### Where is the passphrase for the private key stored?

It's stored in [Windows Credential Manager](https://support.microsoft.com/en-us/windows/accessing-credential-manager-1b5c916a-6a16-889f-8581-fc16e8165ac0).
Passphrases are stored in the [Windows Credential Manager](https://support.microsoft.com/en-us/windows/accessing-credential-manager-1b5c916a-6a16-889f-8581-fc16e8165ac0).

# Screen shot
## Screenshots

<img src="https://github.com/masahide/OmniSSHAgent/blob/main/doc/screen.png?raw=true" width="500">
<img src="https://github.com/masahide/OmniSSHAgent/blob/main/doc/screen-setup.png?raw=true" width="500">
Loading
Loading