Using OmniSSHAgent
Windows comes with standard OpenSSH and ssh-agent. MSYS2 also has /usr/bin/ssh, allowing you to use SSH, Git, rsync, and other tools in a Unix-like environment.
The problem is that you can't directly use keys registered in Windows' ssh-agent with MSYS2's ssh.
This article will outline why this problem occurs, what solutions are available, and then introduce a configuration using OmniSSHAgent, which I personally find the easiest to use.
As of August 2026, using OmniSSHAgent is a good first choice for Windows 11 x64 environments.
Conclusion
The configuration is as follows:
MSYS2 /usr/bin/ssh
│
│ SSH_AUTH_SOCK
▼
Cygwin/MSYS2 compatible socket
│
│ OmniSSHAgent
▼
Windows OpenSSH ssh-agent
│
▼
Private key
OmniSSHAgent is not an SSH agent that manages private keys itself.
It's a bridge that converts the interface so that you can use the standard Windows OpenSSH Authentication Agent from MSYS2/Cygwin. The current OmniSSHAgent connects to the Windows OpenSSH agent's \\.\pipe\openssh-ssh-agent and publishes a Cygwin/MSYS2 compatible interface.
The advantages of this configuration are:
- You can use the standard Windows
ssh-agentfor key management. - You can use MSYS2's
/usr/bin/sshdirectly. - Git, scp, rsync, and other tools can use the same agent.
- It can start automatically after Windows relogin.
- It can also be used with the Pageant interface for PuTTY / WinSCP / TortoiseGit.
- OmniSSHAgent itself does not store private keys or passphrases.
Why can't you use Windows' ssh-agent directly?
Windows OpenSSH and MSYS2 OpenSSH both have commands named ssh, so it seems like you should be able to connect directly.
However, the communication methods with the SSH agent are different.
Windows OpenSSH uses Windows Named Pipes.
\\.\pipe\openssh-ssh-agent
On the other hand, MSYS2, Cygwin, and Git for Windows' Unix-like OpenSSH use Cygwin/MSYS2-style sockets via SSH_AUTH_SOCK.
Therefore,
Windows OpenSSH
↓
Windows Named Pipe
and
MSYS2 OpenSSH
↓
Cygwin/MSYS2 compatible socket
are different.
The OmniSSHAgent README explains that the reason this tool exists is that Windows native OpenSSH, Pageant, and Git for Windows/MSYS2/Cygwin all use incompatible SSH agent interfaces.
Therefore, simply setting
export SSH_AUTH_SOCK='\\.\pipe\openssh-ssh-agent'
in MSYS2 will not solve the problem.
What is needed is a bridge that translates between the protocols/socket formats.
Comparing solutions
There are several ways to use Windows' ssh-agent from MSYS2.
| Method | MSYS2 /usr/bin/ssh
|
Ease of Setup | Recommendation |
|---|---|---|---|
| OmniSSHAgent | ○ | High | ★★★★★ |
| sshwin-msys2 | ○ | Relatively High | ★★★★☆ |
| socat + npiperelay | ○ | Somewhat Complex | ★★☆☆☆ |
Use Windows ssh.exe directly |
× | Very Easy | Depends on Use Case |
Directly specify Named Pipe as SSH_AUTH_SOCK
|
× | - | Not Possible |
For Windows 11 x64, OmniSSHAgent is the most complete choice at the moment.
What is OmniSSHAgent?
OmniSSHAgent is an SSH agent compatibility bridge for Windows.
In its current design,
Windows OpenSSH Authentication Agent
is used as the only backend for key management.
OmniSSHAgent itself does not:
- Store private keys
- Store passphrases
- Replace Windows'
ssh-agent
It specializes in adding a
Pageant
Cygwin/MSYS2
compatible interface to the Windows OpenSSH agent.
This design is quite straightforward.
Key management is centralized in
Windows OpenSSH ssh-agent
and OmniSSHAgent only bridges the clients:
Windows ssh.exe
MSYS2 ssh
Git for Windows
PuTTY
WinSCP
TortoiseGit
Currently, the target environment for OmniSSHAgent MVP is Windows 11 x86-64. Windows 10 and ARM64 are not supported in the current version.
1. Enable Windows ssh-agent
First, enable the standard Windows OpenSSH Authentication Agent.
Open PowerShell with administrator privileges.
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
Check the status.
Get-Service ssh-agent
If it shows Running, it's OK.
The Microsoft official documentation also provides this setting as a way to automatically start Windows' ssh-agent.
2. Register the private key in Windows ssh-agent
For example, for an Ed25519 key:
ssh-add $env:USERPROFILE\.ssh\id_ed25519
Check the registered keys.
ssh-add -l
If it displays something like:
256 SHA256:xxxxxxxxxxxxxxxx user@example (ED25519)
then Windows is ready.
From now on, the main entity managing the keys will be this Windows ssh-agent.
3. Install OmniSSHAgent
The OmniSSHAgent official README provides a PowerShell installer.
Run from PowerShell or PowerShell 7.
irm https://raw.githubusercontent.com/masahide/OmniSSHAgent/main/install.ps1 | iex
The installer will:
- Obtain the latest x86-64 release
- Verify the SHA-256 checksum
- Place it in
%LOCALAPPDATA%\Programs\OmniSSHAgent - Create a Start Menu shortcut
- Start OmniSSHAgent
Administrator privileges are not required.
If you don't want to run the script directly, you can also install it by checking the release contents from GitHub Releases.
As of August 26, 2026, v0.8.0 is the latest release. v0.8.0 adds tray settings and Windows autostart.
4. Enable the Cygwin/MSYS2 interface
When you start OmniSSHAgent, an icon will appear in the notification area.
From the menu, enable:
Cygwin/MSYS2 interface
The current OmniSSHAgent creates a socket descriptor for MSYS2/Cygwin at:
%USERPROFILE%\.ssh\omnisshagent-cygwin.sock
by default.
5. Set SSH_AUTH_SOCK in MSYS2
Start MSYS2 and run:
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
Check it.
echo "$SSH_AUTH_SOCK"
For example:
/c/Users/example/.ssh/omnisshagent-cygwin.sock
Next, run:
ssh-add -l
If the same keys that were registered on the Windows side are displayed, it's successful.
The OmniSSHAgent official README also describes this SSH_AUTH_SOCK setting for MSYS2 / Git Bash / Cygwin.
6. Verify that you are actually using MSYS2's ssh
There may be multiple ssh.exe files on Windows, so it's a good idea to check.
which ssh
which ssh-add
The one you want to use is:
/usr/bin/ssh
/usr/bin/ssh-add
That is:
$ which ssh
/usr/bin/ssh
$ ssh-add -l
256 SHA256:...
If so, communication is happening via:
MSYS2 OpenSSH → OmniSSHAgent → Windows ssh-agent.
7. Automate by adding to .bashrc
You don't need to set SSH_AUTH_SOCK every time.
Add the following to ~/.bashrc:
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
Open a new MSYS2 shell and:
ssh-add -l
If it succeeds, you're done.
After restarting/re-logging into Windows
This is another point where OmniSSHAgent is easy to use.
If autostart is configured correctly, you usually don't need to manually start OmniSSHAgent every time you relogin.
Windows ssh-agent
Windows' ssh-agent is set as a service:
Get-Service ssh-agent | Set-Service -StartupType Automatic
so it starts automatically when Windows starts.
OmniSSHAgent
In the notification area, enable:
Start with Windows
This registers autostart for the current user.
Administrator privileges are not required.
This feature was added in OmniSSHAgent v0.8.0.
MSYS2
Add the following to ~/.bashrc:
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
so it's automatically set when the MSYS2 shell starts.
Therefore, overall:
Windows startup
↓
Windows ssh-agent starts automatically
↓
Windows login
↓
OmniSSHAgent starts automatically
↓
omnisshagent-cygwin.sock is created
↓
MSYS2 startup
↓
.bashrc sets SSH_AUTH_SOCK
↓
/usr/bin/ssh uses Windows ssh-agent
For normal operation, you just start MSYS2 and:
ssh example.com
How to verify after relogin
When problems occur, it's easier to check from the top down.
First, in PowerShell:
Get-Service ssh-agent
Check if it's Running.
Next:
ssh-add -l
to check if the keys are visible to the Windows agent.
Next, check if OmniSSHAgent is running in the notification area.
Finally, in MSYS2:
echo "$SSH_AUTH_SOCK"
ssh-add -l
This will make it easier to isolate:
Key problem
Windows ssh-agent problem
OmniSSHAgent problem
MSYS2 environment variable problem
OmniSSHAgent has logging and diagnostics features, and the logs are saved at:
%LOCALAPPDATA%\OmniSSHAgent\logs
Security considerations for OmniSSHAgent
When evaluating OmniSSHAgent, it's important to note that it does not store the private keys themselves.
In the current design:
Private key
↓
Windows OpenSSH ssh-agent
The private key is stored there, and OmniSSHAgent only bridges the signing requests.
The official README explains the security model:
- Does not store private keys
- Does not store passphrases
- Does not write SSH agent payloads to logs
- Cygwin compatibility listener is bound only to
127.0.0.1 - Uses nonce handshake for Cygwin socket descriptor
Of course, even when using an SSH agent, there are SSH agent-specific security considerations regarding "signing requests from processes that can access the agent."
However, centralizing key management in Windows OpenSSH agent is a management advantage compared to registering the same private keys in multiple agents:
Windows agent
MSYS2 agent
Pageant
sshwin-msys2 as an alternative
Another tool, sshwin-msys2, is also available.
This also uses the Windows OpenSSH named pipe as a backend and creates a socket descriptor that MSYS2 can recognize.
In a standard C:\msys64 environment:
C:\MSYS64\tmp\sshwin-msys2.sock
is created, and on the MSYS2 side:
export SSH_AUTH_SOCK=/tmp/sshwin-msys2.sock
is set.
The README also states that it has been tested with Windows 10 build 19044 and MSYS2, Git Bash, and WSL2.
Therefore,
If you are using Windows 10, sshwin-msys2 is also a viable option.
However, for Windows 11 x64, OmniSSHAgent is easier to use because:
- Tray application
- Cygwin/MSYS2 interface
- Pageant interface
- Windows autostart
- Logging
- Diagnostics
- Centralization on the Windows OpenSSH backend
What about socat + npiperelay?
Another method often mentioned is combining:
socat
+
npiperelay
to connect Windows Named Pipes and Unix sockets.
Conceptually:
MSYS2 ssh
↓
Unix socket
↓
socat
↓
npiperelay
↓
Windows Named Pipe
↓
Windows ssh-agent
This is a common method in WSL, but problems may arise with how MSYS2 handles native Windows executables and standard input/output.
In fact, issue #13 in the npiperelay repository describes a case where someone tried to connect from MSYS2 to the Windows OpenSSH agent and encountered:
copy from stdin to pipe failed:
read /dev/stdin: invalid argument
Since the number of components is also increasing, OmniSSHAgent or sshwin-msys2 are simpler solutions if the goal is only MSYS2.
Using Windows ssh.exe directly may be sufficient for Git
If the goal is only:
git clone
git pull
git push
then you don't need to use MSYS2's ssh.
You can make Git use:
C:\Windows\System32\OpenSSH\ssh.exe
directly, which uses the Windows ssh-agent directly.
This method is very simple.
However, if you want to use the MSYS2 OpenSSH itself, such as:
/usr/bin/ssh
scp
sftp
rsync -e ssh
then OmniSSHAgent is more suitable.
About WSL2
Note that the current OmniSSHAgent does not directly bridge the socket for WSL2.
In the current OmniSSHAgent design:
MSYS2 / Cygwin
→ OmniSSHAgent
Pageant
→ OmniSSHAgent
WSL2
→ Pipeferry
the roles are divided.
If you want to use the Windows OpenSSH agent from WSL2, Pipeferry, which is by the same author, is recommended.
Older articles about OmniSSHAgent may mention WSL functionality, so be careful when searching.
Why I recommend OmniSSHAgent
If the premise is Windows 11 x64 + MSYS2, I recommend OmniSSHAgent.
It's not just because "it works."
The design is clearly separated:
Key management
= Windows OpenSSH ssh-agent
Compatibility conversion
= OmniSSHAgent
OmniSSHAgent does not create its own key store; it centers on the standard Windows agent.
Then, it bridges the differences in interface:
Windows OpenSSH
MSYS2
Cygwin
Git for Windows
PuTTY系アプリ
Furthermore, with v0.8.0, Windows autostart was added, so:
ssh-agent automatic startup
OmniSSHAgent automatic startup
Set SSH_AUTH_SOCK in .bashrc
is all you need to do, and you usually don't need to be aware of the bridge in daily use.
Final Settings
PowerShell — One-time setup
Administrator PowerShell:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
ssh-add -l
OmniSSHAgent
From the notification area:
✓ Cygwin/MSYS2 interface
✓ Start with Windows
MSYS2 ~/.bashrc
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
Verification
which ssh
ssh-add -l
Expected state:
/usr/bin/ssh
256 SHA256:xxxxxxxxxxxxxxxx ...
This completes the configuration:
MSYS2 /usr/bin/ssh
↓
OmniSSHAgent
↓
Windows OpenSSH ssh-agent
Summary
When using SSH in both Windows and MSYS2, the SSH agent can end up being double-managed.
For example:
Register the key in Windows ssh-agent
Register the key in MSYS2 ssh-agent
This configuration can make startup and SSH_AUTH_SOCK management more complex.
With OmniSSHAgent, you can:
┌─ Windows OpenSSH
│
Windows ├─ MSYS2 / Cygwin
OpenSSH agent ───┤
└─ Pageant compatible apps
This centralizes the Windows OpenSSH agent as the key management center.
In particular, if:
- Windows 11 x64
- You want to use MSYS2's
/usr/bin/ssh - You want to centralize key management in the Windows ssh-agent
- You want it to be available automatically after relogin
then OmniSSHAgent is a very user-friendly choice at the moment.
Ultimately, you only need:
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
in MSYS2.
I think it's a relatively clean way to resolve the SSH agent issues that often arise at the boundary between Windows and Unix-like tools.
References
- OmniSSHAgent README / Architecture / Installation / MSYS2 setup / Security model
- OmniSSHAgent Releases — v0.8.0 adds Windows autostart
- Microsoft Learn — Automatically starting Windows
ssh-agentandssh-add - sshwin-msys2 — Another implementation for using Windows OpenSSH agent from MSYS2
- npiperelay issue #13 — MSYS2 + socat standard input error case
Windows の ssh-agent を MSYS2 の ssh から使う
OmniSSHAgent を使う方法
Windows には標準の OpenSSH と ssh-agent が用意されています。一方、MSYS2 にも /usr/bin/ssh があり、Unix に近い環境で SSH や Git、rsync などを使えます。
ここで問題になるのが、Windows の ssh-agent に登録した鍵を MSYS2 の ssh からそのまま利用できないことです。
この記事では、この問題がなぜ起きるのか、どのような解決策があるのかを整理した上で、個人的に最も扱いやすいと考える OmniSSHAgent を使った構成を紹介します。
2026年8月時点では、Windows 11 x64 環境であれば OmniSSHAgent を使う方法を第一候補にするのがよいでしょう。
結論
先に結論を書くと、構成は次のようにします。
MSYS2 /usr/bin/ssh
│
│ SSH_AUTH_SOCK
▼
Cygwin/MSYS2互換 socket
│
│ OmniSSHAgent
▼
Windows OpenSSH ssh-agent
│
▼
秘密鍵
OmniSSHAgent は秘密鍵を独自管理する SSH agent ではありません。
Windows 標準の OpenSSH Authentication Agent をそのまま使い、そのインターフェースを MSYS2/Cygwin から利用できる形に変換するブリッジとして動作します。現在の OmniSSHAgent は Windows OpenSSH agent の \\.\pipe\openssh-ssh-agent に接続し、MSYS2/Cygwin 向けの互換インターフェースを公開します。
この構成の利点は、
- Windows 標準
ssh-agentを鍵管理の中心にできる - MSYS2 の
/usr/bin/sshをそのまま使える - Git、scp、rsync なども同じ agent を利用できる
- Windows 再ログイン後も自動起動できる
- PuTTY / WinSCP / TortoiseGit 用の Pageant インターフェースも利用可能
- OmniSSHAgent 自体は秘密鍵やパスフレーズを保存しない
という点です。
なぜ Windows の ssh-agent を直接使えないのか
Windows OpenSSH と MSYS2 OpenSSH は、どちらも ssh という名前なので一見そのまま接続できそうに見えます。
しかし SSH agent との通信方式が異なります。
Windows OpenSSH は Windows の Named Pipe を使用します。
\\.\pipe\openssh-ssh-agent
一方、MSYS2、Cygwin、Git for Windows の Unix 系 OpenSSH は、Cygwin/MSYS2 形式の socket を SSH_AUTH_SOCK 経由で利用します。
つまり、
Windows OpenSSH
↓
Windows Named Pipe
と、
MSYS2 OpenSSH
↓
Cygwin/MSYS2互換 socket
という違いがあります。
OmniSSHAgent の README でも、Windows ネイティブ OpenSSH、Pageant、Git for Windows/MSYS2/Cygwin がそれぞれ互換性のない SSH agent インターフェースを利用していることが、このツールの存在理由として説明されています。
そのため、単純に MSYS2 で、
export SSH_AUTH_SOCK='\\.\pipe\openssh-ssh-agent'
などと設定しても解決しません。
必要なのは プロトコル/ソケット形式を橋渡しするブリッジです。
解決方法の比較
Windows の ssh-agent を MSYS2 から使う方法はいくつかあります。
| 方法 | MSYS2 /usr/bin/ssh
|
設定の容易さ | おすすめ度 |
|---|---|---|---|
| OmniSSHAgent | ○ | 高い | ★★★★★ |
| sshwin-msys2 | ○ | 比較的高い | ★★★★☆ |
| socat + npiperelay | ○ | やや複雑 | ★★☆☆☆ |
Windows ssh.exe を直接使う |
× | 非常に簡単 | 用途次第 |
Named Pipe を SSH_AUTH_SOCK に直接指定 |
× | - | 不可 |
Windows 11 x64 なら、現在は OmniSSHAgent が最もまとまりのよい選択肢です。
OmniSSHAgent とは
OmniSSHAgent は Windows 用の SSH agent compatibility bridge です。
現在の設計では、
Windows OpenSSH Authentication Agent
を鍵管理の唯一のバックエンドとして利用します。
OmniSSHAgent 自身が、
- 秘密鍵を保存する
- パスフレーズを保存する
- Windows の
ssh-agentを置き換える
わけではありません。
Windows OpenSSH agent に対して、
Pageant
Cygwin/MSYS2
という互換インターフェースを追加する役割に特化しています。
これは設計としてかなり分かりやすいです。
鍵管理は、
Windows OpenSSH ssh-agent
に一本化し、
Windows ssh.exe
MSYS2 ssh
Git for Windows
PuTTY
WinSCP
TortoiseGit
などのクライアント側だけを OmniSSHAgent が橋渡しします。
なお、現在の OmniSSHAgent MVP の対象環境は Windows 11 x86-64 です。Windows 10 や ARM64 は現行版の対象外とされています。
1. Windows ssh-agent を有効にする
まず Windows 標準の OpenSSH Authentication Agent を有効にします。
管理者権限で PowerShell を起動します。
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
状態を確認します。
Get-Service ssh-agent
Running になっていれば OK です。
Microsoft 公式ドキュメントでも、Windows の ssh-agent を自動起動する方法としてこの設定が案内されています。
2. 秘密鍵を Windows ssh-agent に登録する
例えば Ed25519 鍵なら、
ssh-add $env:USERPROFILE\.ssh\id_ed25519
登録された鍵を確認します。
ssh-add -l
例えば、
256 SHA256:xxxxxxxxxxxxxxxx user@example (ED25519)
のように表示されれば Windows 側は準備完了です。
今後、鍵を管理する主体は OmniSSHAgent ではなく、この Windows ssh-agent になります。
3. OmniSSHAgent をインストールする
OmniSSHAgent 公式 README では PowerShell installer が用意されています。
PowerShell または PowerShell 7 から実行します。
irm https://raw.githubusercontent.com/masahide/OmniSSHAgent/main/install.ps1 | iex
インストーラは、
- 最新 x86-64 release の取得
- SHA-256 checksum の検証
-
%LOCALAPPDATA%\Programs\OmniSSHAgentへの配置 - Start Menu shortcut の作成
- OmniSSHAgent の起動
を行います。
管理者権限は不要です。
リモートスクリプトをそのまま実行したくない場合は、GitHub Releases からリリース内容を確認した上で導入する方法でも構いません。
2026年8月26日時点では v0.8.0 が Latest release として公開されています。v0.8.0 では tray settings と Windows autostart が追加されています。
4. Cygwin/MSYS2 interface を有効にする
OmniSSHAgent を起動すると通知領域にアイコンが表示されます。
メニューから、
Cygwin/MSYS2 interface
を有効にします。
現在の OmniSSHAgent はデフォルトで、
%USERPROFILE%\.ssh\omnisshagent-cygwin.sock
に MSYS2/Cygwin 用 socket descriptor を作成します。
5. MSYS2 に SSH_AUTH_SOCK を設定する
MSYS2 を起動して、
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
を実行します。
確認します。
echo "$SSH_AUTH_SOCK"
例えば、
/c/Users/example/.ssh/omnisshagent-cygwin.sock
のようになります。
次に重要なのが、
ssh-add -l
です。
Windows 側で登録した鍵と同じものが表示されれば成功です。
OmniSSHAgent 公式 README でも、MSYS2 / Git Bash / Cygwin についてこの SSH_AUTH_SOCK 設定が案内されています。
6. 本当に MSYS2 の ssh を使っているか確認する
Windows には複数の ssh.exe が存在することがあるので、一度確認しておくことをおすすめします。
which ssh
which ssh-add
今回使いたいのは、
/usr/bin/ssh
/usr/bin/ssh-add
です。
つまり、
$ which ssh
/usr/bin/ssh
$ ssh-add -l
256 SHA256:...
となれば、
MSYS2版 OpenSSH → OmniSSHAgent → Windows ssh-agent
という経路で通信できています。
7. .bashrc に設定して自動化する
毎回 SSH_AUTH_SOCK を設定する必要はありません。
~/.bashrc に、
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
を追加します。
新しい MSYS2 shell を開いて、
ssh-add -l
が成功すれば完了です。
Windows を再起動・再ログインした場合
ここも OmniSSHAgent をおすすめしやすいポイントです。
自動起動を正しく設定しておけば、普段は再ログインのたびに OmniSSHAgent を手動で起動する必要はありません。
Windows ssh-agent
Windows の ssh-agent はサービスとして、
Get-Service ssh-agent | Set-Service -StartupType Automatic
にしてあります。
そのため Windows 起動時に自動で立ち上がります。
OmniSSHAgent
通知領域の OmniSSHAgent メニューで、
Start with Windows
を有効にします。
これは現在のユーザーに対する autostart を登録します。
管理者権限は不要です。
この機能は OmniSSHAgent v0.8.0 で追加されています。
MSYS2
~/.bashrc に、
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
を入れてあるので、MSYS2 shell 起動時に自動設定されます。
したがって全体として、
Windows起動
↓
Windows ssh-agent 自動起動
↓
Windowsログイン
↓
OmniSSHAgent 自動起動
↓
omnisshagent-cygwin.sock 作成
↓
MSYS2起動
↓
.bashrc が SSH_AUTH_SOCK を設定
↓
/usr/bin/ssh が Windows ssh-agent を利用
となります。
普段の操作としては、MSYS2 を起動して、
ssh example.com
するだけです。
再ログイン後の確認方法
問題が起きたときは、上流から順番に確認すると分かりやすいです。
まず PowerShell で、
Get-Service ssh-agent
Running か確認します。
次に、
ssh-add -l
で Windows agent に鍵が見えているか確認します。
次に OmniSSHAgent が通知領域で起動しているか確認します。
最後に MSYS2 で、
echo "$SSH_AUTH_SOCK"
ssh-add -l
を確認します。
この順番なら、
鍵の問題
Windows ssh-agent の問題
OmniSSHAgent の問題
MSYS2環境変数の問題
を切り分けやすくなります。
OmniSSHAgent にはログや configuration check 用の機能も用意されており、ログは、
%LOCALAPPDATA%\OmniSSHAgent\logs
に保存されます。
OmniSSHAgent のセキュリティ面
OmniSSHAgent を評価するときに重要なのは、秘密鍵そのものを保持しない点です。
現在の設計では、
秘密鍵
↓
Windows OpenSSH ssh-agent
に保持され、
OmniSSHAgent は署名要求などを bridge するだけです。
公式 README では、
- 秘密鍵を保存しない
- passphrase を保存しない
- SSH agent payload をログに書かない
- Cygwin compatibility listener は
127.0.0.1のみに bind - Cygwin socket descriptor の nonce handshake を使用
というセキュリティモデルが説明されています。
もちろん SSH agent 自体を利用する以上、「agent にアクセスできるプロセスによる署名要求」という SSH agent 共通のセキュリティ上の考慮は残ります。
それでも、
Windowsのagent
MSYS2のagent
Pageant
などに同じ秘密鍵を何重にも登録するより、Windows OpenSSH agent に一本化できる点は管理上のメリットがあります。
sshwin-msys2 という選択肢
OmniSSHAgent 以外では sshwin-msys2 というツールもあります。
これも Windows OpenSSH の named pipe を backend として利用し、MSYS2 が認識できる socket descriptor を作ります。
標準的な C:\msys64 環境では、
C:\MSYS64\tmp\sshwin-msys2.sock
を作成し、MSYS2 側では、
export SSH_AUTH_SOCK=/tmp/sshwin-msys2.sock
と設定します。
README では Windows 10 build 19044 と MSYS2、Git Bash、WSL2 でのテスト実績も記載されています。
そのため、
Windows 10 を使っている場合は sshwin-msys2 も有力候補
です。
一方、Windows 11 x64 なら、
- tray application
- Cygwin/MSYS2 interface
- Pageant interface
- Windows autostart
- logging
- diagnostics
- Windows OpenSSH backend への一本化
までまとまっている OmniSSHAgent の方が使いやすいと考えます。
socat + npiperelay はどうか
Windows Named Pipe と Unix socket を接続する方法として、
socat
+
npiperelay
を組み合わせる方法もよく紹介されています。
概念的には、
MSYS2 ssh
↓
Unix socket
↓
socat
↓
npiperelay
↓
Windows Named Pipe
↓
Windows ssh-agent
となります。
WSL ではよく利用される方式ですが、MSYS2 では native Windows executable と MSYS2 の標準入出力の扱いが問題になる場合があります。
実際、npiperelay の issue には MSYS2 から Windows OpenSSH agent に接続しようとして、
copy from stdin to pipe failed:
read /dev/stdin: invalid argument
となった事例があります。
構成要素も増えるので、MSYS2 だけが目的なら、現在は OmniSSHAgent や sshwin-msys2 の方が素直です。
Git だけなら Windows ssh.exe を使う手もある
目的が、
git clone
git pull
git push
だけなら、そもそも MSYS2 の ssh を使わない方法もあります。
Windows の、
C:\Windows\System32\OpenSSH\ssh.exe
を Git に使わせれば Windows ssh-agent を直接利用できます。
この方法は bridge が不要なので非常に単純です。
ただし、
/usr/bin/ssh
scp
sftp
rsync -e ssh
など MSYS2 OpenSSH 自体を利用したい場合には解決になりません。
MSYS2 の Unix 的な環境を維持したい場合は OmniSSHAgent の方が適しています。
WSL2 について
注意点として、現在の OmniSSHAgent は WSL2 の socket bridge を直接担当しません。
OmniSSHAgent の現在の設計では、
MSYS2 / Cygwin
→ OmniSSHAgent
Pageant
→ OmniSSHAgent
WSL2
→ Pipeferry
と役割が分けられています。
WSL2 から Windows OpenSSH agent を使う場合は、同じ作者による Pipeferry が案内されています。
古い OmniSSHAgent の記事では WSL 機能も紹介されている場合があるため、検索時には注意が必要です。
OmniSSHAgent をおすすめする理由
Windows 11 x64 + MSYS2 という前提なら、OmniSSHAgent をおすすめします。
理由は単に「動くから」だけではありません。
設計が、
鍵管理
= Windows OpenSSH ssh-agent
互換性変換
= OmniSSHAgent
と明確に分離されているからです。
OmniSSHAgent は独自の鍵ストアを作るのではなく、Windows 標準の agent を中心に据えます。
その上で、
Windows OpenSSH
MSYS2
Cygwin
Git for Windows
PuTTY系アプリ
のインターフェース差だけを吸収します。
さらに v0.8.0 では Windows autostart が入ったため、
ssh-agent 自動起動
OmniSSHAgent 自動起動
SSH_AUTH_SOCK を .bashrc に設定
まで行えば、日常的には bridge の存在を意識する必要がほぼありません。
最終的な設定
PowerShell — 一度だけ
管理者 PowerShell:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
ssh-add -l
OmniSSHAgent
通知領域から、
✓ Cygwin/MSYS2 interface
✓ Start with Windows
を有効にします。
MSYS2 ~/.bashrc
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
動作確認
which ssh
ssh-add -l
期待する状態:
/usr/bin/ssh
256 SHA256:xxxxxxxxxxxxxxxx ...
これで、
MSYS2 /usr/bin/ssh
↓
OmniSSHAgent
↓
Windows OpenSSH ssh-agent
という構成が完成します。
まとめ
Windows と MSYS2 の両方で SSH を使っていると、SSH agent が二重管理になりがちです。
例えば、
Windows ssh-agent に鍵を登録
MSYS2 ssh-agent にも鍵を登録
という構成にすると、起動処理や SSH_AUTH_SOCK の管理も複雑になります。
OmniSSHAgent を使えば、
┌─ Windows OpenSSH
│
Windows ├─ MSYS2 / Cygwin
OpenSSH agent ───┤
└─ Pageant互換アプリ
という形で、Windows OpenSSH agent を SSH 鍵管理の中心にできます。
特に、
- Windows 11 x64
- MSYS2 の
/usr/bin/sshを使いたい - Windows の ssh-agent に鍵管理を一本化したい
- 再ログイン後も自動で利用可能にしたい
という環境なら、現時点では OmniSSHAgent が非常に扱いやすい選択肢です。
MSYS2 側に必要なのは最終的に、
export SSH_AUTH_SOCK="$(cygpath -u "$USERPROFILE/.ssh/omnisshagent-cygwin.sock")"
だけです。
Windows と Unix 系ツールの境界でありがちな SSH agent 問題を、比較的きれいに解消できる構成だと思います。
参考資料
- OmniSSHAgent README / Architecture / Installation / MSYS2 setup / Security model
- OmniSSHAgent Releases — v0.8.0 で Windows autostart を追加
- Microsoft Learn — Windows OpenSSH
ssh-agentの自動起動とssh-add - sshwin-msys2 — MSYS2 から Windows OpenSSH agent を利用する別実装
- npiperelay issue #13 — MSYS2 + socat での標準入力エラー事例
Top comments (0)