SSH 要求在未設定密碼的情況下提供公鑰密碼

SSH 要求在未設定密碼的情況下提供公鑰密碼

我在伺服器上使用公鑰身份驗證已經有一段時間了,但我在嘗試連接的新「客戶端」上遇到了問題github。我已閱讀許多線程來驗證我的權限設定是否正確並已為 github 產生了新金鑰。我面臨的問題是 ssh 要求我輸入密碼,即使我沒有設定密碼。我甚至重新製作了密鑰,以 100% 確定我沒有輸入密碼。

ssh-vvv給出以下相關輸出:

debug1: Offering public key: /home/me/.ssh/github.pub
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1495
debug1: Remote: Forced command: gerve mygithubusername c3:71:db:34:98:30:6d:c2:ca:d9:51:a8:c6:1b:fc:f7
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp c3:71:db:34:98:30:6d:c2:ca:d9:51:a8:c6:1b:fc:f7
debug3: sign_and_send_pubkey
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/me/.ssh/github.pub': 

我一直在尋找為什麼它告訴我PEM_read_PrivateKey失敗了,但我找不到解決方案。

我不使用代理商或任何東西。我配置 ~/.ssh/config 檔案類似於以下內容:

Host github
Host github.com
Hostname github.com
User git
PubkeyAuthentication yes
IdentityFile /home/me/.ssh/github.pub

提前致謝。

答案1

當您使用IdentityFile您的選項時~/.ssh/config,您指向私人,不是公眾, 鑰匙。

man ssh_config

身分檔案
指定從中讀取使用者的 DSA、ECDSA 或 DSA 驗證身分的檔案。對於協定版本 1,預設值為 ~/.ssh/identity;對於協定版本 2,預設值為 ~/.ssh/id_dsa、~/.ssh/id_ecdsa 和 ~/.ssh/id_rsa。

因此,您的~/.ssh/config條目應如下所示:

Host github.com
Hostname github.com
User git
PubkeyAuthentication yes
IdentityFile /home/me/.ssh/github

答案2

我們遇到了這個問題,這是一個剪切和粘貼錯誤。%密鑰檔案末尾添加了一個符號(因此最後一行是-----END RSA PRIVATE KEY-----%)。沒有錯誤或調試資訊或任何其他資訊表明密鑰長度錯誤或格式錯誤,但 ssh 要求輸入密碼。

答案3

就我而言,問題是我的 SSH 用戶端不支援 ED25519 金鑰。解決方案是建立 RSA 金鑰並使用它。

此問題發生於OpenSSH < 6.5(運行ssh -V)和油灰 < 0.68

這可以從以下輸出看出ssh -vvv

debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,[email protected]
debug2: kex_parse_kexinit: hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96
debug2: kex_parse_kexinit: hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]

第一個區塊描述客戶端支援什麼,第二個區塊描述伺服器支援什麼。正如你所看到的,上半部沒有提到“curve25519”,表明客戶端不支援它。

答案4

在我的團隊中,當發生這種情況時,本地任何事情都不是問題。使用者的 ssh 金鑰和/或存取權限尚未在他們連接的伺服器(在我們的範例中為託管平台)上正確配置。由於某種原因,這會觸發提示輸入不存在的 ssh 金鑰。

相關內容