web-dev-qa-db-ja.com

SSHD Givesエラーは許可されたキーを開けませんでしたが、権限は正しいようです

/ var/log/secureに次のエラーがあるため(デバッグログによる)、SSHにログインできません。

Dec 19 18:01:05 hostname sshd[25119]: debug1: trying public key file /root/.ssh/authorized_keys
Dec 19 18:01:05 hostname sshd[25119]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys': Permission denied

ルートに次の権限が設定されています

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod go-wrx ~

ls -lahは、これらのディレクトリに対して次の出力を提供します。

drwx------.   6 root root 4.0K Dec 19 17:46 root
drwx------.  2 root root 4.0K Dec 19 17:41 .ssh
-rw-------. 1 root root  416 Dec 19 17:12 authorized_keys

別のサーバーを問題なくセットアップするだけなので、使用しているキーが正しいことはわかっています。

実行中:CentOSリリース6.4(最終版)

問題を引き起こしている可能性のある何かが間違って設定されている場合に備えて、sshd設定を追加しました。

#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_Host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_Host_rsa_key
#HostKey /etc/ssh/ssh_Host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel DEBUG

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
StrictModes no
#MaxAuthTries 6
#MaxSessions 10

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

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

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server

どんなアイデアでも大歓迎です。

28
newUserNameHere

パーミッションが正しい場合、SELinuxがまだsshdがファイルを開くのを妨げている可能性があります。

.sshディレクトリ(および場合によっては$ HOME)内のラベルを修正してください。

restorecon -FRvv ~/.ssh

(私は意図的にSELinuxを無効にすることや許容モードに設定することを提案していません。)

86
Jan Včelák

キー認証も使用するのに苦労していました。

許可されたキー '/home/myUserName/.ssh/authorized_keys2'を開けませんでした:許可が拒否されました

ここにたどり着いたときに、上記のすべてをチェックしていました(グーグルの最初のリンク)。これは古い投稿であることを認識していますが、他の誰かが私と同じ問題を抱えている場合に備えて、ここに追加します。

Authorized_keysファイルの所有者が「root」になっているため、次のように変更します。

chown myUserName authorized_keys2

私のためにそれを解決しました。

5
niclaslindgren

SELinuxが有効になっている場合:

$ getenforce
Enforcing

非標準ユーザーのホームディレクトリの場所へのpub-key sslログインを一時的に有効にするには:

$ Sudo chcon -t ssh_home_t /srv/jenkins/.ssh/authorized_keys /srv/jenkins/.ssh

$ ls -ldZ /srv/jenkins/.ssh/authorized_keys /srv/jenkins/.ssh/
drwxr-xr-x. jenkins jenkins system_u:object_r:ssh_home_t:s0  /srv/jenkins/.ssh/
-rw-r--r--. jenkins jenkins system_u:object_r:ssh_home_t:s0  /srv/jenkins/.ssh/authorized_keys

詳細については https://linux.die.net/man/8/ssh_selinux をご覧ください。

SELinux設定を永続的に実行するには:

$ Sudo semanage fcontext -a -t ssh_home_t /srv/jenkins/.ssh/authorized_keys
$ Sudo semanage fcontext -a -t ssh_home_t /srv/jenkins/.ssh
$ Sudo restorecon -R -v /srv/jenkins/.ssh/

これは、最新のRHEL、Oracle Linux、CentOSを使用している場合にヒットします。

4
gavenkoa

/ homeディレクトリーの許可を確認してください。そのはず

  • _drwxr-xr-x. 9 root root 113 Jun 28 22:57 home_

次にホームディレクトリの詳細:

  • _drwxr----- 5 user group 124 May 18 17:00 User drwx------ 2 user group 29 May 18 12:05 .ssh -rw------- 1 user group 2235 Jun 28 23:09 authorized_keys_



ログのエラーメッセージ

/ var/log/secure> sshd [22565]:エラー:X.X.X.Xから切断を受信しました:14:利用可能なサポートされている認証方法がありません[preauth]

クライアント側

ssh [email protected] Permission denied (publickey). ssh -vvv [email protected] ... debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey).
サーバー側

  • _service sshd stop_

  • sshdデバッグモードを実行します。

  • _/usr/sbin/sshd -ddd_

    _... debug1: trying public key file /home/USER/.ssh/authorized_keys debug1: Could not open authorized keys '/home/USER/.ssh/authorized_keys': Permission denied ..._

1
Bed Mi

この同じ問題に遭遇し、.sshとauthorized_keysの所有者の両方を同時に変更することで解決しました:chown MyUsername:Myusername .ssh chown MyUsername:Myusername .ssh/authorized_keys

@niclaslindgrenに感謝します。

ところで、authorized_keysに^ Mが含まれているかどうかは関係ありません。テストして証明しましたが、両方の方法で機能します

0

チェックするいくつかのアイデア:

  • Authorized_keysを猫にできますか?ファイルはどのように見えますか?
  • Sshdはルートログインを許可するように設定されていますか?これは一般的に嫌われています、
  • あなたはそれをルートとして、またはsudoerとしてやっていますか?
0
devnill

再確認するいくつかのこと:

  1. 秘密キーではなく、PUBLICキーをauthorized_keysにコピーしましたか? :-)
  2. 行う cat -tv authorized_keys。どれか ^M文字は各行の最後にありますか? dos2unix オン authorized_keys
  3. 構成を変更した後、sshデーモンを再起動しましたか?
0
vijucat
  1. ~/.ssh/...chmodを実行しないでください。正確なパスを書いてみてください:/root/.ssh/...。ときどき(suなどを使用するとき)、~が正しく設定されないことがあります。コマンドで~を使用せずに、完全なパスのアクセス許可を再度確認して投稿してください。

  2. パーミッションがOKであることを完全に確認したら、sshdが実際にユーザールートps -A u | grep sshdで実行されているかどうかを確認します。

0
TMS