LoginSignup
4
2

More than 3 years have passed since last update.

SSHで鍵を指定したらWARNING: UNPROTECTED PRIVATE KEY FILE!となった時の対応方法

Last updated at Posted at 2019-06-19
  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017

事象 : SSHで鍵を指定してポートフォワードしようとしたら怒られた

$ ssh -N -L 1521:10.0.1.2:1521 -i ~/.ssh/key.pem -4 ec2-user@1.23.45.67
The authenticity of host '1.23.45.67 (1.23.45.67)' can`t be established.
ECDSA key fingerprint is SHA256:xxxxx.....
ECDSA key fingerprint is MD5:xx:xx:....
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '1.23.45.67' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for '/home/ponsuke/.ssh/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 "/home/ponsuke/.ssh/key.pem": bad permissions
Permission denied (publickey).

原因 : 指定してる鍵の権限が広すぎるから

仮想マシンの起動

対応 : 権限を変更する

$ sudo chmod 400 .ssh/key.pem
[sudo] password for ponsuke:

$ ls -l .ssh/
total 8
-r--------. 1 ponsuke ponsuke 1696  6月 13 12:00 key.pem

$ ssh -N -L 1521:10.0.1.2:1521 -i ~/.ssh/key.pem -4 ec2-user@1.23.45.67
4
2
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
4
2