SSH - 密码提示后基于密钥的身份验证失败

SSH - 密码提示后基于密钥的身份验证失败

当我使用基于密钥的身份验证并在密钥上关联密码时,以特定用户身份连接到服务器时遇到 SSH 错误。

这是在 IBM i 系统上。

我已将公钥添加到~/.ssh/authorized_keys服务器上该用户的文件中。他们的主目录以及目录~/.ssh/.ssh/authorized_keys文件对除所有者之外的任何人都没有写入权限。并且所有者已正确设置。有趣的是,如果我将相同的密钥移给另一个用户,密码将被接受。或者,如果我对用户 JAV 使用适用于其他用户的密钥对,我会得到相同的行为。因此,似乎服务器端的用户“JAV”存在一些问题,这是问题的根源。

奇怪的是,直到提示用户输入密码后,连接尝试才会失败。我能找到的所有信息都表明文件权限不准确,但我已将有效用户和无效用户之间的相关文件权限进行了匹配 - 并且它们完全相同。

JAV 是不起作用的用户。

/home/JAV和 的权限.ssh

bash-4.4$ pwd
/home/JAV
bash-4.4$ ls -la
total 300
drwx--S---   4 jav  0  24576 Oct 17 14:41 .
drwxrwsrwx 102 qsys 0  61440 Oct 17 15:21 ..
-rw-------   1 jav  0   2108 Oct 17 15:32 .bash_history
-rwx------   1 jav  0    204 Dec 18  2018 .bash_profile
-rwx------   1 jav  0     83 May  5  2017 .bashrc
drwxrwsrwx   3 jav  0   8192 May  9  2018 .eclipse
-rwx------   1 jav  0    559 Oct 17 16:45 .profile
-rw-------   1 jav  0    546 Oct 22  2018 .sh_history
drwx--S---   2 jav  0   8192 Oct 17 16:55 .ssh
bash-4.4$

尝试失败时输出非常详细的信息:

┌─[dl @ PC-1802]─[~/.ssh]─[575]
└─[$]› ssh -vvv JAVDL
OpenSSH_7.6p1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /c/Users/dl/.ssh/config
debug1: /c/Users/dl/.ssh/config line 55: Applying options for JAVDL
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "mydomain.local" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to mydomain.local [10.0.15.8] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/dl/.ssh/dl_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/dl/.ssh/dl_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.0
debug1: match: OpenSSH_8.0 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to mydomain.local:22 as 'jav'
debug3: hostkeys_foreach: reading file "/c/Users/dl/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /c/Users/dl/.ssh/known_hosts:1
debug3: record_hostkey: found key type RSA in file /c/Users/dl/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 2 keys from mydomain.local
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,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-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256,ssh-rsa,[email protected],ssh-ed25519
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
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: rsa-sha2-512,rsa-sha2-256,ssh-rsa,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,[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: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] 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:7Z25Q7mljYwlFOHC0SPGiCraFwbW/Pm4ecbfLL/w29E
debug3: hostkeys_foreach: reading file "/c/Users/dl/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /c/Users/dl/.ssh/known_hosts:1
debug3: record_hostkey: found key type RSA in file /c/Users/dl/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 2 keys from mydomain.local
debug3: hostkeys_foreach: reading file "/c/Users/dl/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /c/Users/dl/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 10.0.15.8
debug1: Host 'mydomain.local' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/dl/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey 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 after 4294967296 blocks
debug2: key: /c/Users/dl/.ssh/dl_rsa (0x0), 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,keyboard-interactive
debug3: start over, passed a different list publickey,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: Trying private key: /c/Users/dl/.ssh/dl_rsa


Enter passphrase for key '/c/Users/dl/.ssh/dl_rsa':


debug3: sign_and_send_pubkey: RSA SHA256:YVE0kS2H4/n5umGS4Gv0J+aWFljM4pauXG8KEe1+2YI
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,keyboard-interactive
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,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 (publickey,keyboard-interactive).

┌─[dl @ PC-1802]─[~/.ssh]─[576]
└─[$]›

许可~/.ssh/authorized_keys

bash-4.4$ pwd
/home/JAV/.ssh
bash-4.4$ ls -la
total 40
drwx--S--- 2 jav 0  8192 Oct 17 17:22 .
drwx--S--- 4 jav 0 24576 Oct 17 14:41 ..
-rwx------ 1 jav 0  1303 Oct 17 16:55 authorized_keys
bash-4.4$

我正在使用的 SSH 主机别名定义:

Host JAVDL
  HostName mydomain.local
  Port 22
  User jav
  IdentityFile ~/.ssh/dl_rsa

我还想指出,在我们的sshd_config文件中我们有明确的拒绝/允许指令。

部分sshd_config

DenyUsers root
AllowUsers dl jav

我找不到任何关于什么debug3: receive packet: type 51意思的提示。也许我的谷歌搜索能力不够,但我甚至找不到关于 openssh 的各种数据包类型的参考,甚至在请求函数

答案1

我找不到任何关于 debug3:receive packet:type 51 含义的提示。也许我的谷歌搜索能力不够,但我甚至找不到关于 openssh 各种数据包类型的参考,甚至在 RFC 中也没有。

数据包 51 表示 SSH_MSG_USERAUTH_FAILURE,如 RFC 4252 中所述:

https://www.rfc-editor.org/rfc/rfc4252#section-6

这意味着密钥由于某种原因被拒绝,该原因记录在服务器日志中(或者如果您增加服务器上的日志级别也会记录)。

答案2

首先,IBM i 上默认不启用 SSHD 日志记录。要进行设置,请按照以下文章进行操作:https://www.ibm.com/support/pages/sshd-can-use-unix-syslog-facilities-logging

然后,在将服务器上的日志级别增加到以下级别后,DEBUG3我发现了以下条目:

sshd[262719]: User jav not allowed because shell /QOpenSys/QIBM/ProdData/OPS/tools/bin/bash does not exist

该文件在我们的系统中不存在,但它也不应该存在,因为我们是从 IBM 的 YUM 存储库安装的。这是使用 5733OPS 获取 bashbash的位置,现在已被视为过时。bash

经过一番搜索后,我确定有一个 UDF 可以PASE为给定用户设置默认 shell。 QSYS2.SET_PASE_SHELL_INFO()如下所述:http://archive.ibmsystemsmag.com/blogs/open-your-i/august-2017/tech-tip-be-like-a-turtle/。查询用户“jav”的值并将其与适用该功能的用户进行比较后,我发现用户“jav”的值设置为 ,/QOpenSys/QIBM/ProdData/OPS/tools/bin/bash而其他所有用户的值均为NULL。果然,将值设置为 后NULL,一切都按预期运行。

我知道你可以用这种方法设置默认 shell,而不用启动文件,比如.profile。但我们只使用启动文件。

查询所有用户的值:

SELECT AUTHORIZATION_NAME, PASE_SHELL_PATH
FROM QSYS2.USER_INFO;

相关内容