仅使用密码启用键盘交互身份验证

仅使用密码启用键盘交互身份验证

我有一个 ssh 客户端和一个 ssh 服务器。我想在服务器上启用键盘交互式身份验证,以便客户端只能使用此身份验证方法连接到服务器。在服务器上的 /etc/ssh/sshd_config 中,我有以下内容:

KbdInteractiveAuthentication yes
ChallengeResponseAuthentication yes
PubkeyAuthentication no
PasswordAuthentication no

当我尝试从客户端连接到服务器时,收到以下错误日志:

julian: ssh -vvv 192.168.1.102
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/client/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.1.102 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.1.102 [192.168.1.102] port 22.
debug1: Connection established.
debug1: identity file /Users/julian/.ssh/id_rsa type 0
debug1: identity file /Users/julian/.ssh/id_rsa-cert type -1
debug1: identity file /Users/julian/.ssh/id_dsa type -1
debug1: identity file /Users/julian/.ssh/id_dsa-cert type -1
debug1: identity file /Users/julian/.ssh/id_ecdsa type -1
debug1: identity file /Users/julian/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/julian/.ssh/id_ed25519 type -1
debug1: identity file /Users/julian/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/julian/.ssh/id_xmss type -1
debug1: identity file /Users/julian/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 1.99, remote software version OpenSSH_4.2
debug1: match: OpenSSH_4.2 pat OpenSSH_2*,OpenSSH_3*,OpenSSH_4* compat 0x00000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.1.102:22 as 'julian'
debug3: hostkeys_foreach: reading file "/Users/julian/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /Users/julian/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.1.102
debug3: hostkeys_foreach: reading file "/etc/ssh/ssh_known_hosts"
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
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],rsa-sha2-512,rsa-sha2-256,ssh-rsa,[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,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,[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: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,ssh-dss
debug2: ciphers ctos: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: ciphers stoc: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: MACs ctos: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: MACs stoc: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: diffie-hellman-group14-sha1
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug2: bits set: 1032/2048
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ssh-rsa SHA256:OHArjVwFi3PAeZ1dpjvNmy1G5U4AY8drwTA+Dh/j4po
debug3: hostkeys_foreach: reading file "/Users/julian/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /Users/julian/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 192.168.1.102
debug3: hostkeys_foreach: reading file "/etc/ssh/ssh_known_hosts"
debug1: Host '192.168.1.102' is known and matches the RSA host key.
debug1: Found key in /Users/julian/.ssh/known_hosts:1
debug2: bits set: 1019/2048
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 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 4294967296 blocks
debug1: Will attempt key: /Users/julian/.ssh/id_rsa RSA SHA256:tpvej9coBUmf7otCvtTtRVxkfWGL2VVvD6v5GUdluT4
debug1: Will attempt key: /Users/julian/.ssh/id_dsa 
debug1: Will attempt key: /Users/julian/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/julian/.ssh/id_ed25519 
debug1: Will attempt key: /Users/julian/.ssh/id_xmss 
debug2: pubkey_prepare: done
debug3: send packet: type 5
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: keyboard-interactive
debug3: start over, passed a different list keyboard-interactive
debug3: preferred publickey,keyboard-interactive,password
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: keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (keyboard-interactive).

我是否需要将密钥从客户端复制到服务器或者在 /etc/ssh/ssh_config 中进行任何更改?

答案1

我需要将密钥从客户端复制到服务器吗?

不。不仅不需要密钥;服务器配置为不允许公钥认证(PubkeyAuthentication no),因此复制任何密钥都是徒劳的。

或做出任何改变/etc/ssh/ssh_config

否。客户端上的这个文件对客户端很重要 ( ssh)。您的客户端计算机似乎配置正确。问题出在服务器上。服务器/etc/ssh/ssh_config上的文件(如果有)对 SSH 服务器无关紧要 ( sshd)。


从这一点开始,答案仅与服务器有关。

认为真的想要keyboard-interactive(作为反对password)然后你需要一些东西来处理它,例如聚丙烯酰胺

我在 Debian 10 上,我可以通过将UsePAM no(连同您提供的配置)放入我的 中来重现您的问题sshd_config。我可以通过更改为 来修复它UsePAM yes

我相信Slackware 使用 PAM也一样。请检查man 5 sshd_config服务器并确保UsePAM它受您的支持sshd

您发布的片段sshd_config未指定UsePAM。默认值为no,因此如果确实没有UsePAM,则就像UsePAM no。如果您愿意使用 PAM,则明确配置

UsePAM yes

笔记:

  • man 5 sshd_config表示“对于每个关键字,将使用第一个获得的值”。添加时,请确保文件中UsePAM yes没有更早的值。UsePAM no
  • 更改后sshd_config,重新加载 SSH 守护程序(sshd)。例如,在我的 Debian 10 中,正确的命令是systemctl reload ssh.service。重新加载服务不应影响sshd处理已建立连接的进程,因此远程执行此操作是安全的。
  • PAM 需要其自身的配置。您的服务器使用的 Linux 发行版很可能提供了合理的/etc/pam.d/sshd文件和附带文件。在这种情况下,PAM 应该可以立即使用,并且在UsePAM yes启动后不会出现任何意外。
  • 错误配置 PAM 或在错误配置的情况下开始使用它可能会导致您无法使用计算机。强烈建议保持提升的 shell ( sudo -i) 运行,直到您确认最终(即在所有更改之后)您可以独立重新登录并重新获得 root 访问权限。如果出现问题,请使用提升的 shell 进行恢复。

相关内容