0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【2022年08月版】 秘密鍵の暗号化を解除できない openssl/ssh-keygen

Posted at

【2022年08月版】 秘密鍵の暗号化を解除できない

はじめに

  • 秘密鍵の暗号化を解除しようと openssl rsa したら、 unable to load Private Key と表示され、できない。。。

前提条件

  • ssh-keygen で秘密鍵を作成した

  • 秘密鍵のヘッダがなんか違う

  • 秘密鍵のヘッダ

-----BEGIN OPENSSH PRIVATE KEY-----
  • 想定しているヘッダ
-----BEGIN RSA PRIVATE KEY-----
  • openssl rsa で暗号化を解除しようとすると、unable to load Private Key と表示されてエラーになる
% openssl rsa -in privatekey.pem -out decrypt.pem
unable to load Private Key
 :
 :
 :
libressl/libressl-2.8/crypto/pem/pem_lib.c:684:Expecting: ANY PRIVATE KEY
  • 秘密鍵のパーミッションは 600 になっていて、読める・書ける

解除方法

  • ssh-keygen で作成した秘密鍵は openssl rsa で解除できない

  • ssh-keygen で解除する

  • 秘密鍵ファイルは privatekey.pem 、なんでもいいけど

  • 解除方法

% ssh-keygen -p -f privatekey.pem
Enter old passphrase: 
Key has comment 'user@machine'
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase.

その他

  • パーミッションを間違っているとエラーになるので確認
% ssh-keygen -p -f privatekey.pem
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0666 for 'privatekey.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Failed to load key privatekey.pem: bad permissions

さいごに

かんたんでしたね

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?