linux - Permission denied (publickey,gssapi-keyex,gssapi-with-mic)报错
迷茫
迷茫 2017-04-17 16:21:27
0
1
1032

1、搞了一个 VPS ,想设置免钥登录,生成私钥和公钥之后,把"#PasswordAuthentication yes" 改成"PasswordAuthentication no" 之后就一直报这个错, Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 搜索了下,权限都 OK , authorized_keys 600 和 644 都试了,.ssh 也是 700 ,就是没办法啊,老报错,求高手解决;SELinux 已关闭,修改了默认端口,端口已加入防火墙了。

2、 ssh-vvv log如下:
penSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 我的 IP [我的 IP] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 7b:70:a2:01:de:01:13:68:9f:38:2a:32:11:a0:60:7e
debug1: Host ‘我的 IP' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
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,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

debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available

debug1: Unspecified GSS failure. Minor code may provide more information

3、ls -l ~/.ssh/
显示
-rw-r--r-- 1 root root 395 12 月 6 17:31 authorized_keys
-rw-r--r-- 1 root root 139 12 月 6 17:40 config
-rw-r--r-- 1 root root 175 12 月 6 16:09 known_hosts

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(1)
迷茫

這是因為你SSH登入的時候沒有加入key參數。

如果你用linux系統去登入的話應該是這樣的:

MacBook-Air-Lan:~ terence$ ssh root@[host or ip] -p [your ssh port] -i [you ssh key]

-p 是端口,如果是預設的22端口可以忽略這個參數;
-i 是ssh key

在透過 ssh-keygen -t rsa -b 4096 指令產生SSH金鑰對的時候會產生兩個檔案:ssh-keygen -t rsa -b 4096 命令生成SSH密钥对的时候会生成两个文件:

  1. .ssh/id_rsa.pub

  2. .ssh/id_rsa

需要将1更名为authorized_keys:

mv .ssh/id_rsa.pub .ssh/authorized_keys

然后将id_rsa文件复制到本地。

还有很重要的一点是,配置好密钥之后先尝试通过证书的方式登录,成功后再修改/etc/ssh/sshd_config

最最后,推一下我的网站,SSH的配置可以参考第七点:0x07 配置SSH

.ssh/id_rsa.pub

  1. .ssh/id_rsa

  2. 需要將1更名為authorized_keys:

    rrreee

    然後將id_rsa檔案複製到本地。
還有很重要的一點是,設定好金鑰之後先嘗試透過憑證的方式登錄,成功後再修改/etc/ssh/sshd_config

最最後,推一下我的網站,SSH的設定可以參考第七點:0x07 設定SSH🎜 🎜新安裝的centos7前期準備🎜 🎜補充:🎜 🎜 🎜🎜請保持authorized_keys檔案的權限為644🎜🎜 🎜🎜請在伺服器上刪除id_rsa文件,或設定權限為600。 🎜🎜 🎜 🎜另外,在mac或Linux上使用SSH金鑰登入時,需要將key的權限設為400。 🎜
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!