網頁

2023/2/20

AWS EC2 instance SSH連線 WARNING: UNPROTECTED PRIVATE KEY FILE

解決本機使用SSH連線到EC2 instance時出現WARNING: UNPROTECTED PRIVATE KEY FILE無法連線。


例如下面以my-key.pem連線到EC2 instance出現WARNING: UNPROTECTED PRIVATE KEY FILE無法連線。

~/..% ssh -i "my-key.pem" ec2-user@ec2-52-194-232-181.ap-northeast-1.compute.amazonaws.com
The authenticity of host 'ec2-52-194-232-181.ap-northeast-1.compute.amazonaws.com (52.194.232.181)' can't be established.
ED25519 key fingerprint is SHA256:8aHs7koEnJ7Wwn8CTE8p4Zw1N2nDU6x318c7vAXku+4.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-52-194-232-181.ap-northeast-1.compute.amazonaws.com' (ED25519) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'my-key.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 "my-key.pem": bad permissions

my-key.pem所在目錄輸入chmod 400 my-key.pem限縮此key pair金鑰檔的權限即可。

~/..% chmod 400 my-key.pem

修改後即可成功SSH連線到EC2 instance

~/..% ssh -i "my-key.pem" ec2-user@ec2-52-194-232-181.ap-northeast-1.compute.amazonaws.com

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

https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-172-31-8-197 ~]$


沒有留言:

張貼留言