SSH認証鍵でFreeNASにログインする

どうしようもないことで詰まったのでメモしておく。

FreeNASのWebGUIや鍵作成ソフト等は使いません。使わなくても大丈夫です。まずTerminal等からFreeNASサーバにSSHへパスワードでログインし、公開鍵と秘密鍵のペアを作成する。

hoges-MacBook:~ hoge$ ssh -l hoge 192.168.11.20
hoge@192.168.11.20's password: 
Last login: Fri Jan 27 12:05:01 2012 from 192.168.11.19
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
	The Regents of the University of California.  All rights reserved.

FreeBSD 8.2-RELEASE-p6 (FREENAS.i386) #0: Wed Jan 18 17:08:54 PST 2012

	FreeNAS nanobsd (c) 2009-2010, The FreeNAS Development Team
	All rights reserved.
	FreeNAS is under the modified BSD license.

	For more information, documentation, help or support, go here:
 	http://freenas.org
Welcome to FreeNAS
[hoge@freenas ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/mnt/data/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /mnt/data/.ssh/id_rsa.
Your public key has been saved in /mnt/data/.ssh/id_rsa.pub.
The key fingerprint is:
ad:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx hoge@freenas.local
The key's randomart image is:
+--[ RSA 2048]----+
|              ...|
|             ....|
|               ..|
|         ........|
|        .........|
|         ........|
|        .........|
|                 |
|                 |
+-----------------+
[hoge@freenas ~]$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
[hoge@freenas ~]$ exit
logout
Connection to 192.168.11.20 closed.

いろいろググると、FreeNASはOpenSSH形式のDSAキーでないといけないみたいな記述があるけど、RSAキーでも普通に成功しました。このようにサーバ上で鍵を作成せずともPuTTy等でも作成できるとは思いますが、試していません。めんどk(ry

書いていないけど、~/.sshディレクトリとauthorized_keysのパーミッションをそれぞれ700と600にする。あとホームディレクトリのパーミッションが700になっていることも確認しておく。ここで詰まって、Permission deniedしまくっていました…orz

あとはクライアントに秘密鍵をコピーさせ、ログインするだけです。Macで作業しているので、Windowsなどの他環境とは異なります。まぁやってることは変わらないので特に問題ないと思います。

hoges-MacBook:~ hoge$ scp -p hoge@192.168.11.20:~/.ssh/id_rsa ~/.ssh
hoge@192.168.11.20's password: 
id_rsa           100% 1766     1.7KB/s   00:00    
hoegs-MacBook:~ hoge$ ssh -l hoge 192.168.11.20
Identity added: /Users/hoge/.ssh/id_rsa (/Users/hoge/.ssh/id_rsa)
Last login: Fri Jan 27 12:38:54 2012 from 192.168.11.19
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
	The Regents of the University of California.  All rights reserved.

FreeBSD 8.2-RELEASE-p6 (FREENAS.i386) #0: Wed Jan 18 17:08:54 PST 2012

	FreeNAS nanobsd (c) 2009-2010, The FreeNAS Development Team
	All rights reserved.
	FreeNAS is under the modified BSD license.

	For more information, documentation, help or support, go here:
 	http://freenas.org
Welcome to FreeNAS
[hoge@freenas ~]$ yattane taechan

WindowsでWinSCPから認証鍵ログインする場合は、さきほど作成した秘密鍵をPuTTyでロードし、.ppkな秘密鍵を作成すればおkです。パーミッションという、超基本的なところで詰まるなんて…だめだこりゃ。もっと勉強します。