LoginSignup
3
3

More than 3 years have passed since last update.

OpenSSHで生成したed25519形式の秘密鍵はputtygenで読み込めない

Last updated at Posted at 2018-11-06

そんな話があるか!と思いググっていると、stackoverflowに先駆者がおりました。
人生の疑問は大体stackoverflowに書いてある!

down vote

The command in the above answer is just printing public key portion in RFC4716 format.
At some point, ssh-keygen generates openssh private key which doesn't use cipher supported by puttygen.
ssh-keygen doesn't provide option to specify cipher name to encrypt the resulting openssh private key.
There is a workaround: remove the passphrase from the key before importing into puttygen.

$ cp ~/.ssh/id_ed25519 ~/.ssh/id_ed25519-for-putty
$ ssh-keygen -p -f ~/.ssh/id_ed25519-for-putty

Enter old passphrase:
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:

Then, use puttygen to convert ~/.ssh/id_ed25519-for-putty into .ppk and set the passphrase from puttygen.
Don't forget to shred and remove ~/.ssh_id_ed25519-for-putty afterwards for obvious reason.

とのことなので生成した後に空パスにしてputtygenに放り込めばおkです。

上記に関しての補記

コメントより、指摘を頂いたので修正させていただきました。

OpenSSH 7.6でOpenSSH形式の秘密鍵の暗号化に使う方式がaes256-cbcからaes256-ctrに変わったからですね。PuTTY 0.70まではaes256-cbc(と非暗号化であるnone)にしか対応していませんでした。
なので、OpenSSH 7.6より前のバージョンで生成した鍵ならば暗号化されていてもPuTTY 0.70で読めますし、OpenSSH側の変更に合わせてPuTTY側でもaes256-ctrでの暗号化に対応したので対応したので、PuTTY 0.71以降ならばではOpenSSH 7.6以降で生成した鍵も読めます。

単にputtyのバージョンが古くて対応していなかっただけで、現在では読み込めるようです。下の解決方法を試す前に、puttyバージョンアップも検討してみて下さい!

解決方法

1: ssh-keygenで普通にed25519形式のキーを生成します。ここでは普通にパスワードを入力して平気です。

cd ~/.ssh
ssh-keygen -t ed25519 -C "コメント(メルアドとか入れとく)"

2: 加工するのでコピーを取る

cp ~/.ssh/id_ed25519 ~/.ssh/id_ed25519-for-putty

3: 2.で作成したコピーを編集して、パスワードを空にしましょう。

ssh-keygen -p -f ~/.ssh/id_ed25519-for-putty

Enter old passphrase: <your passphrase>
Enter new passphrase (empty for no passphrase): <press Enter>
Enter same passphrase again: <press Enter>

// 後始末
sudo chown あなたのユーザ名:あなたのユーザ名 id_ed25519
sudo chmod 600 id_ed25519

5: 生成したid_ed25519-for-puttyをwindowsに移動させて、puttygenにimportします!

終わり!

参考URL: stackoverflow

3
3
2

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
3
3