SSH 设置免密登录遇到的报错, Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

2016-12-06 17:01:09 +08:00
 zzandlove

搞了一个 VPS ,想设置免钥登录,生成私钥和公钥之后,把"#PasswordAuthentication yes" 改成"PasswordAuthentication no" 之后就一直报这个错, Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 搜索了下,权限都 OK , authorized_keys 600 和 644 都试了,.ssh 也是 700 ,就是没办法啊,老报错,求高手解决

39738 次点击
所在节点    程序员
80 条回复
lifanxi
2016-12-06 17:10:15 +08:00
连 ssh 时加-vvv 参数,看具体的 Log 分析原因。
maikcn
2016-12-06 17:13:48 +08:00
私钥的权限设置为 600 了吗? ~/.ssh/id_rsa
indust
2016-12-06 17:14:37 +08:00
SELinux 问题? 试试 restorecon -r ~/.ssh
zzandlove
2016-12-06 17:29:09 +08:00
@indust 关闭了
zzandlove
2016-12-06 17:29:26 +08:00
@maikcn 设置了的
zzandlove
2016-12-06 17:29:42 +08:00
@lifanxi 怎么理解?菜鸟实在不懂 哈哈
noobsheldon
2016-12-06 17:36:17 +08:00
vultr
2016-12-06 17:37:15 +08:00
报这个错误,应该是你的公钥和私钥没有配对好。

ssh user@ip -v

看看具体报什么错误。
zzandlove
2016-12-06 17:37:19 +08:00
@noobsheldon 谢谢,这个看过,没用,哈哈
noobsheldon
2016-12-06 17:39:35 +08:00
@zzandlove 你是什么系统啊
BOYPT
2016-12-06 17:41:44 +08:00
手工添加的 key 可以参考下我的脚本:

https://coding.net/u/boypt/p/ptcoding/git/raw/master/bash/addkey.sh

如果是 rh 系的要注意 selinux ,用命令

restorecon -R -v $HOME/.ssh
sunnyyj
2016-12-06 17:43:43 +08:00
前两天用 google cloud ,想改成 root 直接登录也遇到相同的问题
改 sshd_config , PermitRootLogin yes ,重启 sshd 服务
然后执行了几个命令,突然就好了,不知道对你有没有帮助
chown -R root:root ~/.ssh
chmod 600 ~/.ssh/authorized_keys
restorecon -r -vv ~/.ssh
zzandlove
2016-12-06 17:45:58 +08:00
@vultr

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


我改了默认的 22 端口,改成其他的了
zzandlove
2016-12-06 17:49:22 +08:00
@noobsheldon CentOS 7 64
aaronzjw
2016-12-06 17:51:04 +08:00
chmod 600 '密钥'
zzandlove
2016-12-06 17:52:14 +08:00
@sunnyyj 谢谢
zzandlove
2016-12-06 17:52:53 +08:00
@aaronzjw 是 600 哦
hilenlai
2016-12-06 17:56:27 +08:00
我有个问题是在 .ssh 里面做了 config 分配,但是每次重启都要执行:`ssh-add -K ~/.ssh/id_rsa` 才可以。谁知道怎么破?
vultr
2016-12-06 17:59:50 +08:00
@zzandlove 自己搜吧,关键词: No Kerberos credentials available
zzandlove
2016-12-06 18:02:20 +08:00
@vultr 好咧,十分感谢大神,我研究研究去

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/325706

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX