1
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 5 years have passed since last update.

OpenSSHで作成した鍵がOpenSSLでpemに変換できなかった

Posted at

タイトルが無駄に長いけど、まぁ、そういうことなんですよ。

NGパターン

$ ssh-keygen -t rsa -f ~/.ssh/ssh_key
$ openssl rsa -in ~/.ssh/ssh_key -outform pem > ~/.ssh/ssh_key.pem
$ unable to load Private Key

OKパターン

$ ssh-keygen -t rsa -f ~/.ssh/ssh_key -m PEM
$ openssl rsa -in ~/.ssh/ssh_key -outform pem > ~/.ssh/ssh_key.pem
$ writing RSA key

解説

OpenSSH 7.8で秘密鍵のヘッダが変わったらしい。

# old style
-----BEGIN RSA PRIVATE KEY-----

# new style
-----BEGIN OPENSSH PRIVATE KEY-----

鍵生成時の-m PEMがミソ。これを追加することで、古いPEM形式の鍵を生成できる。OpenSSLで.pemに変換する時は、古い形式のヘッダじゃないと秘密鍵を読み取れないっぽい。

1
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
1
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?