Pages

2011/04/25

pem(RSA PRIVATE KEY)からssh-rsa形式の公開鍵を作成する。

sshの鍵認証でauthorized_keysに記載する内容は、通常ssh-keygenで作成したものを使う。

Chefのclient(ここではサーバ上のユーザ)を作成するときに鍵セットができるんだが、Knife sshを使うときにこの秘密鍵を使いまわせると楽だ。
 


ということでauthorized_keysで使われるssh-rsaを、既存のpemから作れないかとssh-keygenのmanを見る。


man ssh-keygen
-- snip --
-i This option will read an unencrypted private (or public) key file in SSH2-compatible format and
print an OpenSSH compatible private (or public) key to stdout. ssh-keygen also reads the RFC
4716 SSH Public Key File Format. This option allows importing keys from several commercial SSH
implementations.
-e This option will read a private or public OpenSSH key file and print the key in RFC 4716 SSH
Public Key File Format to stdout. This option allows exporting keys for use by several commer‐
cial SSH implementations.
-y This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.
-- snip --


なんかここらでできそうね。

やってみる。
# ssh-keygen -y -f ~/.chef/webui.pem
ssh-rsa AAAA(snip ....


Chefが作る形式だと、-yでよかった。
 

このやり方だと秘密鍵が必要なのですが、ssh-rsaはBase64なだけぽいので公開鍵を直接変換したほうが早いこともあるね。
 

0 件のコメント:

コメントを投稿