- 追加された行はこの色です。
- 削除された行はこの色です。
*概要 [#ne37600e]
Vine Linux 3.1によるサーバ構築 にも書いているように、標準でSSH(Secure Shell)はインストールされており、リモートより操作できますが、外部から接続する場合はパスワード認証だけではちょっと不安です。そこで、鍵交換方式による接続ができるようにします。
なお、ここではすでに[[パスワードによる認証:http://niwaka.ddo.jp/pukiwiki/index.php?Vine%20Linux%203.1%A4%CB%A4%E8%A4%EB%A5%B5%A1%BC%A5%D0%B9%BD%C3%DB#gfde2f8b]]でSSH接続できていることを前提に進めます。
なお、ここではすでに[[パスワードによる認証:http://kayanomori.net/memo/%A5%A4%A5%F3%A5%B9%A5%C8%A1%BC%A5%EB%A4%AA%A4%E8%A4%D3%C0%DF%C4%EA/#gfde2f8b]]でSSH接続できていることを前提に進めます。
*鍵による認証 [#sa3e3694]
**SSH2の鍵を作成 [#i0c6de3c]
鍵を作成するユーザーになる。
# su - test
鍵の作成
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa): ←Enterキーを押す
Created directory '/home/test/.ssh'.
Enter passphrase (empty for no passphrase): ←パスワードを入力
Enter same passphrase again:
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is:
07:8b:30:3c:9f:c3:96:b1:7b:68:4f:8c:cf:ec:e0:6f test@x22
確認
ユーザーディレクトリの.sshディレクトリの中に作成される。
$ ls -l /home/test/.ssh/
合計 8
-rw------- 1 test test 951 Aug 11 15:54 id_rsa ←秘密鍵
-rw-r--r-- 1 test test 218 Aug 11 15:54 id_rsa.pub ←公開鍵
公開鍵の名前変更
$ cd .ssh/
$ mv id_rsa.pub authorized_keys
公開鍵のアクセス権変更
$ chmod 600 authorized_keys
確認
$ ls -l
合計 8
-rw------- 1 test test 218 Aug 11 15:54 authorized_keys ←公開鍵
-rw------- 1 test test 951 Aug 11 15:54 id_rsa ←秘密鍵
**鍵をクライアントに移動する [#u8cbf167]
WinSCPなどでクライアントから接続し、.sshディレクトリにあるid_rsa(秘密鍵)をクライアントに移動する。次回からはこの鍵を使って接続することになる。
#ref(move.png)
右ドラッグして、コピーではなく移動を選択する。
**sshd_configの編集 [#ne90078a]
rootになる。
# su -
Password:
# vi /etc/ssh/sshd_config
>
PubkeyAuthentication yes
公開鍵認証を許可
PasswordAuthentication no
パスワードによる認証を禁止(鍵方式のみ)
**sshdの再起動 [#cd5c353a]
# /etc/rc.d/init.d/sshd restart
sshdを停止中: [ OK ]
sshdを起動中: [ OK ]
これで、パスワードによる認証はできなくなり、鍵を使わないと接続できなくなる。
クライアントからSSHで接続
* コメント [#sb81891f]
#comment