SSH公開鍵はサーバーに送信されません。

SSH公開鍵はサーバーに送信されません。

私は何時間もこの問題に苦しんでいたので、助けてくれてありがとう。

私は2つのサーバーを持っていて、sshOSXの公開鍵を使って問題なく両方のサーバーに接続できるので確信していますsshd_config

両方のサーバーを同期するようにcronジョブを設定しようとしていますが、公開鍵を使用してサーバーB(バックアップ)をサーバーAに接続する必要がありrsyncます。ssh

私の公開鍵が見つからない理由は一生不明です。公開鍵には場所があり~/.ssh/(たとえば/root/.ssh)、AとBに対するすべてのファイル権限が正しいです。

出力は次のとおりです。

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug3: no such identity: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa
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

また、存在しない秘密鍵を探していることに注意してください。

drwx------. 2 root root 4096 May 25 10:15 .
dr-xr-x---. 4 root root 4096 May 24 18:52 ..
-rw-------. 1 root root  403 May 25 01:37 authorized_keys
-rw-------. 1 root root    0 May 25 01:41 config
-rw-------. 1 root root 1675 May 25 02:35 id_rsa_tm1
-rw-------. 1 root root  405 May 25 02:35 id_rsa_tm1.pub
-rw-------. 1 root root  395 May 25 02:36 known_hosts

答え1

宛先ホストの無効なAuthorized_keysファイルは、sshが「私たちはパケットを送信していません」というメッセージを出力し、pubkey認証を使用する代わりにパスワードを要求するもう1つの理由です。

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method

この特別なケースの問題は、.ssh/authorized_keysターゲットホストに貼り付けられた公開鍵データに最初の文字が欠落していることです。

sh-rsa AAAA...

解決策は簡単です。不足している「s」を追加することです。

ssh-rsa AAAA...

だから:-

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.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
...
debug1: Authentication succeeded (publickey).

答え2

SSHのマニュアルページを見てください。

   -i identity_file
          Selects a file from which the identity (private key) for public
          key authentication is read.  The default is ~/.ssh/identity for
          protocol   version   1,   and  ~/.ssh/id_dsa,  ~/.ssh/id_ecdsa,
          ~/.ssh/id_ed25519 and ~/.ssh/id_rsa  for  protocol  version  2.
          Identity files may also be specified on a per-host basis in the
          configuration file.  It is possible to have multiple -i options
          (and  multiple  identities  specified  in configuration files).

またはssh_configのマニュアルページ:

   IdentityFile
          Specifies a file from which the user's DSA, ECDSA,  ED25519  or
          RSA   authentication   identity   is   read.   The  default  is
          ~/.ssh/identity for  protocol  version  1,  and  ~/.ssh/id_dsa,
          ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519 and ~/.ssh/id_rsa for proto‐
          col version 2.  Additionally, any identities represented by the
          authentication  agent  will  be  used for authentication unless
          IdentitiesOnly is set.

キーを指定しないと、一部の特殊ファイル名が試行されていることがわかります。これはログ出力にも表示されるファイルです。

異なる名前のファイルでキーを使用するには、次の3つのオプションがあります。

  • 上記のオプションを使用してファイルを明示的に指定します-i
  • 上記のオプションを使用して、クライアント構成でIdentityFileこのファイルを構成します。
  • エージェントにキーを追加するために使用しますssh-add

対話型セッションの場合、エージェントは最も柔軟です。このオプションはおそらくcron操作の-i最も簡単なオプションです。

答え3

秘密鍵と公開鍵のペアが一致しない場合でも、質問のエラーメッセージ文字列が発生する可能性があります。地域側から。いいえ、まったく話しません。しかし、何が起こっているのかを調べようと長い時間を過ごしただけです。

  • .ssh/mykey.pubリモートシステムAがにコピーされました.ssh/authorized_keys
  • ローカルシステムBには、.ssh/mykeyシステムAの公開鍵と一致する正しい秘密鍵がありますが、代替キーの以前のバージョンである可能性.ssh/mykey.pubがある一致しないファイルもあります。

BからA()へのSSHは、問題のメッセージで失敗します。具体的には、ssh -i mykey ASSHクライアントで開くと、次の内容が表示されます。-vv

秘密鍵を試してみてください:.ssh / mykey
パケットを送信しません。メソッドを無効にします。

実際のキーを試すのではなく、名前が一致するローカル公開鍵ファイルを使用して操作可能であることを確認し、一致しないと実際には何もしないため、これはうそです。両方のデバッグ情報は、実際に問題が何であるかを示していません。

答え4

sshが探すデフォルトのファイル名はとid_rsaですid_rsa.pub

別のファイル名を使用するには、次のように指定する必要があります。ssh_configIdentityFile設定を使用)またはSSH経由コマンドライン 範囲-i

関連情報