通过 SSH 密钥进行 SSH 身份验证不起作用,即使在同一台机器上也不行,一直要求输入密码

通过 SSH 密钥进行 SSH 身份验证不起作用,即使在同一台机器上也不行,一直要求输入密码

在解决无法使用公钥身份验证从客户端连接到远程的问题之前,我认为我应该尝试从我的远程帐户登录到同一个远程帐户,以确保远程正确设置了 ssh。 无论如何,密码验证都可以正常工作。 以下是我在正在sshd运行的远程尝试过的步骤:

rm -rf ~/.ssh
ssh-keygen

我尝试了多种具有不同位长度的密钥类型,但结果对此不敏感。

cat ~/.ssh/id_key.pub >> ~/.ssh/authorized_keys

手动复制并粘贴公钥authorized_keys不会影响结果。我尝试将文件夹的权限设置.ssh为 700 和.ssh/authorized_keys600,但似乎也没有任何明显的效果。

sudo service sshd restart

下面是从我的客户端使用密码验证(在本例中使用密钥)连接时尝试ssh从远程到远程的完整输出:sshrsa

[user@remote ~]$ ssh -v -i .ssh/id_key remote
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to remote [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file .ssh/id_key type 1
debug1: key_load_public: No such file or directory
debug1: identity file .ssh/id_key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to remote:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:XXX
debug1: Host 'remote' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:131179)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:131179)

debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/id_key
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: password
user@remote's password:

我如何让 ssh 服务接受公钥?

非常感谢,经过几个小时阅读手册和网页后,您是我最后的选择。如果您需要查看一些选项,请告诉我。/etc/ssh/sshd_config我认为可能没有必要将其粘贴在这里,因为显然启用了公钥身份验证。

相关内容