0
0

More than 1 year has passed since last update.

AWS CloudShell でEC2へのログインが出来なくなった

Last updated at Posted at 2023-01-25

課題

AWS CloudShell に鍵ファイルを置いて、EC2へログインを試したらエラーが出てログイン出来ない

[cloudshell-user@ip-x-x-x-x ~]$  ssh -i "hoge.pem" ec2-user@ec2-y-y-y-y.ap-northeast-1.compute.amazonaws.com
<省略>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for 'hoge.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "hoge.pem": bad permissions
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[cloudshell-user@ip-x-x-x-x ~]$

課題の原因

hoge.pem の権限が 0644 と広い。
与える権限を変えて狭めてあげるとログイン出来る。

実装の流れ

  1. AWS CloudShell で hoge.pem の権限を変更

手順1. AWS CloudShell で hoge.pem の権限を変更

[cloudshell-user@ip-x-x-x-x ~]$ ls -l
total 20
-rw-rw-r-- 1 cloudshell-user cloudshell-user 1675 Jan 25 06:41 hoge.pem
[cloudshell-user@ip-x-x-x-x ~]$
[cloudshell-user@ip-x-x-x-x ~]$ chmod 600 hoge.pem
[cloudshell-user@ip-x-x-x-x ~]$
[cloudshell-user@ip-x-x-x-x ~]$ ls -l
total 20
-rw------- 1 cloudshell-user cloudshell-user 1675 Jan 25 06:41 hoge.pem
[cloudshell-user@ip-x-x-x-x ~]$

実装後

ログインを試みた際にエラーは出なくなり、ログイン出来るようになる。

[cloudshell-user@ip-x-x-x-x ~]$ ssh -i "hoge.pem" ec2-user@ec2-y-y-y-y.ap-northeast-1.compute.amazonaws.com

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
8 package(s) needed for security, out of 9 available
Run "sudo yum update" to apply all updates.
[cloudshell-user@ip-x-x-x-x ~]$
0
0
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
0
0