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 的各種數據包類型的參考,甚至在RFC

答案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

該檔案在我們的系統上不存在,但它也不應該存在,因為我們是bash從 IBM 的 YUM 儲存庫安裝的。那是bashif使用5733OPS獲取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;

相關內容