3

ssh 公開鍵を使用して1 つのEC2 インスタンスから別の EC2 インスタンスに接続しようとしていて、非常に苦労しています。

シナリオは次のとおりです。スクリプトで、ボックス 1 のファイルをボックス 2 scp にする必要があります。このスクリプトは、パスワードなしで scp できる必要があるため、公開鍵をセットアップする必要があります。

ボックス2で実行ssh-keygen –t rsaして生成id_rsaし、ボックス1にid_rsa.pub コピーしました.sshに移動して実行し、両方のボックス ですべての.sshディレクトリの権限を700に変更し、ファイル自体を600に変更しました。ボックス 1 の sshd_config 設定を次のように変更しました。id_rsa.pubid_rsa.pubcat id_rsa.pug >> authorized_keys

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

そして、sshを再起動しました

/sbin/service sshd restart

box1 から box1 に scp または ssh しようとすると、次のエラーが表示されます。

Address 67.22.33.1 maps to ec2-67-22-33-1.compute-1.amazonaws.com, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
tomcat@tomcat1.****.com's password:

何か案は?


私はその変更を行い、tomcat1 に対して scp を試みましたが、失敗しました。出力は次のとおりです。

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to tomcat1.****.com [67.22.33.15] port 22.
debug1: Connection established.
debug1: identity file /home/tomcat/.ssh/identity type -1
debug1: identity file /home/tomcat/.ssh/id_rsa type 1
debug1: identity file /home/tomcat/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host 'tomcat1.****.com (67.22.33.15)' can't be established.
RSA key fingerprint is 5a:3e:fe:be:b8:0e:05:63:bf:ab:c8:4f:e5:91:db:a0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'tomcat1.****.com,67.22.33.15' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: Trying private key: /home/tomcat/.ssh/identity
debug1: Offering public key: /home/tomcat/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/tomcat/.ssh/id_dsa
debug1: Next authentication method: password
4

7 に答える 7

1

承認されたキーラインは

AuthorizedKeysFile     %h/.ssh/authorized_keys

サーバーがサーバーに対して間違ったディレクトリを探しています。

于 2011-03-09T20:31:53.280 に答える
1

UPDATE - FIXED IT

restorecon -R -v -d /root/.ssh

This is a known issue with RH where directories get mislabelled and PAM prevends sshd from reading authorized_hosts when run as init script. You'll see the errors if you stumble across /var/log/audit/audit.log. Rare it seems but painful when it happens!

More details at https://bugzilla.redhat.com/show_bug.cgi?id=499343

ORIGINAL POST

I've just hit what looks like exactly this problem. I had a poorly tuned VirtualBox (I hadn't told vbox to use 64bit) -- which when I cloned and restarted (in vbox RedHat 64-bit mode), started asking me for a password.

The original image was fine -- with identical settings -- so I think the suggestion of being networking-related might be relevant, or else to do with server keys.

The weird thing however is that if on the box, I kill the sshd process which autostarted, then manually run /usr/sbin/sshd as root, I can log in passwordless fine. A silly workaround, but usable.

So it is an /etc/init.d/sshd issue. But I haven't been able to track down what it is ... have tried chucking out most of the stuff in that script but it still prompts for password when invoked as /etc/init.d/sshd start but not when at /usr/sbin/sshd.

Maybe these comments can help, and someone can then help further!?

于 2012-11-02T19:06:34.107 に答える
0

~/.ssh/known_hosts から box1 の IP を削除して、更新してみてください。おそらく、「中間者」攻撃の可能性があるため、ssh はキー認証を無効にします。

解決しない場合 GSSAPIAuthentication no は、/etc/ssh/ssh_config ファイルに次の行を追加してください。

于 2011-03-09T20:41:34.660 に答える
0

このリンクはあなたの問題を解決すると思います。私はそれを使用して、ssh がログインしない問題を解決します。キーポイントは、ssh root@node02 'restorecon -R -v /root/.ssh' を実行することです。このコマンドは SE http://blog.firedaemon.com/2011/07/27/passwordless-root-ssh-public-を修正します。 key-authentication-on-centos-6/

于 2011-12-21T05:24:10.400 に答える
0

私はまったく同じ問題を抱えていて、午後ずっと頭を悩ませていました. 小さな sshd_config ファイルの問題であることが判明しました。

最初に、リモート ホストの.sshフォルダーのアクセス mod をユーザー アクセスのみに変更します。

chmod 700 ~/.ssh

次に、/etc/ssh/sshd_config に移動し、に変更StrictModes yesStrictModes noます。コメントアウトされている場合は、具体的にStrictModes noファイルに追加してください。

これで問題は解決しました。

于 2014-02-08T01:22:55.010 に答える
0

前の手順を実行した後、.ssh フォルダーでアクセス許可を「..」に設定する必要がありました。

~/.ssh を持っていたら:

drwx------ 2 ビルド ビルド 4096 11 月 4 日 14:35 。

drwx------ 6 ビルド ビルド 4096 11 月 4 日 14:34 ..

-rw------- 1 ビルド ビルド 400 11 月 4 日 14:35authorized_keys

出来た!

ありがとう。ダミアン

于 2013-11-04T14:27:39.833 に答える