sshはパスワードを要求しない

sshはパスワードを要求しない

どういうわけか、私の SSH はパスワードを尋ねようとしません。

そこで、世界のどこかのランダムなサーバーに VPS をセットアップし、SSH で接続したいと考えています。

キーを設定できますが、次のようにすると:

ssh -l some-user IP

次のエラーが発生します:

Received disconnect from ##.##.##.##: 2: Too many authentication failures for some-user

詳細を見ると、パスワードがオプションの 1 つであることがわかります。

debug1: Offering RSA public key: some-user@computer
debug1: Authentications that can continue: publickey,password

しかし、SSH はパスワードを尋ねません。公開鍵方式と思われる方法で 5 回試行して失敗します。なぜ SSH はパスワードで試行しないのでしょうか?

念のため、私の ssh_config ファイルには次の内容が含まれています。

PasswordAuthentication yes

完全なログ

ssh -v -l root ##.##.##.##
OpenSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /home/someuser/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ##.##.##.## [##.##.##.##] port 22.
debug1: Connection established.
debug1: identity file /home/someuser/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/someuser/.ssh/id_rsa-cert type -1
debug1: identity file /home/someuser/.ssh/id_dsa type -1
debug1: identity file /home/someuser/.ssh/id_dsa-cert type -1
debug1: identity file /home/someuser/.ssh/id_ecdsa type -1
debug1: identity file /home/someuser/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2p2 Ubuntu-6
debug1: match: OpenSSH_6.2p2 Ubuntu-6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA XX:XX:...:XX:XX
debug1: Host '##.##.##.##' is known and matches the ECDSA host key.
debug1: Found key in /home/someuser/.ssh/known_hosts:38
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/someuser/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: someuser@computer
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: someuser@computer
debug1: Authentications that can continue: publickey,password
debug1: Offering DSA public key: someuser@computer
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: someuser@computer
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: someuser@computer
Received disconnect from ##.##.##.##: 2: Too many authentication failures for root

答え1

公開鍵認証を無効にしてログインしてみてください。

ssh -o PubkeyAuthentication=no root@newserver

答え2

おそらく、ファイルには複数のidentityfile行があります.ssh/config

たとえ設定が不十分であってもidentityfilehostそれはグローバルに適用されます。つまり、sshサーバーからパスワード プロンプトを要求する前に、すべてのホスト上のすべての ID ファイル (つまり公開キー) が試されるということです。

これを修正するには

  1. 1行を除いてすべて削除するidentityfile、または
  2. PubkeyAuthentication noに追加する.ssh/config、または
  3. パラメータ付きでsshを実行しています-o PubkeyAuthentication=no

からman 5 ssh_config

PubkeyAuthentication
    Specifies whether to try public key authentication.  The argument to this
    keyword must be “yes” or “no”.  The default is “yes”.  This option applies 
    to protocol version 2 only.

IdentityFile
    ...
    It is possible to have multiple identity files specified in configuration
    files; all these identities will be tried in sequence.  Multiple 
    IdentityFile directives will add to the list of identities tried (this 
    behaviour differs from that of other configuration directives).

公開鍵に関する一般的な手順:

  1. 一般的に、クライアント (ワークステーション) ごとに 1 つの秘密キーのみを保持し、クライアントがアクセスする必要があるすべてのサーバーに一致する公開キーを配置する必要があります。つまり、サーバー間で公開キーを共有し、複数のデバイスで同じ秘密キーを使用しないようにします。
  2. 常にデバイス上でキーペアを生成し、公開キーのみを送信してください。こうすることで、サーバーが侵害された場合でも、秘密キーは安全かつ保護されたままになります。これは、バックアップなど、意外な方法で発生する可能性があります。
  3. 他の誰かがサーバーを管理する場合、あなた公開鍵を提供する必要があります。ないキーペアを生成し、秘密キーをあなたに送信します。こうすることで、相手があなたのキーを使ってあなたになりすますことはできません (もちろん、通常は何でもできます)。また、公開キーでは、整合性 (つまり、誰かが公開キーを変更していないこと) のみを保護する必要があります。秘密キーでは、機密性 (つまり、他の誰もキーを取得していないこと) を維持する必要があり、絶対に侵害されていないことを保証することはできません。
  4. 複数のサーバーに接続するために同じ秘密鍵を使用した場合でも、1 つのサーバーが侵害されても他のサーバーが侵害されることはありません (ただし、その秘密鍵をサーバーに送信した場合は除きます。これは絶対に行わないでください)。
  5. ワークステーションが侵害されると、いずれにしても秘密鍵が公開されます。複数の秘密鍵を持っていても、この問題は解決しません (ただし、異なる強力なパスフレーズがあり、そのすべてが攻撃者に利用可能ではない場合を除く)。

これにはいくつか例外がありますが、それほど多くはありません。

答え3

ローカルの ssh はパスワードを尋ねるべきではありませんが、もう一方の端にある ssh サーバーは尋ねるべきでしょう。サーバーがパスワード認証を受け入れないように設定されている可能性があります。私のサーバーでもパスワードは尋ねられません。

答え4

私が見つけたもう一つの原因は、次のとおりです。

Host *
   PreferredAuthentications publickey

(他のユーザーからコピーしたもので~/.ssh/config、「設定」だと思っていた)。実際にはPreferredAuthentications「許可される」方法と順序を指定します。

行を削除するPreferredAuthenticationsか追加してくださいpassword

Host *
   PreferredAuthentications publickey,password

注意: カンマの後にはスペースを入れないでください。

関連情報