Repository navigation
Description
"OpenSSH for Windows" version
((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion)
7.7.2.2
Server OperatingSystem
((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion\" -Name ProductName).ProductName)
Windows Server 2019 Standard
Client OperatingSystem
macOS Mojave Version 10.14.1
ssh -V
OpenSSH_7.8p1, LibreSSL 2.7.3
What is failing
PubKey Authentication with ed25519
Expected output
Successful Login over PubKey
Actual output
Permission Denied
** Additional Data**
Currently I'm trying to achieve PubKey Authentication against a Windows Server 2019, however I could not get it to work.
I actually created a ed259919 key and put it into the correct folder C:\Users\Administrator\.ssh\authorized_keys.
However it just does not work.
What is even strange is the Windows Server Debug output (ProgramData?!):
PS C:\Users\Administrator\unzipped> sshd -d
debug1: sshd version OpenSSH_for_Windows_7.7, LibreSSL 2.6.5
debug1: private host key #0: ssh-rsa SHA256:PNoOxXBKB4SCOQougpsAZ9bUnku658ur9+wucTvsGSc
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:GKf1jbg/+ayrPx+MOCTeCSBgJze/9R7kVYdw4WcEMU8
debug1: private host key #2: ssh-ed25519 SHA256:q8Rqf9l/eUiPMx9YfVSd3mQKxm/2Detld2UgLmIPyLU
debug1: rexec_argv[0]='C:\\Windows\\System32\\OpenSSH\\sshd.exe'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Server will not fork when running in debugging mode.
Connection from 192.168.179.152 port 61251 on 192.168.179.249 port 22
debug1: Client protocol version 2.0; client software version OpenSSH_7.8
debug1: match: OpenSSH_7.8 pat OpenSSH* compat 0x04000000
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: sshd version OpenSSH_for_Windows_7.7, LibreSSL 2.6.5
debug1: list_hostkey_types: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: algorithm: curve25519-sha256 [preauth]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
debug1: rekey after 134217728 blocks [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: rekey after 134217728 blocks [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user Administrator service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: user C:\\Users\\Administrator matched group list administrators at line 84
debug1: userauth-request for user Administrator service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: userauth_pubkey: test pkalg ssh-ed25519 pkblob ED25519 SHA256:2nXx9fR4uOi8KRult6QjtZEvaTHIqH7i4cAv7qg3gSA [preauth]
debug1: trying public key file __PROGRAMDATA__/ssh/administrators_authorized_keys
debug1: Could not open authorized keys '__PROGRAMDATA__/ssh/administrators_authorized_keys': No such file or directory
Failed publickey for Administrator from 192.168.179.152 port 61251 ssh2: ED25519 SHA256:2nXx9fR4uOi8KRult6QjtZEvaTHIqH7i4cAv7qg3gSA
Connection closed by authenticating user Administrator 192.168.179.152 port 61251 [preauth]
debug1: do_cleanup [preauth]
debug1: monitor_read_log: child log fd closed
debug1: do_cleanup
debug1: Killing privsep child 1996
Client Verbose Output:
schmitch@tokio:~$ ssh -vvvv ci02
OpenSSH_7.8p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/schmitch/.ssh/config
debug1: /Users/schmitch/.ssh/config line 34: Applying options for ci02
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.179.249 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.179.249 [192.168.179.249] port 22.
debug1: Connection established.
debug1: identity file /Users/schmitch/.ssh/windows type 3
debug1: identity file /Users/schmitch/.ssh/windows-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_7.7
debug1: match: OpenSSH_for_Windows_7.7 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.179.249:22 as 'Administrator'
debug3: hostkeys_foreach: reading file "/Users/schmitch/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/schmitch/.ssh/known_hosts:155
debug3: load_hostkeys: loaded 1 keys from 192.168.179.249
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:GKf1jbg/+ayrPx+MOCTeCSBgJze/9R7kVYdw4WcEMU8
debug3: hostkeys_foreach: reading file "/Users/schmitch/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/schmitch/.ssh/known_hosts:155
debug3: load_hostkeys: loaded 1 keys from 192.168.179.249
debug1: Host '192.168.179.249' is known and matches the ECDSA host key.
debug1: Found key in /Users/schmitch/.ssh/known_hosts:155
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug2: key: /Users/schmitch/.ssh/windows (0x7fc576c07060), explicit
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred:
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: ED25519 SHA256:2nXx9fR4uOi8KRult6QjtZEvaTHIqH7i4cAv7qg3gSA /Users/schmitch/.ssh/windows
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,password,keyboard-interactive).
My PubKey lies at C:\Users\Administrator.ssh\authorized_keys
Activity
schmitch commentedon Dec 14, 2018
i.e. copy the pubkey to C:\ProgramData\ssh\administrator_authorized_keys does not resolve the problem either
schmitch commentedon Dec 14, 2018
I found that the SSH Config contained something like:
however even when commenting it out, it still does not work.
btw.:
File ACL:
I'm on a headless windows. and completly out of ideas.
manojampalam commentedon Dec 14, 2018
Recommend uncommenting
Make sure C:\ProgramData\ssh\administrators_authorized_keys is a file (and not a folder containing key files)
And its administrators_authorized_keys and not administrator_authorized_keys
NoMoreFood commentedon Dec 15, 2018
Manoj Ampalam (@manojampalam) Schmitt Christian (@schmitch) The SID it's complaining about is from "NT SERVICE\sshd". Should this permission be necessary?
manojampalam commentedon Dec 15, 2018
Bryan Berns (@NoMoreFood) right. That permission should not be there. Schmitt Christian (@schmitch) where did you get your version of Repair-AuthorizedKeyPermission utility ?
schmitch commentedon Dec 16, 2018
Actually I did not download anything.
So it was either included in
pwsh-core-6.1.1.msior inWindows Server 2019manojampalam commentedon Dec 16, 2018
Yanbing (@bingbing8) any clue on how Repair-AuthorizedKeyPermission could automatically land up in a system ?
bingbing8 commentedon Dec 16, 2018
Manoj Ampalam (@manojampalam), the only thing I can guess is that older git version openssh was downloaded/installed from git or chocolaty before.
schmitch commentedon Dec 17, 2018
Actually I remembered:
Source: https://docs.microsoft.com/de-de/windows-server/administration/openssh/openssh_install_firstuse
bingbing8 commentedon Dec 17, 2018
Schmitt Christian (@schmitch) your above cmdlets install inbox openssh from windows update. The script module was never included as OpenSSH WindowsCapability. Not sure if your system is upgraded from previous windows version or not. The script module was needed on RS3 machine, but not needed on RS4 and RS5 any more. I guess you may downloaded the script module if followed openssh RS3 blog to fix key permission on RS3 machine.
schmitch commentedon Dec 17, 2018
than i have no idea, how it was installed.
Actually the system was not upgraded, I only installed PowerShell Core and DotNet Core SDK from Microsoft and other Build Related Tooling like Git, NodeJS etc.
(I also used Pwsh to run the repair script)
adilinden commentedon Dec 18, 2018
I am seeing the exactly same thing. Fresh install of Server 2019 Core with Hyper-V service.
Installed OpenSSH with:
Running
sshd -dgets me:Do note that I plugged my public key into
c:\Users\Administrator\.ssh\authorized_keys.adilinden commentedon Dec 18, 2018
I commented this out in
C:\ProgramData\ssh\sshd_configper instructions above:I then created
.ssh/authorized_keysusingnotepad. Finally I repaired permissions using:It is still failing, but its looking for a file now closer to what would be expected, debug from
sshd -d:adilinden commentedon Dec 18, 2018
Here is what works and doesn't. Note that this is on Server 2019 Core! I previously installed on Server 2016 Core (LTSB release) using the installer from GitHub. With it
Repair-AuthorizedKeyPermissionwas needed and things failed without.For Server 2019 Core:
Make sure we are in
$homeOpen
sshd_configusingnotepadEdit the
Matchstatement pertainingAdminstratorsCreate the
$home\.sshdirectoryCreate
authorized_keysand add public key(s)The file created will be
authorized_keys.txt, rename toauthorized_keysDo NOT repair permissions as this will thow an error
And the error:
Do NOT create
authorized_keysusingechoand subsequently editingAnd the error:
schmitch commentedon Dec 18, 2018
Actually I'm on Server Core aswell. However after "fixing" the sshd config and now correcting the permission (I.e. not using the powershell command everything works, with ed keys)
29 remaining items
AlexeyNovikov commentedon Feb 22, 2020
Solution
For sshd-config do the following changes:
Then open PowerShell as Admin and restart service:
Restart-Service sshdThen through GUI.
For
.sshfolder andauthorized_keysfile do the following:craigthackerx commentedon Feb 26, 2020
Worked for me. Cheers.
xakod commentedon Mar 28, 2020
Did all of this and it didnt work for me.
P.S. StrictModes no tried too
icosahedron commentedon Apr 11, 2020
Finally got it working for myself on Windows 10 Pro using half of one of the solutions above. The key was "make sure that it has the same permissions as ssh_host_ecdsa_key".
The same solution also recommended using
icacls .\administrators_authorized_keys /inheritance:r, but this simply reset the permissions to nil. After resetting the permissions to the same as the key file, it then worked.Daniel15 commentedon Apr 19, 2020
Thanks for this! I had set the permissions on
authorized_keysjust to my user and forgot to addSYSTEM. That fixed it for me!jyavenard commentedon Jun 28, 2020
After struggling for a couple of hours on this; I have to report that this made it all works immediately.
I just couldn't get over the error
12400 2020-06-28 13:55:52.151 Failed publickey for jyavenard from 192.168.160.1 port 51616 ssh2: RSA SHA256:Wsc+cG7fFMQi36MiurOKMpq3NFFAlqjlmoZ+vFVWjG8
12400 2020-06-28 13:55:52.158 debug1: userauth-request for user jyavenard service ssh-connection method keyboard-interactive [preauth]
12400 2020-06-28 13:55:52.158 debug1: attempt 2 failures 1 [preauth]
12400 2020-06-28 13:55:52.158 debug1: keyboard-interactive devs [preauth]
12400 2020-06-28 13:55:52.158 debug1: auth2_challenge: user=jyavenard devs= [preauth]
12400 2020-06-28 13:55:52.158 debug1: kbdint_alloc: devices '' [preauth]
12400 2020-06-28 13:55:53.186 Connection closed by authenticating user jyavenard 192.168.160.1 port 51616 [preauth]
jemiller0 commentedon Jun 28, 2020
I don't know why Microsoft even provides support for this, if basic functionality doesn't work out of the box. It's an embarrassment.
yao-bin commentedon Nov 20, 2020
Thanks for all who comment out this!
#Match Group administrators
#AuthorizedKeysFile PROGRAMDATA/ssh/administrators_authorized_keys
frippe75 commentedon Mar 24, 2021
Just as a side-note for those not wanting to comment out that clause and use the PROGRAMDATA/ssh/administrators_authorized_keys file as "intended".
I struggle with it for over an hour but realizing from how it works on linux that it silently discards the auth file with too open perms on the file.
I disabled inheritance for parent and removed the "read & execute" for authenticated users.
I think this is part of what Repair-AuthorizedKeyPermission.ps1 does but could not find it to have a look at the source.
daedalus-codes commentedon Dec 10, 2021
Thank you so much Sergei Nikalaichyk (@SNikalaichyk)! Those commands resolved an issue I was having getting OpenSSH to work on Windows Server 2016!! I didn't think about the permissions on that file, but now it makes sense come to think of it!
bagajjal commentedon Dec 10, 2021
fyi, starting from Win32-OpenSSH V8.6, there is no need to modify the administrators_authorized_keys ACLs.
All users can have read permissions to administrators_authorized_keys file as it contains the public key information for admin users.
pshri commentedon Dec 22, 2021
this worked for me
$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl
credit: https://superuser.com/questions/1445976/windows-ssh-server-refuses-key-based-authentication-from-client
TonalidadeHidrica commentedon Jul 28, 2022
Does Adi Linden (@adilinden) or anybody now why
echo-ing intoauthorized_keysdoesn't work?yTI0r commentedon Oct 12, 2024
I had a similar problem, nothing helped. I came across the advice to check that the authorized_keys file has a CRLF ending.
Actually, I noticed that the file created by notepad has UTF-16 BOM encoding as soon as I rearranged the encoding to UTF-8, everything worked!
Check that your authorized_keys has CRLF and UTF-8 encoding without BOM
mortbauer commentedon Mar 25, 2025
for me it was simply adjusting from
__PROGRAMDATA__/ssh/administrators_authorized_keysto__PROGRAMDATA__/ssh/administrators_authorized_keys.txtsince windows just had added that extension. no words