初めに
dockerコンテナの./sshディレクトリからEC2にsshキーで接続しようとしたら下記のようなエラーが発生。
root@???:~/.ssh# ssh -i "sample_rsa" ec2-user@ec2-??-??-??-??.ap-northeast-1.compute.amazonaws.com
The authenticity of host 'ec2-??-??-??-??.ap-northeast-1.compute.amazonaws.com (??.??.??.??)' can't be established.
ECDSA key fingerprint is SHA???????????????.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-??-??-??-??.ap-northeast-1.compute.amazonaws.com,??.??.??.??' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'sample_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "sample_rsa": bad permissions
ec2-user@ec2-??-??-??-??.ap-northeast-1.compute.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
エラー
どうやらこのエラーは、秘密鍵のパーミッションが644になってて他のユーザーからアクセスできるような権限では使えないよ!
と指摘してるようです。
Permissions 0644 for 'sample_rsa' are too open.
解決
以下のようにパーミッションを変更してあげれば解決できます。
ちなみに600
は、所有者のみ読み書き可能
という権限設定になります。
~/.ssh# chmod 600 sample_rsa
これで再度EC2に接続で成功!
参考記事