powerdee.com
Google
 
このサイト内 Web
 
カウンタ

OpenSSHサーバの構築

OpenSSHの確認

サーバを遠隔操作する場合、セキュリティを考慮すると暗号化されたSSHでのみ接続できるようにしておきます。 telnetやftpは暗号化せずに平文でやりとりするので、危険です。opensshでtelnet及びscpで接続します。
opensshは、Linuxインストール時に自動的にインストールされています。
インストールされているパッケージを確認します。

$ rpm -qa | grep openssh
openssh-3.6.1p2-33.30.3
openssh-server-3.6.1p2-33.30.3
openssh-askpass-3.6.1p2-33.30.3
openssh-clients-3.6.1p2-33.30.3
openssh-askpass-gnome-3.6.1p2-33.30.3

opensshの設定ファイル

/etc/ssh/sshd_config

設定ファイルに記述されているので、コメントをはずして設定を行います。

PermitRootLogin no              <-- root権限でのログインを禁止
PasswordAuthentication no       <-- 公開鍵方式で認証
PermitEmptyPasswords no         <-- 空パスワードの禁止

再起動して、設定を反映させます。

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

鍵の作成

SSH1とSSH2が作成できますが、ここではセキュリティレベルの高いほうのSSH2を作成します。

  1. 鍵を作成するユーザでログイン
  2. 鍵の作成
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hoge/.ssh/id_rsa):  <-- enter(鍵の保存先)
Created directory '/home/hoge/.ssh'.
Enter passphrase (empty for no passphrase):                    <-- パスフレーズの入力
Enter same passphrase again:                                   <-- パスフレーズの再入力
Your identification has been saved in /home/hoge/.ssh/id_rsa.
Your public key has been saved in /home/hoge/.ssh/id_rsa.pub.
The key fingerprint is:
??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:?? hoge@localhost
  1. 鍵が作成されているのを確認
$ ls -la /home/hoge/.ssh/
合計 32
-rw-------   1 hoge hoge  951  2月 15 16:36 id_rsa             <-- 秘密鍵
-rw-r--r--   1 hoge hoge  238  2月 15 16:36 id_rsa.pub         <-- 公開鍵
  1. 公開鍵をauthorized_keysに追加
$ cd
$ cat ./id_rsa.pub >> ./authorized_keys
$ chmod 600 ./authorized_keys
$ rm ./id_rsa.pub
  1. 秘密鍵をクライアントPCにコピー後、削除
$ rm ./id_rsa

おすすめ書籍


Linux教科書 LPICレベル1 第2版 (Linux教科書)

著者:中島 能和、濱野 賢一朗
出版社:翔泳社(2006-08-11)
価格:¥3,990(税込)
Linuxカーネル2.6解読室

著者:高橋浩和、小田逸郎、山幡為佐久
出版社:ソフトバンククリエイティブ(2006-11-18)
価格:¥5,670(税込)


ページTopへ / ▲Homeへ