Windows 服务器上的 Openssh:ssh 到 localhost 要求输入密码

Windows 服务器上的 Openssh:ssh 到 localhost 要求输入密码

因此,我已经在 Windows Server 2016 上安装并配置了 Openssh,现在我正在尝试设置与本地主机的无密码连接,因为脚本需要它。

尽管将公钥复制到 authorized_keys 文件,但无需密码登录 localhost 仍无法正常工作。以下是日志。

C:\Users\AWSAmazonCntAppIDDEV>ssh -vvv AWSAmazonCntAppIDDEV@localhost
OpenSSH_8.3p1, OpenSSL 1.1.1g  21 Apr 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "localhost" port 22
debug2: ssh_connect_direct
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_rsa type 0
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_dsa type 0
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_xmss type -1
debug1: identity file /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.6
debug1: match: OpenSSH_for_Windows_8.6 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to localhost:22 as 'AWSAmazonCntAppIDDEV'
debug3: hostkeys_foreach: reading file "/c/Users/AWSAmazonCntAppIDDEV/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /c/Users/AWSAmazonCntAppIDDEV/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
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: peer server KEXINIT proposal
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:SHXUWbmljiMgQld335wbngd7Ooyvp/G8Q//6NqShdxE
debug3: hostkeys_foreach: reading file "/c/Users/AWSAmazonCntAppIDDEV/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /c/Users/AWSAmazonCntAppIDDEV/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/AWSAmazonCntAppIDDEV/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out 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 in after 134217728 blocks
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_rsa RSA SHA256:zpgLGNnEaLGE58i9zmvxJzgrI0mkxpKr6VyHH0xDvgw
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_dsa RSA SHA256:zpgLGNnEaLGE58i9zmvxJzgrI0mkxpKr6VyHH0xDvgw
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa_sk
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519_sk
debug1: Will attempt key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_xmss
debug2: pubkey_prepare: done
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,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
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,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_rsa RSA SHA256:zpgLGNnEaLGE58i9zmvxJzgrI0mkxpKr6VyHH0xDvgw
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
debug1: Offering public key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_dsa RSA SHA256:zpgLGNnEaLGE58i9zmvxJzgrI0mkxpKr6VyHH0xDvgw
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
debug1: Trying private key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa
debug3: no such identity: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa_sk
debug3: no such identity: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519
debug3: no such identity: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519_sk
debug3: no such identity: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_xmss
debug3: no such identity: /c/Users/AWSAmazonCntAppIDDEV/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug3: send packet: type 50
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
AWSAmazonCntAppIDDEV@localhost's password:

以下是我迄今为止尝试过的:

  • 注释掉 sshd_config 文件中以下几行
#Match Group administrators
#       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
  • PubkeyAuthentication 和 PasswordAuthentication 设置为 yes
 PubkeyAuthentication yes
 PasswordAuthentication yes

  • %user_home/.ssh 文件夹仅由系统和 my_ID(我的帐户)拥有。此外,继承也被禁用。这是为了确保 .ssh 文件夹具有等效的 700 权限,而 authorized_keys 文件具有 0600 权限。
  • 尝试重新创建密钥。

我仍然认为这是一个权限问题,因为当我在 Windows 中运行 ls -lart 时,它仍然显示权限为 644,如您所见。我试图将其更改为 600,但它不允许我这样做,因为它是 Windows。我很感激任何帮助。

C:\Users\AWSAmazonCntAppIDDEV\.ssh>ls -alrt
total 26
-rw-r--r-- 1 AWSAmazonCntAppIDDEV 1049089  589 Jul 15 14:01 id_rsa.pub
-rw-r--r-- 1 AWSAmazonCntAppIDDEV 1049089 2635 Jul 15 14:01 id_dsa
-rw-r--r-- 1 AWSAmazonCntAppIDDEV 1049089  588 Jul 15 14:02 authorized_keys
-rw-r--r-- 1 AWSAmazonCntAppIDDEV 1049089  171 Jul 15 14:05 known_hosts
drwxr-xr-x 1 AWSAmazonCntAppIDDEV 1049089    0 Jul 15 14:23 ..
drwxr-xr-x 1 AWSAmazonCntAppIDDEV 1049089    0 Jul 15 14:39 .

答案1

我卸载了 openssh,然后按照下面文档中提到的步骤重新安装。然后我就可以不用密码 ssh 到 localhost 了。

https://adamtheautomator.com/openssh-windows/

我跳过了证书认证链接中的部分,因为它与我的情况无关。

相关内容