权限被拒绝(PublicKey)无效-Ubuntu

时间:2020-01-06 06:34:05

标签: ubuntu ssh permissions public

我一直在努力几个小时,以在运行Ubuntu的计算机和cpanel Web主机之间建立SSH连接。我一一尝试了在互联网上找到的所有解决方案,但没有一个解决了我的问题。我总是收到这个“权限被拒绝(公共密钥)”。

我以所有可能的方式编辑了sshd_config。

当我运行命令:ssh -vvv user@server.com时,这就是我得到的:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to mikaelthiffeault.com [198.72.104.64] port 22.
debug1: Connection established.
debug1: identity file /home/mikael/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mikael/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to mikaelthiffeault.com:22 as 'mikaelt'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:hfwdTaky/bQQaQy/fnPoarKCBqDblCVkBVM3aPkhkEc
debug1: Host 'mikaelthiffeault.com' is known and matches the ECDSA host key.
debug1: Found key in /home/mikael/.ssh/known_hosts:1
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
debug1: No more authentication methods to try.
Permission denied (publickey).

请帮助我,你们是我最后的希望。

1 个答案:

答案 0 :(得分:0)

这里也一样。 我收到尝试执行此消息的消息-ssh -v user1@192.168.1.20 -i ~/.ssh/my-keypair-1

我尝试将正确的权限设置为〜/ .ssh /和〜/ .ssh / authorized_keys 没有运气.. 我实际上有另一个用户在同一台​​计算机上使用另一个SSH密钥,该用户的SSH密钥配置完全相同!

现在尝试将近2天。

更新-最终找到了解决方案!

问题在于权限

事实证明,SSH对权限非常挑剔,您需要做的就是(在您要连接的服务器中) 删除.ssh文件夹(在提示符下{rm -r ~/.ssh/键入yes,然后单击Enter)。

然后,不要自己创建.ssh文件夹,而是ssh-keygen,不用担心它创建的那些新的私钥和公钥,可以自由删除它们。
最后,将CD插入.ssh文件夹(cd ~/.ssh/)中并创建authorized_keys(nano authorized_keys),然后将其粘贴到公共密钥中,单击CTRL + X(保存),然后键入字母y,然后单击Enter。

PS -如果您想要更好的安全性,这意味着用户将无法使用密码而不是密钥登录,打开外壳并在其中键入sudo nano /etc/ssh/sshd_config,滚动到最后一部分,然后粘贴

ChallengeResponseAuthentication no

PasswordAuthentication no

UsePAM no

PermitRootLogin no

PubkeyAuthentication yes

请确保其中没有#,因为#使它们仅是注释而不是实际命令。

如果您希望能够通过SSH进入root用户,只需从其中删除PermitRootLogin no

现在,单击CTRL + X,键入字母y,然后单击Enter。

几乎忘记了-执行sudo /etc/init.d/ssh restart重新启动SSH服务器,以便您的配置生效。

您完成了!让我知道我是否犯了任何错误。

我已发表此评论,以便有此问题的其他人可以解决。