SSH 权限被拒绝(公钥),但 root ssh 有效

use*_*314 17 server ssh

我正在尝试为我在 DigitalOcean Ubuntu 12.04 服务器上使用厨师创建的用户帐户设置 ssh 访问权限。我在 DigitalOcean 中设置了选项,以便在创建 Droplet 时自动复制我的 mac 的 ssh 密钥。

我可以毫无问题地以 root 身份登录,但我的其他用户无法进行身份验证。这似乎是一个常见问题,我检查了其他一些答案,并找到了此命令以获取更多信息:

ssh -vvv -i id_rsa user@serverIP
Run Code Online (Sandbox Code Playgroud)

使用该命令的 root 用户(成功)的日志是

调试

1: Offering RSA public key: /Users/evan/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp snip!
debug3: sign_and_send_pubkey: snip!
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Run Code Online (Sandbox Code Playgroud)

失败的用户:

调试

1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred 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: Offering RSA public key: /Users/evan/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/evan/.ssh/id_dsa
debug3: no such identity: /Users/evan/.ssh/id_dsa: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Run Code Online (Sandbox Code Playgroud)

这对我来说意味着公钥不正确。但是,如果我以 root 用户身份登录并转到

home/otheraccount/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

然后我可以看到我的 ssh 密钥在那里。我以为可能有错误,所以我做了:

cp .ssh/authorized_keys ~/home/otheraccout/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

但这没有帮助。我不知道还能去哪里看。

我的etc/ssh/sshd_config

# 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
"sshd_config" 88L, 2508C
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

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 no

# GS

SAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

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

#MaxStartups 10:30:60

AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM no
Banner /etc/ssh_banner
Run Code Online (Sandbox Code Playgroud)

编辑:

drwx------ 2 deploy deploy 4096 Apr 20 06:00 .ssh
-rw------- 1 deploy deploy 820 Apr 20 05:35 authorized_keys
Run Code Online (Sandbox Code Playgroud)

编辑2:

正如评论中所建议的,/var/log/authlog包含:

Apr 21 04:59:30 localhost sshd[586]: User deploy not allowed because account is locked
Apr 21 04:59:30 localhost sshd[586]: input_userauth_request: invalid user deploy [preauth]
Run Code Online (Sandbox Code Playgroud)

我试图做:

sudo usermod --expiredate -1 deploy
Run Code Online (Sandbox Code Playgroud)

它返回:

no changes
Run Code Online (Sandbox Code Playgroud)

小智 19

  • SSH登录失败有多种原因(不正确的目录/文件的权限,不正确的密钥等)和连接的客户端将只得到Permission deniedNo more authentication methods to try或一些一般性错误。

  • 登录失败的确切原因将在 ssh 日志中提供/var/log/auth.log/var/log/secure取决于 syslog 配置。

  • 这是我见过的有关 SSH 登录失败问题的最佳答案!不要像所有其他答案所建议的那样随机猜测错误的权限和文件名,只需检查提到的日志,它们包含您需要的所有信息! (2认同)
  • 我怀疑如果您正在查看充当服务器 (sshd) 的计算机,这些日志会很有帮助,但如果您尝试连接到您无权访问的远程计算机,这些日志就没有帮助。 (2认同)