无法打开授权,权限被拒绝[关闭]

Posted

技术标签:

【中文标题】无法打开授权,权限被拒绝[关闭]【英文标题】:Could not open authorized, Permission denied [closed] 【发布时间】:2015-04-01 09:04:36 【问题描述】:

我在尝试为我的用户设置 SSH 登录时收到此错误。

Feb  2 13:56:57 (none) sshd[4075]: debug1: trying public key file //.ssh/authorized_keys
Feb  2 13:56:57 (none) sshd[4075]: debug1: Could not open authorized keys '//.ssh/authorized_keys': Permission denied
Feb  2 13:56:57 (none) sshd[4075]: debug1: restore_uid: 0/0
Feb  2 13:56:57 (none) sshd[4075]: Failed publickey for soinfit from 79.182.124.164 port 52788 ssh2
Feb  2 13:56:57 (none) sshd[4075]: debug3: mm_answer_keyallowed: key 0x7f3d8516faf0 is not allowed
Feb  2 13:56:57 (none) sshd[4075]: debug3: mm_request_send entering: type 22
Feb  2 13:56:57 (none) sshd[4075]: debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa [preauth]

文件权限为:

root@(none):/home/soinfit# ls -lah
total 12K
drwx------ 3 soinfit soinfit 4.0K Feb  2 13:30 .
drwxr-xr-x 4 root    root    4.0K Feb  2 12:08 ..
drwx------ 2 soinfit soinfit 4.0K Feb  2 13:36 .ssh

我的 sshd 配置:

# 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 DEBUG3

# 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 no

我已经重启了 SSH 服务和机器。

我看到了这个帖子: SSHD Gives error could not open Authorized Keys, although permissions seem correct

那里给出的答案对我没有帮助。 当我尝试运行 restorecon -FRvv ~/.ssh 时,我得到:

root@(none):/home/soinfit/.ssh# restorecon -FRvv ~/.ssh
-bash: restorecon: command not found

编辑

root@(none):~# grep soinfit /etc/passwd
soinfit:x:1001:1001::/:/bin/sh

【问题讨论】:

您是否为 ssh 命令使用了正确的用户,例如 ssh soinfit@79.182.124.164soinfit的主目录是否正确(查看grep soinfit /etc/passwd)?我问这个是因为调试文件中的//.ssh/authorized_keys 条目。我会期待像/home/soinfit/.ssh/authorized_keys这样的东西。 我不明白你在说哪个命令 我已经编辑了评论。看看吧。 查看我的编辑。我发布到日志。 【参考方案1】:

您已将根目录 / 设置为用户 soinfit 而不是 /home/soinfit 的主目录。

为用户soinfit 编辑/etc/passwd 中的条目

soinfit:x:1001:1001::/:/bin/sh

soinfit:x:1001:1001::/home/soinfit:/bin/sh

【讨论】:

@BasileStarynkevitch 目录.ssh 位于/home/soinfit(参见OP 中'EDIT' 之前的代码)。另一侧的/etc/passwd 中的原始条目暗示用户soinfit 具有/ 作为$HOME。因此我建议在/etc/passwd 中更改此条目 现在我收到另一个错误:2 月 2 日 15:33:59(无)sshd[4440]:来自 79.182.124.164 端口 49778 ssh2 的 soinfit 的公钥失败 2 月 2 日 15:33:59(无) sshd[4440]: debug3: mm_answer_keyallowed: key 0x7f8d56455f70 is not allowed 看起来您调用ssh soinfit@79.182.124.164 的位置的公钥不在您服务器上的/home/soinfit/.ssh/authorized_keys 中。 文件在那里。我确定。 但是id_rsa.pub文件的条目是从您在文件/home/soinfit/.ssh/authorized_keys中启动ssh连接的位置开始的(应该是这样的一行:ssh-rsa AAAAB3[.......]== some_comment

以上是关于无法打开授权,权限被拒绝[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

无法打开输出文件,权限被拒绝

应用使用权限被拒绝如何解决

无法打开流或文件:无法打开流:权限被拒绝[重复]

无法打开流或文件:无法打开流:权限被拒绝

Laravel 4:无法打开流:权限被拒绝

ls: 无法打开目录'.': 权限被拒绝