質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

4061閲覧

Chefで環境構築した2台目のサーバーにログインできない

redara

総合スコア344

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2016/11/10 08:53

編集2016/11/10 09:33

AWSのインスタンスAを作成し環境設定を行い、同じ環境をChefでインスタンスBにも設定しました。
「A」にはデフォルトユーザー「hoge」以外に「fuga」というユーザーを作成し、どちらも公開鍵認証でログインできる設定にしていました。

Aサーバーにはhogeでもfugaでも公開鍵認証でログインできます。

ssh hoge@Aサーバー -i hoge用の秘密鍵 ⇒ ログイン成功
ssh fuga@Aサーバー -i fuga用の秘密鍵 ⇒ ログイン成功

しかし

Bサーバーにはhogeについては公開鍵認証でログインできますが、
fugaでログインしようとするとログインできません。(鍵ではじかれてる?)

ssh hoge@Bサーバー -i hoge用の秘密鍵 ⇒ ログイン成功
ssh fuga@Bサーバー -i fuga用の秘密鍵 ⇒ 失敗。。

Bサーバーにhoge(デフォルトユーザー)でログインし、/home/fuga/.sshの中を確認してみたところ、
Aサーバーの/home/fuga/.sshにあるものと同一のauthorized_keysが存在し、
パーミッションは600になっており、.sshフォルダのパーミッションも700になっているのは確認しています。

何が考えられるでしょうか。

【追記】
-vvvオプションをつけたときのログです
最終的にパスフレーズを求められています。
うまくいくケースでは特にパスフレーズの要求はありません

OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/tarou/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to Bサーバー port 22.
debug1: Connection established.
debug3: Not a RSA1 key file /Users/tarou/work/fuga用秘密鍵.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Proc-Type:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'DEK-Info:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /Users/tarou/work/fuga用秘密鍵 type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 126/256
debug2: bits set: 497/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /Users/tarou/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 15
debug1: Host 'Bサーバー' is known and matches the RSA host key.
debug1: Found key in /Users/tarou/.ssh/known_hosts:15
debug2: bits set: 508/1024
debug1: ssh_rsa_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: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/tarou/.ssh/id_dsa (0x100125f40)
debug2: key: /Users/tarou/work/fuga用秘密鍵 (0x100126210)
debug2: key: /Users/tarou/work/fuga用秘密鍵 (0x0)
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred 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: Offering public key: /Users/tarou/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Offering public key: /Users/tarou/work/fuga用秘密鍵
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/tarou/work/fuga用秘密鍵
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug3: Not a RSA1 key file /Users/tarou/work/fuga用秘密鍵.
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug2: no passphrase given, try next key
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moonphase

2016/11/10 09:03

次のコマンドの結果はどうなってますか?ssh -vvv fuga@Bサーバー -i fuga用の秘密鍵
redara

2016/11/10 09:36 編集

(書き込みを削除しました)ログをここに記述しましたが、改行が効かなかったので削除します。
guest

回答1

0

ベストアンサー

全く検討違いでしたらすみません。

SSHホスト鍵が同じになっていないか確認できますか?
両サーバのホスト鍵のMD5値が同じでないか確認してみてください。

$ sudo md5sum /etc/ssh/ssh_host_key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX /etc/ssh/ssh_host_key

投稿2016/11/10 09:58

moonphase

総合スコア6621

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

redara

2016/11/11 01:17

ssh_host_keyがなかったので、 ssh_host_rsa_key、ssh_host_dsa_keyで確認してみましたが、 サーバー間でMD5値は異なっていました。
moonphase

2016/11/11 01:39

確認ありがとうございます。 ssh fuga@Aサーバー -i fuga用の秘密鍵 ⇒ ログイン成功 これに -vvv を付けてBサーバとのログの違いを確認できませんか?
redara

2016/11/11 03:26

成功する方では send_pubkey_testのあと Server accepts key : pkalg ssh-rsa blen 279というのが出て Authentication succeededとなるのに対し 失敗するケースでは send_pubkey_testのあと debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey debug1: Trying private key: /Users/tarou/work/fuga用秘密鍵 debug1: PEM_read_PrivateKey failed となって失敗しています。 ログの上部での違いは見当たりませんでした
redara

