SSHで鍵認証設定時にエラーが起きた場合
ローカル側で公開鍵と秘密鍵を生成する。
% ssh-keygen -t rsa -b 2048 Generating public/private rsa key pair. Enter file in which to save the key (/Users/littlebuddha/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/littlebuddha/.ssh/id_rsa. Your public key has been saved in /Users/littlebuddha/.ssh/id_rsa.pub. The key fingerprint is: a1:d0:16:1a:f7:ed:5a:dc:cf:1b:87:29:2b:e4:2c:6a littlebuddha@MacBookPro.local The key's randomart image is: +--[ RSA 2048]----+ | | | =o| | o = o o.B| | . X = + .+| | . E = o o. | | o . . . . | | . | | | | | +-----------------+
公開鍵をサーバー側に転送して、公開鍵を登録する。
% ssh-keygen -i -f ~/id_rsa_2048.pub >> ~/.ssh/authorized_keys
uudecode failed.
そうすると、「uudecode failed.」とエラーが出て、登録ができない。オプションを下記のものにすれば、登録はできるようになるが、パスワード入力無しの鍵認証になってしまうので、それは避けたい。
そもそも「uudecode failed.」は何かを調べたら、下記のことが原因だとわかった。
First of all, you used two dashes instead of one in the options.
http://www.linuxquestions.org/questions/linux-general-1/how-can-i-import-my-rsa-key-646579/#post3172938
Secondly, the -f option is for importing an ssh key and exporting an openssh key. If you are using openssh in both, simply:
cat mykey.pub >> .ssh/authorized_keys
If the server is running a commercial ssh server, then export the openssh key to an RFC 4716 SSH public key format:
ssh-keygen -e -f mykey.pub > my4716key.pub. The server will probably
either accept this form or be able to import it.
要するに、ローカル側とサーバー側で openssh を利用しているのならば、単に追記すれば良いようだ。
$ cat mykey.pub >> .ssh/authorized_keys
ということなので、公開鍵を追記する。
% cat ~/id_rsa.pub >> ~/.ssh/authorized_key
そして、ローカルからSSH ログインを試してみて、正しく接続できた。