Skip to content

PubKey Auth not working #1306

Closed
Closed

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

according to https://docs.microsoft.com/de-de/windows-server/administration/openssh/openssh_keymanagement

Activity

  1. schmitch commented on Dec 14, 2018

    @schmitch
    Author

    i.e. copy the pubkey to C:\ProgramData\ssh\administrator_authorized_keys does not resolve the problem either

  2. schmitch commented on Dec 14, 2018

    @schmitch
    Author

    I found that the SSH Config contained something like:

    Match Group administrators
           AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

    however even when commenting it out, it still does not work.

    s3544 2018-12-14 15:06:37.650 debug2: fd 3 setting O_NONBLOCK
    3544 2018-12-14 15:06:37.650 debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
    3544 2018-12-14 15:06:37.650 debug1: Bind to port 22 on ::.
    3544 2018-12-14 15:06:37.650 Server listening on :: port 22.
    3544 2018-12-14 15:06:37.650 debug2: fd 4 setting O_NONBLOCK
    3544 2018-12-14 15:06:37.650 debug1: Bind to port 22 on 0.0.0.0.
    3544 2018-12-14 15:06:37.650 Server listening on 0.0.0.0 port 22.
    3544 2018-12-14 15:06:40.670 debug3: fd 5 is not O_NONBLOCK
    3544 2018-12-14 15:06:40.672 debug3: spawning "C:\\Windows\\System32\\OpenSSH\\sshd.exe" "-R"
    3544 2018-12-14 15:06:40.675 debug3: send_rexec_state: entering fd = 8 config len 394
    3544 2018-12-14 15:06:40.675 debug3: ssh_msg_send: type 0
    3544 2018-12-14 15:06:40.675 debug3: send_rexec_state: done
    2664 2018-12-14 15:06:40.721 debug1: inetd sockets after dupping: 3, 3
    2664 2018-12-14 15:06:40.721 Connection from 192.168.179.152 port 65269 on 192.168.179.249 port 22
    2664 2018-12-14 15:06:40.721 debug1: Client protocol version 2.0; client software version OpenSSH_7.8
    2664 2018-12-14 15:06:40.721 debug1: match: OpenSSH_7.8 pat OpenSSH* compat 0x04000000
    2664 2018-12-14 15:06:40.721 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
    2664 2018-12-14 15:06:40.722 debug2: fd 3 setting O_NONBLOCK
    2664 2018-12-14 15:06:40.728 debug3: spawning "C:\\Windows\\System32\\OpenSSH\\sshd.exe" "-y"
    2664 2018-12-14 15:06:40.730 debug2: Network child is on pid 2700
    2664 2018-12-14 15:06:40.731 debug3: send_rexec_state: entering fd = 6 config len 394
    2664 2018-12-14 15:06:40.731 debug3: ssh_msg_send: type 0
    2664 2018-12-14 15:06:40.731 debug3: send_rexec_state: done
    2664 2018-12-14 15:06:40.731 debug3: ssh_msg_send: type 0
    2664 2018-12-14 15:06:40.731 debug3: ssh_msg_send: type 0
    2664 2018-12-14 15:06:40.731 debug3: preauth child monitor started
    2664 2018-12-14 15:06:40.756 debug3: list_hostkey_types: ssh-dss key not permitted by HostkeyAlgorithms [preauth]
    2664 2018-12-14 15:06:40.756 debug1: list_hostkey_types: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
    2664 2018-12-14 15:06:40.756 debug3: send packet: type 20 [preauth]
    2664 2018-12-14 15:06:40.756 debug1: SSH2_MSG_KEXINIT sent [preauth]
    2664 2018-12-14 15:06:40.756 debug3: receive packet: type 20 [preauth]
    2664 2018-12-14 15:06:40.756 debug1: SSH2_MSG_KEXINIT received [preauth]
    2664 2018-12-14 15:06:40.756 debug2: local server KEXINIT proposal [preauth]
    2664 2018-12-14 15:06:40.756 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 [preauth]
    2664 2018-12-14 15:06:40.756 debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
    2664 2018-12-14 15:06:40.756 debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] [preauth]
    2664 2018-12-14 15:06:40.756 debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] [preauth]
    2664 2018-12-14 15:06:40.756 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 [preauth]
    2664 2018-12-14 15:06:40.756 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 [preauth]
    2664 2018-12-14 15:06:40.756 debug2: compression ctos: none [preauth]
    2664 2018-12-14 15:06:40.756 debug2: compression stoc: none [preauth]
    2664 2018-12-14 15:06:40.756 debug2: languages ctos:  [preauth]
    2664 2018-12-14 15:06:40.756 debug2: languages stoc:  [preauth]
    2664 2018-12-14 15:06:40.756 debug2: first_kex_follows 0  [preauth]
    2664 2018-12-14 15:06:40.756 debug2: reserved 0  [preauth]
    2664 2018-12-14 15:06:40.756 debug2: peer client KEXINIT proposal [preauth]
    2664 2018-12-14 15:06:40.756 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 [preauth]
    2664 2018-12-14 15:06:40.756 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 [preauth]
    2664 2018-12-14 15:06:40.756 debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] [preauth]
    2664 2018-12-14 15:06:40.757 debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] [preauth]
    2664 2018-12-14 15:06:40.757 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 [preauth]
    2664 2018-12-14 15:06:40.757 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 [preauth]
    2664 2018-12-14 15:06:40.757 debug2: compression ctos: none,[email protected],zlib [preauth]
    2664 2018-12-14 15:06:40.757 debug2: compression stoc: none,[email protected],zlib [preauth]
    2664 2018-12-14 15:06:40.757 debug2: languages ctos:  [preauth]
    2664 2018-12-14 15:06:40.757 debug2: languages stoc:  [preauth]
    2664 2018-12-14 15:06:40.757 debug2: first_kex_follows 0  [preauth]
    2664 2018-12-14 15:06:40.757 debug2: reserved 0  [preauth]
    2664 2018-12-14 15:06:40.757 debug1: kex: algorithm: curve25519-sha256 [preauth]
    2664 2018-12-14 15:06:40.757 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth]
    2664 2018-12-14 15:06:40.757 debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth]
    2664 2018-12-14 15:06:40.757 debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth]
    2664 2018-12-14 15:06:40.757 debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
    2664 2018-12-14 15:06:40.760 debug3: receive packet: type 30 [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_key_sign entering [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_request_send entering: type 6 [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_key_sign: waiting for MONITOR_ANS_SIGN [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_request_receive_expect entering: type 7 [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_request_receive entering [preauth]
    2664 2018-12-14 15:06:40.768 debug3: mm_request_receive entering
    2664 2018-12-14 15:06:40.768 debug3: monitor_read: checking request 6
    2664 2018-12-14 15:06:40.769 debug3: mm_answer_sign
    2664 2018-12-14 15:06:40.770 debug3: mm_answer_sign: hostkey proof signature 000001683069E4C0(101)
    2664 2018-12-14 15:06:40.770 debug3: mm_request_send entering: type 7
    2664 2018-12-14 15:06:40.770 debug2: monitor_read: 6 used once, disabling now
    2664 2018-12-14 15:06:40.770 debug3: send packet: type 31 [preauth]
    2664 2018-12-14 15:06:40.770 debug3: send packet: type 21 [preauth]
    2664 2018-12-14 15:06:40.770 debug2: set_newkeys: mode 1 [preauth]
    2664 2018-12-14 15:06:40.770 debug1: rekey after 134217728 blocks [preauth]
    2664 2018-12-14 15:06:40.770 debug1: SSH2_MSG_NEWKEYS sent [preauth]
    2664 2018-12-14 15:06:40.770 debug1: expecting SSH2_MSG_NEWKEYS [preauth]
    2664 2018-12-14 15:06:40.770 debug3: send packet: type 7 [preauth]
    2664 2018-12-14 15:06:40.778 debug3: receive packet: type 21 [preauth]
    2664 2018-12-14 15:06:40.778 debug1: SSH2_MSG_NEWKEYS received [preauth]
    2664 2018-12-14 15:06:40.778 debug2: set_newkeys: mode 0 [preauth]
    2664 2018-12-14 15:06:40.778 debug1: rekey after 134217728 blocks [preauth]
    2664 2018-12-14 15:06:40.778 debug1: KEX done [preauth]
    2664 2018-12-14 15:06:40.789 debug3: receive packet: type 5 [preauth]
    2664 2018-12-14 15:06:40.789 debug3: send packet: type 6 [preauth]
    2664 2018-12-14 15:06:40.789 debug3: receive packet: type 50 [preauth]
    2664 2018-12-14 15:06:40.789 debug1: userauth-request for user Administrator service ssh-connection method none [preauth]
    2664 2018-12-14 15:06:40.789 debug1: attempt 0 failures 0 [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_getpwnamallow entering [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_request_send entering: type 8 [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_getpwnamallow: waiting for MONITOR_ANS_PWNAM [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_request_receive_expect entering: type 9 [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_request_receive entering [preauth]
    2664 2018-12-14 15:06:40.789 debug3: mm_request_receive entering
    2664 2018-12-14 15:06:40.789 debug3: monitor_read: checking request 8
    2664 2018-12-14 15:06:40.789 debug3: mm_answer_pwnamallow
    2664 2018-12-14 15:06:40.790 debug2: parse_server_config: config reprocess config len 394
    2664 2018-12-14 15:06:40.790 debug3: mm_answer_pwnamallow: sending MONITOR_ANS_PWNAM: 1
    2664 2018-12-14 15:06:40.790 debug3: mm_request_send entering: type 9
    2664 2018-12-14 15:06:40.791 debug2: monitor_read: 8 used once, disabling now
    2664 2018-12-14 15:06:40.791 debug2: input_userauth_request: setting up authctxt for Administrator [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_inform_authserv entering [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_send entering: type 4 [preauth]
    2664 2018-12-14 15:06:40.791 debug2: input_userauth_request: try method none [preauth]
    2664 2018-12-14 15:06:40.791 debug3: userauth_finish: failure partial=0 next methods="publickey,keyboard-interactive" [preauth]
    2664 2018-12-14 15:06:40.791 debug3: send packet: type 51 [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_receive entering
    2664 2018-12-14 15:06:40.791 debug3: monitor_read: checking request 4
    2664 2018-12-14 15:06:40.791 debug3: mm_answer_authserv: service=ssh-connection, style=
    2664 2018-12-14 15:06:40.791 debug2: monitor_read: 4 used once, disabling now
    2664 2018-12-14 15:06:40.791 debug3: receive packet: type 50 [preauth]
    2664 2018-12-14 15:06:40.791 debug1: userauth-request for user Administrator service ssh-connection method publickey [preauth]
    2664 2018-12-14 15:06:40.791 debug1: attempt 1 failures 0 [preauth]
    2664 2018-12-14 15:06:40.791 debug2: input_userauth_request: try method publickey [preauth]
    2664 2018-12-14 15:06:40.791 debug1: userauth_pubkey: test pkalg ssh-ed25519 pkblob ED25519 SHA256:2nXx9fR4uOi8KRult6QjtZEvaTHIqH7i4cAv7qg3gSA [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_key_allowed entering [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_send entering: type 22 [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_key_allowed: waiting for MONITOR_ANS_KEYALLOWED [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_receive_expect entering: type 23 [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_receive entering [preauth]
    2664 2018-12-14 15:06:40.791 debug3: mm_request_receive entering
    2664 2018-12-14 15:06:40.791 debug3: monitor_read: checking request 22
    2664 2018-12-14 15:06:40.791 debug3: mm_answer_keyallowed entering
    2664 2018-12-14 15:06:40.791 debug3: mm_answer_keyallowed: key_from_blob: 000001683069E300
    2664 2018-12-14 15:06:40.791 debug1: trying public key file C:\\Users\\Administrator\\.ssh/authorized_keys
    2664 2018-12-14 15:06:40.792 debug3: Bad permissions. Try removing permissions for user: S-1-5-80-3847866527-469524349-687026318-516638107-1125189541 on file C:/Users/Administrator/.ssh/authorized_keys.
    2664 2018-12-14 15:06:40.792 Authentication refused.
    2664 2018-12-14 15:06:40.792 debug3: mm_answer_keyallowed: publickey authentication test: ED25519 key is not allowed
    2664 2018-12-14 15:06:40.792 Failed publickey for Administrator from 192.168.179.152 port 65269 ssh2: ED25519 SHA256:2nXx9fR4uOi8KRult6QjtZEvaTHIqH7i4cAv7qg3gSA
    2664 2018-12-14 15:06:40.792 debug3: mm_request_send entering: type 23
    2664 2018-12-14 15:06:40.792 debug2: userauth_pubkey: authenticated 0 pkalg ssh-ed25519 [preauth]
    2664 2018-12-14 15:06:40.792 debug3: userauth_finish: failure partial=0 next methods="publickey,keyboard-interactive" [preauth]
    2664 2018-12-14 15:06:40.792 debug3: send packet: type 51 [preauth]
    2664 2018-12-14 15:06:40.794 Connection closed by authenticating user Administrator 192.168.179.152 port 65269 [preauth]
    2664 2018-12-14 15:06:40.794 debug1: do_cleanup [preauth]
    2664 2018-12-14 15:06:40.795 debug1: monitor_read_log: child log fd closed
    2664 2018-12-14 15:06:40.795 debug3: mm_request_receive entering
    2664 2018-12-14 15:06:40.795 debug1: do_cleanup
    2664 2018-12-14 15:06:40.795 debug1: Killing privsep child 2700
    

    btw.:

    PS C:\ProgramData\ssh> Repair-AuthorizedKeyPermission C:\Users\Administrator\.ssh\authorized_keys
      [*] C:\Users\Administrator\.ssh\authorized_keys
          looks good
    

    File ACL:

    PS C:\ProgramData\ssh> Get-Acl C:\Users\Administrator\.ssh\authorized_keys|Format-List
    
    
    Path   : Microsoft.PowerShell.Core\FileSystem::C:\Users\Administrator\.ssh\authorized_keys
    Owner  : BUILTIN\Administrators
    Group  : WIN-JC8T67AORH2\None
    Access : NT SERVICE\sshd Allow  Read, Synchronize
             NT AUTHORITY\SYSTEM Allow  FullControl
             BUILTIN\Administrators Allow  FullControl
             WIN-JC8T67AORH2\Administrator Allow  FullControl
    Audit  :
    Sddl   : O:BAG:S-1-5-21-2330858761-2518894999-591638271-513D:AI(A;;FR;;;S-1-5-80-3847866527-469524349-687026318-516638107-1125189541)(A;ID;FA;;;SY)
             (A;ID;FA;;;BA)(A;ID;FA;;;LA)
    

    I'm on a headless windows. and completly out of ideas.

  3. manojampalam commented on Dec 14, 2018

    @manojampalam
    Contributor

    Recommend uncommenting

    Match Group administrators
           AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

    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

    For administrator C:\ProgramData\ssh\administrator_authorized_keys
    
  4. NoMoreFood commented on Dec 15, 2018

    @NoMoreFood

    Manoj Ampalam (@manojampalam) Schmitt Christian (@schmitch) The SID it's complaining about is from "NT SERVICE\sshd". Should this permission be necessary?

  5. manojampalam commented on Dec 15, 2018

    @manojampalam
    Contributor

    Bryan Berns (@NoMoreFood) right. That permission should not be there. Schmitt Christian (@schmitch) where did you get your version of Repair-AuthorizedKeyPermission utility ?

  6. schmitch commented on Dec 16, 2018

    @schmitch
    Author

    Actually I did not download anything.
    So it was either included in pwsh-core-6.1.1.msi or in Windows Server 2019

  7. manojampalam commented on Dec 16, 2018

    @manojampalam
    Contributor

    Yanbing (@bingbing8) any clue on how Repair-AuthorizedKeyPermission could automatically land up in a system ?

  8. bingbing8 commented on Dec 16, 2018

    @bingbing8
    Contributor

    Manoj Ampalam (@manojampalam), the only thing I can guess is that older git version openssh was downloaded/installed from git or chocolaty before.

  9. schmitch commented on Dec 17, 2018

    @schmitch
    Author

    Actually I remembered:

    Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
    Name  : OpenSSH.Client~~~~0.0.1.0
    State : Installed
    
    Name  : OpenSSH.Server~~~~0.0.1.0
    State : Installed
    
    # Install the OpenSSH Client
    Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
    
    # Install the OpenSSH Server
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
    

    Source: https://docs.microsoft.com/de-de/windows-server/administration/openssh/openssh_install_firstuse

  10. bingbing8 commented on Dec 17, 2018

    @bingbing8
    Contributor

    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.

  11. schmitch commented on Dec 17, 2018

    @schmitch
    Author

    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)

  12. adilinden commented on Dec 18, 2018

    @adilinden

    I am seeing the exactly same thing. Fresh install of Server 2019 Core with Hyper-V service.

    Installed OpenSSH with:

    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
    

    Running sshd -d gets me:

    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
    

    Do note that I plugged my public key into c:\Users\Administrator\.ssh\authorized_keys.

  13. adilinden commented on Dec 18, 2018

    @adilinden

    I commented this out in C:\ProgramData\ssh\sshd_config per instructions above:

    #Match Group administrators
    #       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

    I then created .ssh/authorized_keys using notepad. Finally I repaired permissions using:

    Repair-AuthorizedKeyPermission -FilePath $home\.ssh\authorized_keys
    

    It is still failing, but its looking for a file now closer to what would be expected, debug from sshd -d:

    debug1: trying public key file C:\\Users\\Administrator\\.ssh/authorized_keys
    Authentication refused.
    Failed publickey for Administrator from 192.168.123.107 port 62628 ssh2: ED25519 SHA256:XUCnOR
    
  14. adilinden commented on Dec 18, 2018

    @adilinden

    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-AuthorizedKeyPermission was needed and things failed without.

    For Server 2019 Core:

    Make sure we are in $home

    cd $home
    

    Open sshd_config using notepad

    notepad C:\ProgramData\ssh\sshd_config`
    

    Edit the Match statement pertaining Adminstrators

    #Match Group administrators
    #       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

    Create the $home\.ssh directory

    mkdir .ssh
    

    Create authorized_keys and add public key(s)

    notepad .ssh\authorized_keys
    

    The file created will be authorized_keys.txt, rename to authorized_keys

    mv .\.ssh\authorized_keys.txt .\.ssh\authorized_keys
    

    Do NOT repair permissions as this will thow an error

    Repair-AuthorizedKeyPermission -FilePath $home\.ssh\authorized_keys
    

    And the error:

    debug1: trying public key file C:\\Users\\Administrator\\.ssh/authorized_keys
    Authentication refused.
    

    Do NOT create authorized_keys using echo and subsequently editing

    echo test > .ssh\authorized_keys
    echo $null > .ssh\authorized_keys
    

    And the error:

    debug1: read_keyfile_line: C:\\Users\\Administrator\\.ssh/authorized_keys line 1 exceeds size limit
    
  15. schmitch commented on Dec 18, 2018

    @schmitch
    Author

    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)

  16. 29 remaining items

  17. AlexeyNovikov commented on Feb 22, 2020

    @AlexeyNovikov

    Solution

    For sshd-config do the following changes:

    1. Comment this one:
    #Match Group administrators
    #      AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    
    1. Uncomment these two:
    PubkeyAuthentication yes
    PasswordAuthentication no
    

    Then open PowerShell as Admin and restart service:
    Restart-Service sshd

    Then through GUI.
    For .ssh folder and authorized_keys file do the following:

    1. Properties -> Security -> Advanced -> Disable inheritance -> Convert inherited permissions into explicit permissions on this object.
    2. Then delete all users(groups) except:
    • System
    • Administrators
    • current user
  18. craigthackerx commented on Feb 26, 2020

    @craigthackerx

    Solution

    For sshd-config do the following changes:

    1. Comment this one:
    #Match Group administrators
    #      AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    
    1. Uncomment these two:
    PubkeyAuthentication yes
    PasswordAuthentication no
    

    Then open PowerShell as Admin and restart service:
    Restart-Service sshd

    Then through GUI.
    For .ssh folder and authorized_keys file do the following:

    1. Properties -> Security -> Advanced -> Disable inheritance -> Convert inherited permissions into explicit permissions on this object.
    2. Then delete all users(groups) except:
    • System
    • Administrators
    • current user

    Worked for me. Cheers.

  19. xakod commented on Mar 28, 2020

    @xakod

    Solution

    For sshd-config do the following changes:

    1. Comment this one:
    
    #Match Group administrators
    #      AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    
    1. Uncomment these two:
    
    PubkeyAuthentication yes
    PasswordAuthentication no
    

    Then open PowerShell as Admin and restart service:
    Restart-Service sshd

    Then through GUI.
    For .ssh folder and authorized_keys file do the following:

    1. Properties -> Security -> Advanced -> Disable inheritance -> Convert inherited permissions into explicit permissions on this object.
    
    2. Then delete all users(groups) except:
    
    
    * System
    
    * Administrators
    
    * current user
    

    Did all of this and it didnt work for me.
    P.S. StrictModes no tried too

  20. icosahedron commented on Apr 11, 2020

    @icosahedron

    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.

  21. Daniel15 commented on Apr 19, 2020

    @Daniel15

    Solution

    For sshd-config do the following changes:

    1. Comment this one:
    
    #Match Group administrators
    #      AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    
    1. Uncomment these two:
    
    PubkeyAuthentication yes
    PasswordAuthentication no
    

    Then open PowerShell as Admin and restart service:
    Restart-Service sshd

    Then through GUI.
    For .ssh folder and authorized_keys file do the following:

    1. Properties -> Security -> Advanced -> Disable inheritance -> Convert inherited permissions into explicit permissions on this object.
    
    2. Then delete all users(groups) except:
    
    
    * System
    
    * Administrators
    
    * current user
    

    Thanks for this! I had set the permissions on authorized_keys just to my user and forgot to add SYSTEM. That fixed it for me!

  22. jyavenard commented on Jun 28, 2020

    @jyavenard

    First remove the windows capability:

    Remove-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0"
    Remove-WindowsCapability -Online -Name "OpenSSH.Server~~~~0.0.1.0"
    

    Then install openssh latest version with chocolatey:

    choco install openssh -params '"/SSHServerFeature /KeyBasedAuthenticationFeature /SSHAgentFeature"'
    

    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]

  23. jemiller0 commented on Jun 28, 2020

    @jemiller0

    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.

  24. yao-bin commented on Nov 20, 2020

    @yao-bin

    Thanks for all who comment out this!

    #Match Group administrators
    #AuthorizedKeysFile PROGRAMDATA/ssh/administrators_authorized_keys

  25. frippe75 commented on Mar 24, 2021

    @frippe75

    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.

  26. daedalus-codes commented on Dec 10, 2021

    @daedalus-codes

    Hi! I was able to get the C:\ProgramData\ssh\administrators_authorized_keys file to work.

    You should set the ACL for the administrators_authorized_keys file to match the ACL of the ssh_host_dsa_key file in the same C:\ProgramData\ssh directory.

    icacls C:\ProgramData\ssh\administrators_authorized_keys /remove "NT AUTHORITY\Authenticated Users"
    icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
    

    Then restart SSH services:

    Restart-Service -Name sshd, ssh-agent -Force

    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!

  27. bagajjal commented on Dec 10, 2021

    @bagajjal
    Collaborator

    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.

  28. pshri commented on Dec 22, 2021

    @pshri

    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

  29. TonalidadeHidrica commented on Jul 28, 2022

    @TonalidadeHidrica

    Does Adi Linden (@adilinden) or anybody now why echo-ing into authorized_keys doesn't work?

  30. yTI0r commented on Oct 12, 2024

    @yTI0r

    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

  31. mortbauer commented on Mar 25, 2025

    @mortbauer

    for me it was simply adjusting from __PROGRAMDATA__/ssh/administrators_authorized_keys to __PROGRAMDATA__/ssh/administrators_authorized_keys.txt since windows just had added that extension. no words

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions