LoginSignup
3
1

More than 5 years have passed since last update.

EC2のAMIはベースOSの種類でログインユーザー名が異なる

Last updated at Posted at 2018-10-21

wordpressのサイトをEC2で作りたいと思い、AMIからbitnami-wordpresのイメージを使ってデプロイを行いました。作成方法は以下の通りです。

  • インスタンス作成時にAMIカスタムイメージを選択(bitnami-wordpress)
  • 既存で作成していたpemファイルを選択
  • インスタンス起動

これでログインすると以下のようなエラーが出ました。

[hogenoMacBook-ea:~/.ssh $ ssh wordpress-aws01
ec2-user@ec2-52-68-14-142.ap-northeast-1.compute.amazonaws.com: Permission denied (publickey).

ssh接続はconfigファイルで管理しており、こちらの設定はこんな感じです。

#wordpress-aws01
  Host         wordpress-aws01
  HostName     ec2-52-68-14-142.ap-northeast-1.compute.amazonaws.com
  User         ec2-user
  IdentityFile ~/.ssh/authorized_keys/test-aws01.pem

今までの経験上あるあるの間違いは

  • ディレクトリ、pemファイルのパーミッション
  • 異なるpemファイルを利用している

なので今回も確認してみました。

[hogenoMacBook-ea:~/.ssh $ ls -la
total 16
drwx------   5 hoge  staff  160 Oct 21 15:12 .
drwxr-xr-x+ 26 hoge  staff  832 Oct 21 15:12 ..
drwx------   3 hoge  staff   96 Jul 21 12:39 authorized_keys

authorized_keysのディレクトリは700になっているので所有者にリード、ライト、実行権限があるので問題ないです。

[hogenoMacBook-ea:~/.ssh/authorized_keys $ ls -la
-rw-------  1 hoge  staff  1692 Jul 21 12:39 test-aws01.pem

pemファイルのほうも問題なさそうです。
他のEC2も同じpemファイルで接続しているので、異なるpemを使用している線はないです。

そんな中いろいろ探しているとまずEC2でsshエラーが出たときはAWSのこのサイトを見ましょうということが書いてありました。

インスタンスへの接続に関するトラブルシューティング

スクロールしていくとAMIによって標準のユーザー名が異なると書いてありました。

Amazon Linux 2 または Amazon Linux AMI の場合は、ユーザー名は ec2-user です。
Centos AMI の場合、ユーザー名は centos です。
Debian AMI の場合は、ユーザー名は admin または root です。
Fedora AMI の場合、ユーザー名は ec2-user または fedora です。
RHEL AMI の場合は、ユーザー名は ec2-user または root のどちらかです。
SUSE AMI の場合は、ユーザー名は ec2-user または root のどちらかです。
Ubuntu AMI の場合は、ユーザー名は ubuntu です。

なるほど、原因はこれですね。bitnami-wordpressのAMIを調べてみるとubuntuになっていたので、configファイルを修正します。

#wordpress-aws01
  Host         wordpress-aws01
  HostName     ec2-52-68-14-142.ap-northeast-1.compute.amazonaws.com
  User         ubuntu          //es2-userからubuntuへ変更  
  IdentityFile ~/.ssh/authorized_keys/test-aws01.pem

変更してからsshしてみます。

[hogenoMacBook-ea:~/.ssh $ ssh wordpress-aws01
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-1065-aws x86_64)
*** System restart required ***
       ___ _ _                   _
      | _ |_) |_ _ _  __ _ _ __ (_)
      | _ \ |  _| ' \/ _` | '  \| |
      |___/_|\__|_|_|\__,_|_|_|_|_|

  *** Welcome to the Bitnami WordPress 4.9.8-0 ***
  *** Documentation:  https://docs.bitnami.com/aws/apps/wordpress/ ***
  ***                 https://docs.bitnami.com/aws/ ***
  *** Bitnami Forums: https://community.bitnami.com/ ***
Last login: Sun Oct 21 06:12:21 2018 from 150.249.202.145
bitnami@ip-172-31-35-129:~$

AMIのログインユーザーは全部ec2-userだと思ってました。OS種別毎にユーザー名が異なるみたいなのでこれからは気をつけたいと思います。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1