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

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

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

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

Q&A

解決済

2回答

972閲覧

AWSへのSSH接続について

if_dap

総合スコア7

Amazon EC2

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

0グッド

1クリップ

投稿2017/12/31 02:10

編集2018/01/01 14:56

やりたいこと

AWSへterminalからSSH接続

やったこと

AWSのコンソール上でec2インスタンスを起動
Elastic IPを割り当て
割り当てているセキュリティーグループでSSHが追加されていることを確認
キーペア(Wordpress.pem)を作成し'~/.ssh配下へ配置
Wordpress.pemの権限を400に

エラー文

$ ssh -i "/Users/user/.ssh/Wordpress.pem" ec2-user@ecx-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com The authenticity of host 'ecx-xx-xxx-xxxx.us-east-2.compute.amazonaws.com ()' can't be established. ECDSA key fingerprint is SHA256:8+kiK6jBAUlNO2Aydz4FPwADJbetrhJzm002dRlOjfI. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'ecx-xx-xxx-xxxx.us-east- 2.compute.amazonaws.com,' (ECDSA) to the list of known hosts. Permission denied (publickey).

というエラーが出ました。もう一度実行してみたところ同じ内容でしたが、それ以降は同じコマンドを実行しても、

Permission denied (publickey).
と一文出るのみになりました。

権限を600に変えてみてもうまくいかず、お手上げ状態です。アドバイスをいただけると嬉しいです。

追記

回答を受けて、インスタンスのキーペア名の箇所が-になっていることに気づき、もう一度インスタンスとキーペアを作成仕直し、作成したキーペアを指定してインスタンスのキーペア名が表示されていることを確認しました。
イメージ説明

その後ssh接続をしようとしたところ、また同じようなエラーが...

$ sudo ssh -i "/Users/user/.ssh/WordPress.pem" ec2-user@ecx-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com
The authenticity of host 'ec2-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com (xx.xxx.x.xxx)' can't be established.
ECDSA key fingerprint is SHA256:grG8qBfR/TRD76KSsKTAhK5/5xYkWg8eIdIDztdTqhI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ecx-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com,xx.xxx.x.xxx' (ECDSA) to the list of known hosts.
Permission denied (publickey).

追記2

-vをつけて実施してみました。

OpenSSH_6.9p1, LibreSSL 2.1.8 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to ec2-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com [18.217.7.231] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: key_load_public: No such file or directory debug1: identity file /Users/user/.ssh/WordPress.pem type -1 debug1: key_load_public: No such file or directory debug1: identity file /Users/user/.ssh/WordPress.pem-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.9 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000 debug1: Authenticating to ec2-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com:22 as 'ec2-user' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:grG8qBfR/TRD76KSsKTAhK5/5xYkWg8eIdIDztdTqhI debug1: Host 'ecx-xx-xxx-x-xxx.us-east-2.compute.amazonaws.com' is known and matches the ECDSA host key. debug1: Found key in /var/root/.ssh/known_hosts:1 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 debug1: Next authentication method: publickey debug1: Trying private key: /Users/user/.ssh/WordPress.pem debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey).

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

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

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

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

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

guest

回答2

0

自己解決

自己解決解決しました。
ec2のコンソールでインスタンスの接続を選択した際に出るユーザー名を確認したところ、ec2-userではなくubuntuでした....
本当に申しわけないです。お手数おかけしました。

投稿2018/01/01 14:56

if_dap

総合スコア7

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

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

0

サーバーの/home/ec2-user/.ssh/authorized_keysにパブリックキーを追加する必要があります。

追記
インスタンスの作成時にデフォルトのKey Pairを選択、または、新規作成したと思います。
インスタンスには、そのPublic Keyが登録済みですので、そのPrivate Keyで接続できます。

追記2
インスタンスを作り直したと言うことですね。
最初のインスタンスはKey Pairが設定されていないようなので、パスワード認証でログイン出来ませんか?
二個目のインスタンスを作成するさい、Key Pairの新規作成時にダウンロードして保存しろと警告が出たはずです。接続にはそれを使用して下さい。
また、sshに-vオプションを付けると詳細なエラーメッセージが出ます。尚、-vは3個まで付けられます。

投稿2017/12/31 02:24

編集2017/12/31 04:18
hichon

総合スコア5737

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

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

if_dap

2017/12/31 02:26

AWSで立ち上げたサーバーにSSH接続できないのにそれ以外でサーバー内にパブリックキーを追加する方法があるのでしょうか?
hichon

2017/12/31 02:43

追記しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問