2016/11/11 03:31

それから念のためサーバーAとサーバーBの それぞれの md5sum /home/fuga/.ssh/authorized_keysを確認しましたが 同一のものでした。
moonphase

2016/11/11 03:40

なんでしょうね。 念のためですが、Bサーバーの指定はIPアドレスで指定してますか? もしホスト名で指定の場合、/etc/hostsやDNSの正引きの結果意図しているものと違うサーバに接続されている可能性があるので、IPアドレスでの指定を試してみてください。 あとは、Bサーバにfugaアカウントがないとか。 気になってるのは「PEM_read_PrivateKey failed 」ですが、、、うーん。
moonphase

2016/11/11 03:44

次の手順で秘密鍵を作成しなおしてもダメでしょうか? cd /Users/tarou/work/ mv fuga用の秘密鍵 fuga用の秘密鍵.orig openssl rsa -in fuga用の秘密鍵.orig -out fuga用の秘密鍵 chmod 600 fuga用の秘密鍵
redara

2016/11/11 04:04

サーバーはIPアドレスで指定しています。 /etc/passwd /etc/groupでそれぞれ確認しましたがユーザーは作られています。 また回答いただいた手順で秘密鍵を作成し直してみましたが、こちらも特に変化がありませんでした。 それから他のマシン(Windows機)からも秘密鍵からppkファイルを作成して試してみましたが、挙動は同じで、Aサーバーではうまくログインでき、Bサーバーではログインできませんでした。「Server refuse our key」というメッセージがPutty上に表示されました。
moonphase

2016/11/11 04:12

Aサーバ、Bサーバの /home/fugaのディレクトのパーミッションはどうなっていますか? Bサーバの/home/fugaのパーミッションが気になります。
redara

2016/11/11 04:34

パーミッションはどちらのサーバーも700でした
moonphase

2016/11/11 04:38

試しにhoge用の公開鍵を/home/fuga/.ssh/authorized_keysに登録して、hoge用秘密鍵でログインできますか?
redara

2016/11/11 04:51

試してみましたがログインできませんでした。
redara

2016/11/11 05:07

ためしに追加でもう1つインスタンスを作成して(サーバーC)、Chefを使わずユーザーの設定とsshの設定を行ったところ、fugaユーザーでうまくログインできました。 気になった点とはしてはサーバーA、サーバーCではhogeでログインしたときに sudo su - fuga でユーザーの変更が可能ですが、サーバーBでユーザーの切り替えを行おうとするとsu: failed to execute /bin/zsh: No such file or directoryと出て切り替えられませんでした。
redara

2016/11/11 05:15

suでユーザーを切り替えられないのは chefでfugaのデフォルトシェルをzshに設定するように記述しているため、そのせいだけかもしれず、あまり関係ないかもしれません。 execute "default zsh" do user "root" command "usermod -s /bin/zsh fuga" end
moonphase

2016/11/11 05:21

試しにzshをインストールしていないサーバのログインシェルを/bin/zshにしたら、 SSHで同じエラーがでました。 サーバーBでyum install zshしたらログインできませんか?
redara

2016/11/11 05:30

入れるようになりました! デフォルトシェルを設定しているのにシェル自体インストールしてないとSSHで入れなくなるということでしたか。。 解決でき、とても助かりました。ありがとうございます
moonphase

2016/11/11 05:36

サーバBのログを確認すべきでしたね。 次のようなログが出ているはずです。 /var/log/secure ... Nov 11 05:20:55 ip-xx-xx-xx-xx sshd[8578]: User ec2-user not allowed because shell /bin/zsh does not exist Nov 11 05:20:55 ip-xx-xx-xx-xx sshd[8578]: input_userauth_request: invalid user ec2-user [preauth] Nov 11 05:20:55 ip-xx-xx-xx-xx sshd[8578]: Connection closed by 192.168.0.111 [preauth] ...
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問