使用 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 (这是服务器配置)

相关内容