错误‘权限被拒绝(公钥,密码)’

错误‘权限被拒绝(公钥,密码)’

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

ssh -v [email protected]

但它没有连接。它一直给我错误

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

我搜索了很久,就是找不到问题所在。我可以使用相同的方法通过油灰在 Windows 上,可以通过档案

完整输出:

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).

答案1

尝试再次添加密钥。

PasswordAuthentication yes文件中的第一组sshd_配置在目标机器上,然后执行ssh-copy-id user@host,登录,然后它就会复制密钥。

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

你也可以好奇地检查源机器上的 id_rsa.pub 是否在授权密钥目标机器上的文件。

答案2

您可能已经在启动的机器上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

答案3

它可能有所不同,因为它看起来像您正在连接localhost或某物(192.168.0.2或者这只是为了提出问题?)。

解决此类问题的方法通常是编辑文件~/.ssh/known_hosts并删除您要连接的域的条目,它会重新提示您输入 ssh 凭据并避免因不正确的“期望”而导致的问题。

答案4

首先cat $HOME/.ssh/id_rsa.pub在您的计算机上运行。这将为您获取一个密钥。将此密钥保存在某处。

然后通过在您要 ssh 连接的计算机上运行来打开此文件vim $HOME/.ssh/authorized_keys。然后将密钥复制到此文件的新行中,并通过键入关闭它:wq

一切已就绪。

相关内容