使用 rsa 金鑰透過 ssh 隧道登入仍給予密碼提示

使用 rsa 金鑰透過 ssh 隧道登入仍給予密碼提示

我有兩台具有動態 IP 位址的筆記型電腦(主機 A 和主機 C)和一台桌上型電腦(主機 B),所有這些都運行 (Ubuntu) Linux。現在我已完成設置,以便我可以從主機 C 存取主機 A,如下所示。我有一個從 A 到 C 的 ssh 隧道,在 hostA 上使用以下形式的命令

autossh -NR 10023:localhost:22 [email protected]

我正在使用密鑰配對,以便 autossh 命令實際上可以發生。

然後我可以從 C ssh 進入 B,然後連接到 A

ssh -p 10023 localhost

提示輸入密碼,我可以進入。

不過,我想提高 A 的安全性,因此登入時需要金鑰。因此,我在 HostB 上使用 ssh-keygen 產生一對金鑰,並將我的金鑰命名為 customkey_rsa 並為其指定密碼。那麼customkey_rsa.pub就是公鑰。我無法讓 ssh-copy-id 使用此隧道,因此我只需從 C 登入 A,並透過主機 B 上的 customkey_rsa.pub 進行 scp。

cd .ssh & cat customkey_rsa.pub >> authorized_keys

但現在,當我嘗試登入時,我仍然收到密碼提示。事實上,它看起來就像嘗試了鑰匙一樣,但在最後一秒不知何故放棄了,如下所示

從B

ssh -v -i customkey_rsa -p 10023 localhost

給出

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Connecting to localhost [127.0.0.1] port 10023.
debug1: Connection established.
debug1: identity file customkey_rsa type 1
debug1: identity file customkey_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA (redacted)
debug1: Host '[localhost]:10023' is known and matches the ECDSA host key.
debug1: Found key in /home/ohnoplus/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: customkey_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password 
ohnoplus@localhost's password: 

~/.ssh請注意,主機 A 中的權限為 , 的700權限.ssh/authorized_keys600

所以我的問題。為什麼這不起作用,我該如何修復它?

我看過的事情沒有幫助:

仔細研究了建議清單。我的系統上的權限設定正確,其他解決方案不適用。 為什麼使用公鑰驗證時,我仍然收到 ssh 密碼提示?

類似,但沒有提供解決方案: 使用 rsa 金鑰的 ssh 要求輸入密碼

我沒有“authorized_keys2”文件 儘管 .ssh/authorized_keys ssh 仍提示輸入密碼

答案1

您需要添加:

PasswordAuthentication no

到你的 sshd_config (這是伺服器設定)

相關內容