XREA: 楕円 DSA 鍵でログイン

環境の確認

 この手順が記録されたときのローカルホストとリモートホストの環境は

# : ThinkPad X61
$ uname -sr
OpenBSD 5.6
$ ssh -V
OpenSSH_6.7, LibreSSL 2.0

# : XREA
$ uname -sr
Linux 2.6.27.59-smp
$ ssh -V
OpenSSH_6.6p1 OpenSSL 0.9.8za 5 Jun 2014

となっています。

 ECDSA (楕円 DSA) は OpenSSL 5.7 (参照: OpenSSH 5.7 リリースノート)

Changes since OpenSSH 5.6
=========================

Features:

 * Implement Elliptic Curve Cryptography modes for key exchange (ECDH)
   and host/user keys (ECDSA) as specified by RFC5656. ECDH and ECDSA
   offer better performance than plain DH and DSA at the same equivalent
   symmetric key length, as well as much shorter keys.

から対応なので, ローカルホストとリモートホストの OpenSSH のバージョンが 5.7 以上で対応しているかどうか事前に確認しておきましょう.

楕円 DSA 鍵の強度

 The Case for Elliptic Curve Cryptography によれば, 楕円 DSA の 521 ビットは, RSA の 15360 ビット相当の強度があるようです.

1. ホームディレクトリに .ssh ディレクトリを作り, 鍵を生成する.

 ローカルホストのホームディレクトリで .ssh ディレクトリを作成・移動後, ssh-keygen コマンドで秘密鍵のパスフレーズを入力し鍵のペア (公開鍵と秘密鍵) を生成します.

$ cd
$ pwd
/home/your
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen -t ecdsa -b 521
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/your/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/your/.ssh/id_ecdsa.
Your public key has been saved in /home/your/.ssh/id_ecdsa.pub.
The key fingerprint is:
1e:5e:32:27:23:3a:02:6f:fb:e3:b7:66:59:37:aa:77 your@your.domain
The key's randomart image is:
+---[ECDSA 521]---+
|                 |
|                 |
|                 |
|                 |
|.     . S o      |
| o   . +.Oo      |
|  + o  ooo .     |
| . o..= o E      |
|  .oo=o+ .       |
+-----------------+
$ ls
id_ecdsa id_ecdsa.pub

二つの鍵ファイル id_ecdsa (秘密鍵) と id_ecdsa.pub (公開鍵) が生成されました.

2. 認証鍵を XREA にアップロードし, authorized_keys ファイルに登録する.

 先ほど生成した認証鍵のファイル id_ecdsa.pub を, リモートホストである XREA に scp コマンドでアップロードします.

$ scp ./id_ecdsa.pub your@your.com:.
The authenticity of host 'your.com (XXX.XXX.XXX.XXX)' can't be established.
ECDSA key fingerprint is 1e:5e:32:27:23:3a:02:6f:fb:e3:b7:66:59:37:aa:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'your.com,XXX.XXX.XXX.XXX' (ECDSA) to the list of known hosts.
your@your.com's password:
id_ecdsa.pub    100%  274    0.3KB/
$

ssh 関連のコマンド (scp, sftp なども含む) でサーバに接続する際, そのサーバとの接続が初めてのときに限り, 上記のように警告のメッセージが表示されます. 今回は「yes」と入力しリモートホストの公開鍵をローカルホストの known_hosts ファイルに登録しました.

$ pwd
/home/your/.ssh
$ ls
id_ecdsa id_ecdsa.pub known_hosts
$

 次は ssh で XREA にログインし id_ecdsa.pub を authorized_keys に登録します. 今回鍵の登録は初めてなので .ssh と authorized_keys を作成してから id_ecdsa.pub を登録していますが, 既に authorized_keys がある場合は authorized_keys に上書きしないように気をつけてください.

$ ssh your@your.com
your@your.com's password: 
Last login: Thu Feb  5 00:02:32 2015 from your-IP

> cd                                    
> pwd                                   
/virtual/your
> mkdir .ssh                            
> chmod 700 .ssh                        
> cd .ssh                               
> mv ../id_ecdsa.pub ./                 
> touch authorized_keys                 
> cat id_ecdsa.pub >>authorized_keys    
> chmod 600 authorized_keys             
> rm id_ecdsa.pub                       
> logout                                
Connection to your.com closed.

$

 鍵の登録が正しく完了していれば, 秘密鍵のパスフレーズのみで XREA にログインすることができます.

$ ssh your@your.com
Enter passphrase for key '/home/your/.ssh/id_ecdsa': 
Last login: Thu Feb  5 00:04:57 2015 from your-IP

> pwd
/virtual/your
> logout
Connection to your.com closed.

$

以上で, おしまいです.

参考サイト

GitHubユーザーのSSH鍵6万個を調べてみた
SSH接続エラー回避方法:.ssh/known_hostsから特定のホストを削除する/削除しないで対処する3つの方法

さらに詳しく

LinuxでSSH -- 秘密鍵のパスフレーズ入力の省略など.

0 コメント :

コメントを投稿