Repository navigation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest version
- Search the existing issues.
Steps to reproduce
Project: PowerShell/Win32-OpenSSH (the OpenSSH for Windows port).
This is NOT a PowerShell engine issue — filed here because this repo has no
issue template of its own.
Environment: Windows 11 Pro for Workstations 10.0.26300 (x64),
OpenSSH_for_Windows_10.4p1 (LibreSSL 4.3.3), unpacked from OpenSSH-Win64.zip
(10.4.0.0p1-Preview).
In an elevated PowerShell:
Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\ssh-agent' `
-Name ImagePath -Value 'C:\tools\openssh-10.4\ssh-agent.exe'
Set-Service ssh-agent -StartupType Manual
sc.exe start ssh-agent
Start-Sleep 4
sc.exe queryex ssh-agent
Get-WinEvent -LogName 'OpenSSH/Admin' -MaxEvents 1These exact steps on a second Windows 11 10.0.26300 machine, with the same
binary and the same registry/service state, leave the service RUNNING.
Expected behavior
SERVICE_NAME: ssh-agent
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
WIN32_EXIT_CODE : 0 (0x0)Actual behavior
SERVICE_NAME: ssh-agent
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1067 (0x42b)
SERVICE_EXIT_CODE : 0 (0x0)Error details
OpenSSH/Admin — Event ID 1 (Critical):
ssh-agent: fatal: cannot create agent root reg key, ERROR:5
System — Event ID 7034 (on every attempt):
The OpenSSH Authentication Agent service terminated unexpectedly.
Process Monitor, filter "Process Name is ssh-agent.exe", during the failed start:
RegOpenKey HKLM\System\CurrentControlSet\Services\WinSock2\Parameters
ACCESS DENIED Desired Access: All Access
RegCreateKey HKLM\SOFTWARE\OpenSSH
SUCCESS Desired Access: Maximum Allowed,
Granted Access: Read, Create Link
RegCreateKey HKLM\SOFTWARE\OpenSSH\Agent
ACCESS DENIED Desired Access: Write
No WER dump is produced even with LocalDumps configured for ssh-agent.exe —
the process exits cleanly rather than crashing.Two-machine comparison
| A (fails) | B (works) | |
|---|---|---|
| OS build | 10.0.26300 | 10.0.26300 |
| Binary | OpenSSH_for_Windows_10.4p1, same sha256 | same file |
HKLM\SOFTWARE\OpenSSH\Agent |
owner SYSTEM, SDDL O:SYG:SYD:PAI(A;OICI;KA;;;SY)(A;OICI;KA;;;BA), value ProcessID |
identical |
| Service | LocalSystem / SID_TYPE UNRESTRICTED / same sc privs |
identical |
IFEO MitigationOptions |
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 (19 bytes) |
identical |
| Defender ASR / Controlled Folder Access | none configured | none configured |
| WDAC policy files | 8 | 8, same file names |
| Secure Boot | Enabled (also tested Disabled, see 13) | Disabled |
| Hardware | Ryzen 9 9950X3D desktop | Ryzen 3 3250U laptop |
What has already been ruled out
Both machines: identical OS build (10.0.26300), same binary
(sha256 B67FF8BECD203502190EC42AC7787C24C2CD3325ED7700485FE7A1C83D2A7957),
same registry ACLs, same service config, same security posture. Only machine A fails.
- Binary / package integrity — same zip extracted on machine B → RUNNING.
- Path depth / drive — copied to the identical
D:\git\...\_tools\openssh-10.4
path on B → RUNNING. - Service ACL & privileges —
sc sdshow/sc qprivsalready matchinstall-sshd.ps1. - Registry key owner / DACL — applying the installer's exact SDDL and owner
(withSeRestorePrivilegeenabled) changes nothing. - RedirectionGuard — deleting the IFEO
MitigationOptionsvalue → stillERROR:5. - Pre-existing key state — deleting
HKLM\SOFTWARE\OpenSSH\Agententirely →
same error, and the key is not recreated. - Pre-creating keys —
HKLM\SOFTWARE\OpenSSH\Agent\Keysand
HKU\S-1-5-18\Software\OpenSSH\Agent\Keys→ no change. - Leftover
ProcessIDvalue — adding the same value on machine B does not break it. - Reboot — reproduces identically after clean restarts (4 times).
- Defender ASR / Controlled Folder Access / third-party AV — none on either machine.
%PATH%version mixing (the cause diagnosed in cannot create agent root reg key, ERROR:5 #285) — ruled out both directions:
adding the 10.4 dir beforeSystem32\OpenSSHon B (with reboot) does not break it;
removing it entirely from the machine PATH on A (with reboot) does not fix it.- VBS / HVCI / WDAC / Smart App Control — disabling the hypervisor on A
(bcdedit /set {current} hypervisorlaunchtype off+ reboot, soHypervisorPresent=False
and VBS status=0, matching machine B) → stillERROR:5. - Secure Boot — disabling it in firmware on A and rebooting → still
ERROR:5.
After the above, no known configuration difference remains between the two machines.
The decisive oddity
Pointing the same service at cmd.exe /c <script> (running as LocalSystem) and doing
reg add "HKLM\SOFTWARE\OpenSSH\__svcprobe" returns errorlevel 0 (success) on the
failing machine. So the service account itself can write that key — only
ssh-agent.exe cannot. This suggests the agent performs part of its initialisation
with a less-privileged effective token (impersonation / restricted token), and that
this path behaves differently on this machine.
Related issues
- cannot create agent root reg key, ERROR:5 #285 — same error string, closed 2016; diagnosed as a
%PATH%version mix-up
(ruled out here in both directions, see item 11). - sshd and ssh-agent not registered on 21H1 #1794 — services not registered at all; a different failure.
Questions
- Which registry key exactly is the "agent root reg key", and with which
samDesired? - Does the agent pass a
SECURITY_ATTRIBUTES(owner =BUILTIN\Administrators) to
RegCreateKeyEx? If so, that requiresSeRestorePrivilegeto be enabled in the
token, not merely assigned viasc privs. - Any known incompatibility between the 10.4 agent and Windows 11 build 26300 when
HKLM\SOFTWARE\OpenSSHpre-exists from an older install?
Additional observations
- The inbox 9.5p2 agent runs correctly on machine A — only the 10.4 build fails there.
- No WER dump is produced even with
LocalDumps\ssh-agent.execonfigured (DumpType=2),
i.e. the process returns and exits rather than crashing. stringson both 9.5p2 and 10.4p1 shows the same symbol set
(StartServiceCtrlDispatcherW,RegisterServiceCtrlHandlerW,SetServiceStatus,
\\.\pipe\openssh-ssh-agent,SOFTWARE\OpenSSH\Agent,SOFTWARE\OpenSSH\Agent\Keys,
RegOpenCurrentUser,cannot create agent root reg key, ERROR:%d) — same code generation.
Environment data
Name Value
---- -----
PSVersion 7.6.9
PSEdition Core
GitCommitId 7.6.9
OS Microsoft Windows 10.0.26300
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Version
OpenSSH 10.4.0.0p1-Preview (OpenSSH_for_Windows_10.4p1, LibreSSL 4.3.3) PowerShell 7.6.9
Visuals
No response
Activity
github-actions commentedon Nov 9, 2026
This is a well-documented Windows-specific
ssh-agentservice-startup regression that is ready for maintainer investigation.For maintainers
HKLM\\SOFTWARE\\OpenSSH, and a Windows-only event log diagnostic. A fix would belong in PowerShell/openssh-portable, not upstream OpenSSH. This is not an upstream-parity feature request.ssh-agentservice registry initialization), but identifying the machine-specific token/registry condition may require maintainer diagnostics before a safe patch can be specified.ssh-agent, specifically Windows service startup and creation/opening of the agent registry root; logging around the failing Win32 registry call may also help distinguish token, requested-access, and security-descriptor behavior.Related reports and triage notes
ssh-agentservice exiting during registry initialization, so it is not the same root cause.Suggested first diagnostic
Compare the 9.5p2 and 10.4 Windows agent startup paths at the
SOFTWARE\\OpenSSH\\Agentcreate/open call, including the effective token, requested registry access mask, and any supplied security descriptor. Capturing those values in diagnostic logging would help isolate why only the newer binary receivesERROR_ACCESS_DENIEDon this machine.The repository troubleshooting checklist may also help collect any additional traces maintainers request: https://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting-Steps
Add this agentic workflow to your repo
To install this agentic workflow, run
[-]# ssh-agent (10.4.0.0p1-Preview) fails to start on one Windows 11 26300 machine: `cannot create agent root reg key, ERROR:5`[/-][+]ssh-agent (10.4.0.0p1-Preview) fails to start on one Windows 11 26300 machine: `cannot create agent root reg key, ERROR:5`[/+]CoCooGitHub commentedon Nov 9, 2026
Follow-up: 9.5p2 vs 10.4p1 on the same machine
The "suggested first diagnostic" above can already be answered. I captured the startup of both agents on the same machine — same service, same
LocalSystemaccount, same registry state — with Process Monitor (filter: Process Name is ssh-agent.exe).9.5p2 (inbox, works) — PID 2808
0
ACCESS DENIEDresults for the whole process.10.4p1 (fails) — PID 14372
2
ACCESS DENIEDresults, exactly the two shown above.What this establishes
All AccessandWriteon exactly the same keys, seconds apart, under the same account and the sameservice configuration. Any theory that requires a damaged ACL / owner / hive state is
excluded by this.
HKLM\System\CurrentControlSet\Services\WinSock2\Parameters, which grantsSYSTEMfullcontrol on this machine, is denied with
Desired Access: All Access.full path (
RegCreateKey HKLM\SOFTWARE\OpenSSH\Agent), so the kernel opens the parent withKEY_CREATE_SUB_KEYand the call succeeds. 10.4p1 instead opens the parent explicitly first(
HKLM\SOFTWARE\OpenSSH,MAXIMUM_ALLOWED) and is only grantedRead, Create Link— whichdoes not include
KEY_CREATE_SUB_KEY— so the subsequent subkey creation must fail.Interpretation
Both binaries contain the same symbol set for service startup and the same registry paths, and
neither is affected by the environment (9.5p2 proves the environment is fine). The regression is
therefore in how the 10.4 agent establishes or holds its security context during startup.
It would help to know whether the 10.4 agent deliberately drops privileges (restricted token or
impersonation) during initialisation. If it does not, then the service is failing to run with the
token
services.exehanded to it — which would point at the service startup path rather than atthe registry code.
Either way, logging the effective token's SIDs and the exact
samDesiredat theSOFTWARE\OpenSSH\Agentcreate call would pin this down immediately.CoCooGitHub commentedon Nov 10, 2026
Additional finding: the foreground (
-d) agent terminates after serving a single requestWhile investigating the service-startup failure, I ran the same binary in its foreground mode
(
ssh-agent.exe -ddd) from an elevated console on the same machine. It starts correctly —creates
HKLM\SOFTWARE\OpenSSH\Agent, publishesProcessID, and creates\\.\pipe\openssh-ssh-agent— but it exits after handling exactly one client request, withexit code 0:
After that the process is gone (exit code 0), the named pipe is gone, and every subsequent
ssh-addreportsError connecting to agent: No such file or directory.Reproduction
Request type 11 is served correctly (the identity list comes back), so this is not a protocol
problem — the listener simply stops after the first connection is cleaned up.
The same binary fails at startup when started with a MEDIUM integrity token
Started from an elevated console the
-dddagent runs. Started from a normal console itstill dies at startup:
At the same moment, the same MEDIUM token can write to that key:
So the
ERROR:5is not an ACL problem: the caller is allowed to write the key, yetRegCreateKeyExW(..., KEY_WRITE, &sa, ...)still fails once theSECURITY_ATTRIBUTESargument isinvolved. That structure is built in
agent_start()(contrib/win32/win32compat/ssh-agent/agent.c):The last parameter of
ConvertStringSecurityDescriptorToSecurityDescriptorWis the outputsize of the security descriptor, so
sa.nLengthis overwritten with the SD length instead ofremaining
sizeof(SECURITY_ATTRIBUTES)— i.e. theSECURITY_ATTRIBUTEShanded toRegCreateKeyExWhas an invalidnLength. Note the supplied DACL also only grantsSYandBA,so an administrator token (where
BUILTIN\Administratorsis enabled) matches it while a normaluser token does not.
This block is byte-identical in v9.5.0.0 and v10.4.0.0, so on its own it does not explain the
regression — but it is very likely why the call fails for a caller that is otherwise permitted to
write the key.
Why this matters for the original report
Together these explain the earlier observations:
WIN32_EXIT_CODE 1067) while the same binary starts finewhen run in the foreground;
after the very first request.
Both behaviours are in the 10.4 Windows agent and are independent of the machine-to-machine
differences discussed in the original post.
tgauth commentedon Nov 11, 2026
Does using the ssh-agent steps in
install-sshd.ps1included in the provided zip configure the 10.4 ssh-agent service properly?Also I'd suggest installing to
C:\Program Filesinstead ofC:\toolsif possibleCoCooGitHub commentedon Nov 11, 2026
Thanks — the service startup issue is resolved.
The service now starts correctly
Installed to
C:\Program Files\OpenSSH, ran.\install-sshd.ps1from an elevatedconsole, then
Start-Service ssh-agent. The agent starts, stays running, andserves requests:
No more
cannot create agent root reg key, ERROR:5, no immediate exit, noWIN32_EXIT_CODE 1067.FYI only: foreground
-dstill exits after one requestNot a blocker for us — just noting it for completeness. Same build (10.4.0.0,
asset from
10.4.0.0p1-Preview, SHA256B67FF8BE…), installed the same way ontwo different machines, both run from an elevated console:
On both machines the request is served correctly, then the process exits with
code 0 (so no WER dump), the named pipe disappears, and any subsequent
ssh-addgetsNo such file or directory.-dis a debug-only path, and our actual use case — the service — works, so thisdoesn't affect us in practice. Feel free to close this issue; if you'd rather
track the
-dbehaviour separately I'm happy to open a new one with the detailsabove.
Thanks again for the help — much appreciated.
tgauth commentedon Nov 12, 2026
That's the intended behavior of debug mode.