公開鍵認証に失敗しました


9

私はubuntu 13.10を使用しており、サーバーはubuntu 12.04を実行しています。私はssh-keygenを使用して秘密鍵と公開鍵を生成し、id_rsa.pubをサーバー側にauthorzied_keys配置して、インターネットで見つけたメソッドに追加しました。しかし、ログインしようとしている間もパスワードを入力する必要があります。ホームディレクトリを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

回答:


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_keysによって追加された行を比較してssh-copy-idください。うまくいけば、何が問題だったか理解できるでしょう。


うまくいきました、ありがとうございました!authorized_keysファイル名にタイプミスがあったことがわかりました。私はすべての方法を試し、ファイル名を何度もチェックしましたが(ファイル名のタイプミスについて何か読んだ)、...眠い間は目がうまくいきません...
leetom

使用することssh-copy-idが私にとってのトリックになった
Asaf 14

これは完璧に動作します... Macをお持ちでない限り。:)
Fixee 2015年

@Fixee brew install ssh-copy-idあなたが自作を使用する場合
グレッグ

1
これらの正確な症状は、SELinuxが有効になっていて、sshdがauthorized_keysファイルを読み取れないように誤って構成している場合にも発生する可能性があります(SELinuxは、簡単にアクセスできるほど細かいため、SELinux監査ログを確認しないと必ずしも明白ではありません。ユーザーとして、またはsudoを介して手動で読み取ることができる状態)
mtraceur

5

アクセス許可は、公開鍵認証の失敗の原因となる別の種類の問題である可能性があります。ユーザーとユーザーのディレクトリ以外のユーザーが~~/.sshディレクトリを読み取れないことを確認してください(それchmod 700 ~ && chmod 700 ~/.sshを修正できる可能性があります)。

編集:の権限750 ~も問題ないはずです。


これは本当ですか?の権限は~/問題になりません。Ubuntuのデフォルトは通常、ホームディレクトリの755であり、私には問題ありません。
UlfR 2016

私は本当に(リモートホストで)CentOS 7とOpenSSH_6.4とOpenSSH_6.6.1の両方を使用することに直面しました。これでchmod 700 ~問題は解決しました。
AntonioK

よかったね!しかし、これによれば、askubuntu.com / a / 69867/31749にはホームディレクトリに対するグループ書き込み権限はありませんが、グループ読み取りは問題ないはずです。
UlfR 2016

そのシステムで私のケースで750が機能するかどうかを確認する必要があります。
AntonioK

2
ちょうどそれをチェックしました。chmod 750 ~正常に動作します。
AntonioK

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 2018年
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.