公钥认证失败


9

我正在使用ubuntu 13.10,并且服务器运行ubuntu 12.04。我已经使用ssh-keygen生成了私钥和公钥,并将id_rsa.pub放到服务器端,并将其添加到authorzied_keys我在Internet上找到的方法中。但是,在尝试登录时,我仍然必须输入密码。我已经将主目录设置为700,.ssh目录设置为700,authorzied_keys文件设置为600,并且我检查了sshd_config文件,但没有任何反应。

调试信息(带有-vvv选项)和sshd_config如下,服务器的auth.log文件中未列出任何内容。

我什至在客户端和服务器端都更新了openssh-server openssh-client。

我还有什么需要做的吗?感谢您提供任何信息。

debug3: load_hostkeys: loading entries for host "[xxx.101.15.62]:2222" from file "/home/leetom/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/leetom/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "[xxx.101.15.62]:2222" from file "/home/leetom/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /home/leetom/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host '[xxx.101.15.62]:2222' is known and matches the ECDSA host key.
debug1: Found key in /home/leetom/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/leetom/.ssh/id_rsa ((nil)),
debug2: key: /home/leetom/.ssh/id_dsa ((nil)),
debug2: key: /home/leetom/.ssh/id_ecdsa ((nil)),
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/leetom/.ssh/id_rsa
debug1: read PEM private key done: type RSA
debug3: sign_and_send_pubkey: RSA 68:51:b6:ed:cc:c2:54:f4:xx:15:41:d7:f5:4a:0e:da
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/leetom/.ssh/id_dsa
debug3: no such identity: /home/leetom/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/leetom/.ssh/id_ecdsa
debug3: no such identity: /home/leetom/.ssh/id_ecdsa: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
leetom@xxx.101.15.62's password: 

和sshd_config

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

Answers:


12

好像我们使用您的私钥尝试进行密码登录一样,然后由于不被接受而不得不尝试其他操作:

debug1: Trying private key: /home/leetom/.ssh/id_rsa
debug1: read PEM private key done: type RSA
debug3: sign_and_send_pubkey: RSA 68:51:b6:ed:cc:c2:54:f4:xx:15:41:d7:f5:4a:0e:da
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password

最简单的问题可能是您复制了公钥,因为我尝试使用我知道另一端没有的密钥进行身份验证时会得到相同的响应。

与其尝试手动复制ID,不如不尝试ssh-copy-id-输入密码,密码将会更新authorized_keys。那应该(a)绝对选择与ssh应该选择的键相同的密钥,(b)确保您没有意外添加任何格式错误。

如果这对您有用,请比较添加到的行authorized_keysssh-copy-id并希望您会明白问题出在哪里。


很有效,非常感谢!原来,我在authorized_keys文件名上有错字。我尝试过每种方法并多次检查文件名(我读过一些有关文件名错字的信息),但是...我困倦时眼睛无法正常工作……
leetom 2013年

使用ssh-copy-id为我制造了诀窍
Asaf 2014年

除非您拥有Mac,否则它可以完美运行。:)
Fixee

@Fixee,brew install ssh-copy-id如果您使用自制软件
Greg,

1
如果您启用了SELinux并对其进行了错误配置,那么这些确切的症状也会显现出来,从而阻止sshd读取authorized_keys文件(在未查看SELinux审核日志的情况下并不总是很明显,因为SELinux的粒度足够细,您可以轻松地进入一种状态,其中以用户或通过sudo读取手册可以成功)
mtraceur

5

权限可能是导致公钥身份验证失败的另一种问题:检查您的~~/.ssh目录,除您的用户外,其他任何人都不可读(chmod 700 ~ && chmod 700 ~/.ssh可以解决此问题)。

编辑:权限750 ~应该也可以。


这是真的吗?的权限~/无关紧要,Ubuntu中的默认目录通常是主目录中的755,它对我有用。
UlfR '16

我真的遇到了(在远程主机上)使用CentOS 7以及OpenSSH_6.4和OpenSSH_6.6.1的问题。这样做chmod 700 ~已经解决了我的问题。
AntonioK 2016年

对你有益!但是:根据:askubuntu.com/a/69867/31749,主目录上没有组写入权限,但组读取应该可以。
UlfR

好的,我应该检查750在我的系统上是否可以正常工作。
AntonioK '16

2
刚刚检查。chmod 750 ~工作良好。
AntonioK '16

3

偶然地,在创建authorized_keys文件时,您是否拼错了文件名(由于您已authorzied_keys按照问题中的拼写方式进行了拼写(交换了i和z),所以您可能以相同的方式命名了文件)在ssh配置文件中,文件名专门提到为

AuthorizedKeysFile %h/.ssh/authorized_keys

因此,您需要特别指出文件名是相同的。因此,只需验证文件名即可。


3

有时您需要使用-i显式提供私钥

例: ssh -i /root/.ssh/id_rsa2 user@remote


1
这似乎不是这里的问题,但无论如何都是好点。
LittleByBlue
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.