VineLinux3.x/init/鍵交換方式によるSSH接続 のバックアップ(No.1)


概要

Vine Linux 3.1によるサーバ構築 にも書いているように、標準でSSH(Secure Shell)はインストールされており、リモートより操作できますが、外部から接続する場合はパスワード認証だけではちょっと不安です。そこで、認証鍵による接続ができるようにします。

なお、ここではすでにパスワードによる認証で接続できていることを前提に進めます。

鍵による認証

もっとセキュリティを強化したいとき(外部から接続する場合)

SSH2の鍵を作成

鍵を作成するユーザーになる

# 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 .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				←秘密鍵

鍵をクライアントに移動する

WinSCPなどでクライアントから接続し、.sshディレクトリにあるid_rsa(秘密鍵)をクライアントに移動する。次回からはこの鍵を使って接続することになる。

move.png

右ドラッグしてコピーではなく移動を選択する。

sshd_configの編集

rootになる

# su -
Password:
# vi /etc/ssh/sshd_config
PubkeyAuthentication yes
公開鍵認証を許可
PasswordAuthentication no
パスワードによる認証を禁止(鍵方式のみ)

sshdの再起動

# /etc/rc.d/init.d/sshd restart
sshdを停止中:                                              [  OK  ]
sshdを起動中:                                              [  OK  ]

コメント

コメントはありません。 鍵交換方式によるSSH接続/コメント?

お名前: