目次



目的

せっかくなのでリモートでメンテを行えるようにする。
クライアントはWindowsXPでPuTTyを利用し、通信はSSHで暗号化する。

準備

インストール

  1. ソースの取得
    # wget -P /usr/local/src http://openssh.linux-mirror.org/portable/openssh-5.2p1.tar.gz

  2. ソースの解凍
    # cd /usr/local/src
    # tar zxvf openssh-5.2p1.tar.gz

  3. コンパイル設定
    configureのヘルプ
    # cd /usr/local/src/openssh-5.2p1
    # ./configure \
    > --prefix=/usr/local/openssh-5.2p1 \
    > --with-tcp-wrappers \
    > --with-ssl-dir=/usr/local/ssl \
    > --with-privsep-user=sshd \
    > --with-privsep-path=/var/empty/sshd

  4. インストール
    # make
    # make install

  5. シンボリックリンクの作成
    # ln -s /usr/local/openssh-5.2p1 /usr/local/ssh

設定

  1. sshd_confの設定
    # vi /usr/local/ssh/etc/sshd_config
    
    #Port 22
    ↓
    Port 22
    
    #SyslogFacility AUTH
    ↓
    SyslogFacility AUTH
    
    #PermitRootLogon yes
    ↓
    PermitRootLogon no                ← rootでのログインを禁止
    
    #AuthorizedKeysFile   .ssh/authorized_keys
    ↓
    AuthorizedKeysFile   .ssh/authorized_keys
    
    #PasswordAuthentication yes
    ↓
    PasswordAuthentication no         ← パスワードでのログインを禁止(鍵方式によるログインのみ許可)
    
    #PermitEmptyPasswords no
    ↓
    PermitEmptyPasswords no           ← パスワードなしでのログインを禁止

  2. 起動スクリプトのコピー
    ソースの中にある起動スクリプトをコピーする
    # cp /usr/local/src/openssh-5.2p1/contrib/redhat/sshd.init /etc/rc.d/init.d/sshd

  3. sshd起動スクリプトの編集
    # vi /etc/rc.d/init.d/sshd
    
    KEYGEN=/usr/bin/ssh-keygen
    ↓
    KEYGEN=/usr/local/ssh/bin/ssh-keygen
    
    SSHD=/usr/sbin/sshd
    ↓
    SSHD=/usr/local/ssh/sbin/sshd
    
    RSA1_KEY=/etc/ssh/ssh_host_key
    ↓
    RSA1_KEY=/usr/local/ssh/etc/ssh_host_key
    
    RSA_KEY=/etc/ssh/ssh_host_rsa_key
    ↓
    RSA_KEY=/usr/local/ssh/etc/ssh_host_rsa_key
    
    DSA_KEY=/etc/ssh/ssh_host_dsa_key
    ↓
    DSA_KEY=/usr/local/ssh/etc/ssh_host_dsa_key
    ※SSHサーバー起動時に以下のワーニングメッセージが出力されることの対処
    Starting sshd:WARNING: initlog is deprecated and will be removed in a future release
    〜start()の中〜
    initlog -c "$SSHD $OPTIONS" && success || failure
    ↓
    #initlog -c "$SSHD $OPTIONS" && success || failure    ← 元の行をコメントアウト
    $SSHD $OPTIONS && success || failure                  ← 代わりに追加

  4. sshd起動スクリプトの登録
    # chmod 755 /etc/rc.d/init.d/sshd
    # chkconfig --add sshd
    # chkconfig sshd on
    # chkconfig --list sshd
    sshd            0:off   1:off   2:off   3:on    4:on    5:on    6:off

鍵の作成

  1. 一般ユーザーで作成する
    # su - XXXXX
    $ /usr/local/ssh/bin/ssh-keygen -t rsa                   ← SSH2で公開鍵・秘密鍵を作成
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/XXXXX/.ssh/id_rsa): ← 鍵のファイル名を入力(空EnterでOK)
    Created directory '/home/XXXXX/.ssh'
    Enter passphrase (empty for no passphrase):                  ← パスフレーズの入力
    Enter same passphrase again:                                 ← パスフレーズの再入力
    Your identification has been saved in /home/XXXXX/.ssh/id_rsa.
    Your public key has been saved in /home/XXXXX/.ssh/id_rsa.pub.
    The key fingerprint is:
    〜鍵情報が表示される〜

  2. 作成された鍵の確認
    $ cd .ssh
    $ ls -la
    合計 16
    drwx------   2 XXXXX XXXXX 4096  3月  8 21:22 .
    drwx------  16 XXXXX XXXXX 4096  3月  8 20:33 ..
    -rw-------   1 XXXXX XXXXX  951  3月  8 21:22 id_rsa      ← 秘密鍵
    -rw-r--r--   1 XXXXX XXXXX  241  3月  8 21:22 id_rsa.pub  ← 公開鍵

  3. 公開鍵の名前の変更
    authorized_keysが既存の場合
    $ cd ~/.ssh
    $ cat id_rsa.pub >> authorized_keys 
    $ rm -f ~/.ssh/id_rsa.pub                                 ← 元の鍵を削除
    authorized_keysがない場合
    $ cd ~/.ssh
    $ mv id_rsa.pub authorized_keys

  4. 公開鍵の権限の変更
    $ chmod 400 ~/.ssh/authorized_keys

  5. フロッピーにコピー
    id_rsaファイルをフロッピーにコピーする。(フロッピーのマウント
    # cp /home/XXXXX/.ssh/id_rsa /mnt/floppy
    フロッピーにコピーされたid_rsaファイルを使用してPuTTyの接続設定を行う。

トップ   編集 凍結解除 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-05-10 (水) 20:53:50