SSH公钥无法验证登陆了,求问原因

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
billzt
帖子: 1666
注册时间: 2010-05-23 20:44
系统: Ubuntu
联系:

SSH公钥无法验证登陆了,求问原因

#1

帖子 billzt » 2015-06-12 13:05

我想使用SSH公钥实现免密码SSH登陆服务器,操作步骤完全按照 http://bbs.chinaunix.net/thread-343905-1-1.html 里面介绍的来进行,但是设置完之后发现还是需要输入密码。以下是 ssh -v 给出的信息:

代码: 全选

OpenSSH_6.8p1, OpenSSL 1.0.2a 19 Mar 2015
debug1: Connecting to 124.17.27.143 [124.17.27.143] port 22.
debug1: Connection established.
debug1: identity file /home/bill/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/bill/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:tVg3VPf1nFqCv+GCLEQ176FBgoXoCcXDmFugq0YxaM8
debug1: Host '124.17.27.143' is known and matches the RSA host key.
debug1: Found key in /home/bill/.ssh/known_hosts:1
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,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/bill/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/bill/.ssh/id_dsa
debug1: Trying private key: /home/bill/.ssh/id_ecdsa
debug1: Trying private key: /home/bill/.ssh/id_ed25519
debug1: Next authentication method: password
[email protected]'s password:
求问是哪里出问题了?(本来应该发在服务器板块里面,但是想借一下本版人气,请见谅)
师大生信者:http://bnuzhutao.cn
头像
lainme
论坛版主
帖子: 7805
注册时间: 2008-09-13 19:17
系统: Arch Linux (x86_64)
联系:

Re: SSH公钥无法验证登陆了,求问原因

#2

帖子 lainme » 2015-06-12 13:17

authorized_keys放的地方对么?通常用哪个用户登录,就要放到哪个用户的家目录下。再检查一下权限。

http://unix.stackexchange.com/questions ... entication
头像
billzt
帖子: 1666
注册时间: 2010-05-23 20:44
系统: Ubuntu
联系:

Re: SSH公钥无法验证登陆了,求问原因

#3

帖子 billzt » 2015-06-12 14:12

lainme 写了:authorized_keys放的地方对么?通常用哪个用户登录,就要放到哪个用户的家目录下。再检查一下权限。

http://unix.stackexchange.com/questions ... entication
我仔细看了一下,跟这个是一模一样的问题 http://serverfault.com/questions/321534 ... -is-daemon ,服务器端sshd如果是daemon,就无法成功,如果是debug mode,就能成功。

我在服务器端执行了 restorecon -R -vv ~/.ssh,但还是不行。

服务器是 CentOS 6.5
师大生信者:http://bnuzhutao.cn
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: SSH公钥无法验证登陆了,求问原因

#4

帖子 poloshiao » 2015-06-12 16:26

我想使用SSH公钥实现免密码SSH登陆服务器
但是设置完之后发现还是需要输入密码。

ssh-keygen -t rsa

ssh-keygen -t dsa
會要你輸入密碼

如果 你直接按下 Enter 不要任何輸入 # 意思是 密碼是空集合
那麼 將來 SSH 登陆服务器 時 就不必輸入密碼
實際上 還是有密碼 密碼是空集合

參閱
https://help.ubuntu.com/lts/serverguide ... enssh-keys
試試看 CentOS 6.5 是否也適用
头像
billzt
帖子: 1666
注册时间: 2010-05-23 20:44
系统: Ubuntu
联系:

Re: SSH公钥无法验证登陆了,求问原因

#5

帖子 billzt » 2015-06-12 21:13

poloshiao 写了:
我想使用SSH公钥实现免密码SSH登陆服务器
但是设置完之后发现还是需要输入密码。

ssh-keygen -t rsa

ssh-keygen -t dsa
會要你輸入密碼

如果 你直接按下 Enter 不要任何輸入 # 意思是 密碼是空集合
那麼 將來 SSH 登陆服务器 時 就不必輸入密碼
實際上 還是有密碼 密碼是空集合

參閱
https://help.ubuntu.com/lts/serverguide ... enssh-keys
試試看 CentOS 6.5 是否也適用
不对,主要还是上楼的问题。怀疑是selinux的问题
师大生信者:http://bnuzhutao.cn
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: SSH公钥无法验证登陆了,求问原因

#6

帖子 poloshiao » 2015-06-12 21:40

不对,主要还是上楼的问题。怀疑是selinux的问题
1. 可以大膽假設 但是要小心求證
作作看 再下結論吧
我想使用SSH公钥实现免密码SSH登陆服务器
2. 你的目的 是 免密碼

3. http://unix.stackexchange.com/questions ... entication
Why am I still getting a password prompt with ssh with public key authentication?
這一篇文章 問的問題 跟你問的一樣

3-1. 其中
http://unix.stackexchange.com/a/76167
Just try these following commands
1. try these following commands
ssh-keygen
Press Enter key till you get the prompt

3-2. 跟
viewtopic.php?p=3136543#p3136543
講的是同一件事
ssh-keygen -t rsa
直接按下 Enter
回复