課題
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 と広い。
与える権限を変えて狭めてあげるとログイン出来る。
実装の流れ
- 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 ~]$