即使我尝试使用我创建的用户密码进行连接,SSH 仍然会要求输入公钥

即使我尝试使用我创建的用户密码进行连接,SSH 仍然会要求输入公钥

4 个月前,我在 DreamCompute (DreamHost) 上创建了一个实例。要通过 ssh 连接到它,您需要创建一个密钥对,并使用用户的公钥进行访问dhc-user:我记得当我第一次登录时,我创建了一个带密码的新用户,这样我就可以在没有公钥的情况下连接到服务器,并且它运行正常。

现在我终止了该实例并创建了一个新的实例,我做了同样的事情,但是当我尝试连接到我添加的用户时,它给了我错误Permission denied (publickey)

$ ssh -v user@IPADDRESS
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to IPADDRESS [IPADDRESS] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to IPADDRESS as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:blablablabla
debug1: Host 'IPADDRESS' is known and matches the ECDSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: 
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/user/.ssh/id_rsa
debug1: Trying private key: /Users/user/.ssh/id_dsa
debug1: Trying private key: /Users/user/.ssh/id_ecdsa
debug1: Trying private key: /Users/user/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

答案1

您使用了错误的 SSH 密钥,或者它对于您尝试连接的服务器无效。

检查您使用的密钥是否对服务器有效。如果您将其保存在其他地方,请使用该ssh -i <path_to_key>密钥强制使用该特定密钥。

如果您实际上没有密钥,则需要使用 DreamCompute 控制台临时添加一个密钥,或者从恢复控制台禁用它(如果有的话)。

笔记:禁用 SSH 密钥验证以回退到密码是一个坏主意!SSH 密钥是很多比密码更安全,强烈建议您保持启用状态。


然后,要禁用服务器上的 SSH 密钥验证,您必须实际上将其关闭。

在 中/etc/ssh/sshd_config有以下几行:

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

将其更改noyes使用您最喜欢的文本编辑器,然后ssh通过运行重新启动服务:sudo service ssh restart

相关内容