错误“权限被拒绝(公钥,密码)”

har*_*amc 7 ssh openssh remote-access rsa public-key

我正在尝试从终端通过 SSH 连接到本地 IP 地址。命令是

ssh -v user@192.168.0.2
Run Code Online (Sandbox Code Playgroud)

但它没有连接。它不断给我错误

“权限被拒绝(公钥,密码)。”

我一直在寻找年龄,只是找不到问题所在。我可以通过Windows上的PuTTY使用相同的方法进行连接,也可以通过FileZilla进行连接

完整输出:

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 192.168.0.2 [192.168.0.2] port 22.
debug1: Connection established.
debug1: identity file /Users/[UserName]/.ssh/id_rsa type 1
debug1: identity file /Users/UserName/.ssh/id_rsa-cert type -1
debug1: identity file /Users/UserName/.ssh/id_dsa type -1
debug1: identity file /Users/UserName/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2
debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: [Server Host Key]
debug1: Host '192.168.0.2' is known and matches the RSA host key.
debug1: Found key in /Users/[UserName]/.ssh/known_hosts:1
debug1: ssh_rsa_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: /Users/[UserName]/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/[UserName]/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey,password).
Run Code Online (Sandbox Code Playgroud)

bar*_*lop 7

尝试再次添加密钥。

PasswordAuthentication yes在目的机的sshd_config文件里设置,然后do ssh-copy-id user@host,登录,然后把keycopy过来。

现在您可以设置PasswordAuthentication no(如果需要,为了额外的安全),您应该能够自动登录。

您还可以利用您的好奇心检查源计算机上的 id_rsa.pub 是否在目标计算机上的authorized_keys文件中。

  • 现货!像魅力一样工作 (2认同)

Mic*_*her 5

您可能已经在启动的机器上进行了PasswordAuthentication no设置。该文件用于传出 ssh 连接。/etc/ssh/ssh_configssh

对于传入的 ssh 连接,相同的设置也存在于远程计算机/etc/ssh/sshd_configsshd而不是!)中。ssh但如果此设置错误,它也将无法与另一台计算机putty一起使用或使用ssh

必须将两个文件中的设置设置为PasswordAuthentication yes才能使其正常工作。

当您不是管理员或者只是不想/etc/ssh/ssh_config永久更改本地时,您还可以将参数传递到 ssh 命令行:

ssh -o "PasswordAuthentication yes" yourserverip
Run Code Online (Sandbox Code Playgroud)

  • 我已经尝试了几个小时 ssh 到一台机器,但没有成功,包括使用“ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no”。我刚刚尝试了你的`ssh -o“PasswordAuthentication yes”`,我终于加入了! (2认同)