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

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

新規登録して質問してみよう
ただいま回答率
85.48%
Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

Q&A

1回答

620閲覧

SSHを利用してのEC2へのログインができなくなってしまった

AK12

総合スコア32

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

0グッド

3クリップ

投稿2019/07/06 14:59

参考サイト

https://qiita.com/naoki_mochizuki/items/814e0979217b1a25aa3e
こちらのサイトを参考にec2-userでログインを行うとしたところ、
下記内容が表示されるようになりました。

$ ssh -v .ssh/key_test.pem ec2-user@52.194.94.200 OpenSSH_7.6p1, LibreSSL 2.6.2 debug1: Reading configuration data /Users/user_name/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 48: Applying options for * debug1: Connecting to .ssh/key_test.pem port 22. ssh: Could not resolve hostname .ssh/key_test.pem: -65540

もともとうまくいっていたのですが、別の工程で色々試しているうちに、ログイン自体もできなくなってしまったという形です。
うまくいっていた時との違いとして、もともと key_test.pemのファイルが開くことができていたのですが、
今は開こうとすると、エラーが起きました。項目を読み込めません。とキーチェーンアクセスの画面がでています。

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

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

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

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

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

guest

回答1

0

こんばんは。

Could not resolve hostname .ssh/key_test.pem: -65540

のメッセージなので...。
鍵の指定の仕方は問題ありませんか?以下ではNGでしょうか?

bash

1ssh -v -i ~/.ssh/key_test.pem ec2-user@52.194.94.200

EC2自体はIPの変更はないかと思いますが、合わせて確認してみてくださいね。

投稿2019/07/06 15:07

suama

総合スコア1997

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

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

AK12

2019/07/06 15:20

早速回答頂きありがとうございます 下記内容が出力されました $ ssh -v -i ~/.ssh/key_test.pem ec2-user@52.194.94.200 OpenSSH_7.6p1, LibreSSL 2.6.2 debug1: Reading configuration data /Users/user_name/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 48: Applying options for * debug1: Connecting to 52.194.94.200 port 22. debug1: Connection established. debug1: key_load_public: No such file or directory debug1: identity file /Users/user_name/.ssh/key_test.pem type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/user_name/.ssh/key_test.pem-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.6 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 52.194.94.200:22 as 'ec2-user' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:F4Z6eVuOo+HnT/yPAnGugW7VmorD+WrQcvXaRGJmfEw debug1: Host '52.194.94.200' is known and matches the ECDSA host key. debug1: Found key in /Users/user_name/.ssh/known_hosts:1 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Next authentication method: publickey debug1: Trying private key: /Users/user_name/.ssh/key_test.pem debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: No more authentication methods to try. ec2-user@52.194.94.200: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
suama

2019/07/06 15:46

ありがとうございます! ~/.ssh/ の下に鍵があるという前提で提示してしまいましたが、key_test.pem は、想定の場所にありますでしょうか? ~/.ssh/ ではない場所に置いていたりしますか? 別であれば正しい場所を -i の後ろに指定してみてください。
AK12

2019/07/06 21:28

パスは間違っていないです。 うまくいっていたときと、同じ内容で行っているので…
suama

2019/07/06 23:40

おはようございます!ありがとうございます! 鍵の場所やパーミッションが問題ないとしたら、ユーザ名か接続先のIPに間違いがないかとかでしょうか。 ユーザ名も前回もec2-userでOKでしたでしょうか?(AMI, OSにより異なるので)
AK12

2019/07/09 11:28

返信遅くなり申し訳ございません。 状況は改善されませんでした。 ちなみに、別のインスタンスに別のキーペアを作成し、同じ場所でsshを実行した際は問題ございませんでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問