Strovent SystemsSign in
Reference

Windows OpenSSH server asks for a password for an admin user: administrators_authorized_keys

On Windows, sshd reads keys for Administrators members from C:\ProgramData\ssh\administrators_authorized_keys, not the profile .ssh folder. Set its ACL.

You put your public key in C:\Users\user1\.ssh\authorized_keys on a Windows machine running the OpenSSH server, but the server still asks for a password or replies Permission denied (publickey). If that account is in the local Administrators group, this is expected: sshd does not read that file for administrators.

Why the key is ignored

The default sshd_config on Windows (in C:\ProgramData\ssh\) ends with:

Match Group administrators
       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

So for every member of Administrators, sshd reads one shared file, C:\ProgramData\ssh\administrators_authorized_keys, instead of the file in the user's profile. Accounts that are not administrators keep using .ssh\authorized_keys in their profile.

Fix

Put the public key, one line per key, in C:\ProgramData\ssh\administrators_authorized_keys. Then set the file's permissions from an elevated PowerShell prompt, as Microsoft's guide shows:

icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

Microsoft's guide says the file should only have entries for SYSTEM, which needs full control, and Administrators. The command above removes inherited entries and sets exactly those two. If another user or group can change the file, sshd refuses to use it. On Windows in another language, the group name differs; use the SID with an asterisk instead, /grant "*S-1-5-32-544:F".

A new key in the file works on the next login. No restart is needed for that.

Other choices

  • Use the profile file for admins too. Comment out the two Match Group administrators lines in sshd_config, then restart the service with Restart-Service sshd. sshd then reads .ssh\authorized_keys in each profile, as it does for other users.
  • Use a non-admin account for SSH if the work does not need admin rights.

See what sshd says

By default the Windows OpenSSH server logs to Event Viewer, under the OpenSSH logs. A file with the wrong permissions shows up there as Bad permissions. Try removing permissions for user: followed by the account to remove, then Authentication refused. For a log file instead, set SyslogFacility LOCAL0 (and, for more detail, LogLevel DEBUG3) in sshd_config and restart the service; logs then go to C:\ProgramData\ssh\logs.

Sources

Spotted a mistake? Email [email protected].