ページ「Ntp Howto」と「OpenSSH 6.1p1」の間の差分

提供:あべたけの覚書
(ページ間の差分)
ナビゲーションに移動 検索に移動
(ページの作成:「Network Time Protocol(ネットワーク・タイム・プロトコル)は、ネットワークに接続される機器において、機器が持つ時計を正しい時刻へ同期するための通信プロトコル。 == 目的 == 時刻の同期。 == インストール == <pre> # yum install ntp </pre> == 設定 == <ol> <li>'''ntp.confの修正'''<br/> <syntaxhighlight lang="bash"> [root@hoge ~]# vi /etc/ntp.conf #restrict 192.168.1.0 mask 255.255.255…」)
 
(ページの作成:「==目的== せっかくなのでリモートでメンテを行えるようにする。<br> クライアントはWindowsXPで[http://www.chiark.greenend.org.uk/%7Esgtatham/putty/ PuTTy]を利用し、通信はSSHで暗号化する。 ==準備== <ul> <li>[http://www.gzip.org/zlib/ zlib] <syntaxhighlight lang="bash"> [root@XXXXX ~]# yum install zlib-devel </syntaxhighlight > <br> </li> <li>tcp_wrappers-devel <syntaxhighlight lang="bash"> [root@XXXXX ~]# yum install tc…」)
 
1行目: 1行目:
Network Time Protocol(ネットワーク・タイム・プロトコル)は、ネットワークに接続される機器において、機器が持つ時計を正しい時刻へ同期するための通信プロトコル。
==目的==
せっかくなのでリモートでメンテを行えるようにする。<br>
クライアントはWindowsXPで[http://www.chiark.greenend.org.uk/%7Esgtatham/putty/ PuTTy]を利用し、通信はSSHで暗号化する。


== 目的 ==
==準備==
時刻の同期。
<ul>
<li>[http://www.gzip.org/zlib/ zlib]
<syntaxhighlight lang="bash">
[root@XXXXX ~]# yum install zlib-devel
</syntaxhighlight >
<br>
</li>
<li>tcp_wrappers-devel
<syntaxhighlight lang="bash">
[root@XXXXX ~]# yum install tcp_wrappers-devel
</syntaxhighlight >
<br>
</li>
<li>[http://www.openssl.org/ OpenSSL]
</li>
</ul>


== インストール ==
==インストール==
<pre>
<ol>
# yum install ntp
<li>'''ソースの取得'''
</pre>
<syntaxhighlight lang="bash">
 
[root@XXXXX ~]# wget -P /usr/local/src http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-6.1p1.tar.gz
== 設定 ==
</syntaxhighlight >
<br>
</li>
<li>'''ソースの解凍'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# cd /usr/local/src
[root@XXXXX ~]# tar zxvf openssh-6.1p1.tar.gz
</syntaxhighlight >
<br>
</li>
<li>'''コンパイル設定'''<br/>
([[OpenSSH 6.1p1のconfigureヘルプ]])
<syntaxhighlight lang="bash">
[root@XXXXX ~]# cd /usr/local/src/openssh-6.1p1
[root@XXXXX ~]# ./configure \
> --prefix=/usr/local/openssh-6.1p1 \
> --with-tcp-wrappers \
> --with-ssl-dir=/usr/local/ssl \
> --with-privsep-user=sshd \
> --with-privsep-path=/var/empty/sshd
</syntaxhighlight >
<br>
'''tcp_wrappers-devel''' がないとconfigureの途中で怒られる。
<syntaxhighlight lang="bash">
checking for libwrap... configure: error: *** libwrap missing
</syntaxhighlight >
<br>
</li>
<li>'''インストール'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# make
[root@XXXXX ~]# make install
</syntaxhighlight >
<br>
</li>
<li>'''シンボリックリンクの作成'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# ln -s /usr/local/openssh-6.1p1 /usr/local/ssh
</syntaxhighlight >
<br>
</li>
</ol>
==設定==
<ol>
<ol>
<li>'''ntp.confの修正'''<br/>
<li>'''sshd_confの設定'''<br/>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
[root@hoge ~]# vi /etc/ntp.conf
[root@XXXXX ~]# vi /usr/local/ssh/etc/sshd_config


  #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  # Port 22
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap ← 追加(内部からの時刻同期を許可)
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
時刻同期先NTPサーバーを変更
Port 22
server -4 ntp.nict.jp # 日本標準時を提供しているNTPサーバー(stratum 1)
 
server -4 ntp.jst.mfeed.ad.jp # 上記サーバーと直接同期しているNTPサーバー(stratum 2)
# SyslogFacility AUTH
server -4 プロバイダのNTPサーバー名 # プロバイダのNTPサーバー
SyslogFacility AUTH
 
# PermitRootLogin yes
PermitRootLogin no                ← rootでのログインを禁止
 
# PasswordAuthentication yes
PasswordAuthentication no        ← パスワードでのログインを禁止(鍵方式によるログインのみ許可)
 
# PermitEmptyPasswords no
PermitEmptyPasswords no          ← パスワードなしでのログインを禁止
</syntaxhighlight >
</syntaxhighlight >
<br>
<br>
</li>
</li>
<li>'''手動で時刻合わせ。'''<br/>NTPサーバー起動時に大幅に時刻がずれているとNTPサーバーが起動できないので、いったん、手動で時刻を合わせる。<br/>
<li>'''起動スクリプトのコピー'''<br/>
ソースの中にある起動スクリプトをコピーする
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
[root@hoge ~]# ntpdate ntp.nict.jp ← 手動で時刻を合わせる
[root@XXXXX ~]# cp /usr/local/src/openssh-6.1p1/contrib/redhat/sshd.init /etc/rc.d/init.d/sshd
</syntaxhighlight >
</syntaxhighlight >
<br>
<br>
</li>
</li>
<li>'''起動、自動起動の設定'''
<li>'''起動スクリプトの編集'''<br/>
([[OpenSSH 5.9p1のデフォルト起動スクリプト]])
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
[root@hoge ~]# /etc/rc.d/init.d/ntpd start ← NTPサーバー起動
[root@XXXXX ~]# vi /etc/rc.d/init.d/sshd
ntpd を起動中:                                            [  OK  ]


[root@hoge ~]# chkconfig ntpd on ← NTPサーバー自動起動設定
SSHD=/usr/sbin/sshd
SSHD=/usr/local/ssh/sbin/sshd
</syntaxhighlight >
start()の中
<syntaxhighlight lang="bash">
/usr/bin/ssh-keygen -A
/usr/local/ssh/bin/ssh-keygen -A
</syntaxhighlight >
<br>
</li>
<li>'''起動スクリプトの登録'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# chkconfig --add sshd
[root@XXXXX ~]# chkconfig sshd on
[root@XXXXX ~]# chkconfig --list sshd
sshd            0:off  1:off  2:off  3:on    4:on    5:on    6:off
</syntaxhighlight >
<br>
</li>
</ol>


[root@hoge ~]# chkconfig --list ntpd ← NTPサーバー自動起動設定確認
==鍵の作成==
ntpd            0:off  1:off   2:on    3:on    4:on    5:on    6:off ← ランレベル2~5のonを確認
<ol>
<li>'''一般ユーザーで作成する'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# su - hoge
[hoge@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/hoge/.ssh/id_rsa): ← 鍵のファイル名を入力(空EnterでOK)
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:
~鍵情報が表示される~
</syntaxhighlight >
<br>
</li>
<li>'''作成された鍵の確認'''<br/>
<syntaxhighlight lang="bash">
[hoge@XXXXX ~]$ cd .ssh
[hoge@XXXXX ~]$ 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  ← 公開鍵
</syntaxhighlight >
<br>
</li>
<li>'''公開鍵の名前の変更'''<br/>
<ul>
<li>authorized_keysが既存の場合
<syntaxhighlight lang="bash">
[hoge@XXXXX ~]$ cd ~/.ssh
[hoge@XXXXX ~]$ cat id_rsa.pub >> authorized_keys
[hoge@XXXXX ~]$ rm -f ~/.ssh/id_rsa.pub                                ← 元の鍵を削除
</syntaxhighlight >
</li>
<li>authorized_keysがない場合
<syntaxhighlight lang="bash">
[hoge@XXXXX ~]$ cd ~/.ssh
[hoge@XXXXX ~]$ mv id_rsa.pub authorized_keys
</syntaxhighlight >
</li>
</ul>
<br>
</li>
<li>'''公開鍵の権限の変更'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# chmod 400 ~/.ssh/authorized_keys
</syntaxhighlight >
<br>
</li>
<li>'''フロッピーにコピー'''<br/>
id_rsaファイルをフロッピーにコピーする。<br/>
([[CentOS_Howto#フロッピーのマウント|フロッピーのマウント]])
<syntaxhighlight lang="bash">
[root@XXXXX ~]# cp /home/hoge/.ssh/id_rsa /mnt/floppy
</syntaxhighlight >
</syntaxhighlight >
<br>
<br>
</li>
</li>
</ol>
</ol>
フロッピーにコピーされたid_rsaファイルを使用してPuTTyの接続設定を行う。

2023年5月11日 (木) 09:16時点における最新版

目的

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

準備

  • zlib
    [root@XXXXX ~]# yum install zlib-devel


  • tcp_wrappers-devel
    [root@XXXXX ~]# yum install tcp_wrappers-devel


  • OpenSSL

インストール

  1. ソースの取得
    [root@XXXXX ~]# wget -P /usr/local/src http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-6.1p1.tar.gz


  2. ソースの解凍
    [root@XXXXX ~]# cd /usr/local/src
    [root@XXXXX ~]# tar zxvf openssh-6.1p1.tar.gz


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


    tcp_wrappers-devel がないとconfigureの途中で怒られる。

    checking for libwrap... configure: error: *** libwrap missing


  4. インストール
    [root@XXXXX ~]# make
    [root@XXXXX ~]# make install


  5. シンボリックリンクの作成
    [root@XXXXX ~]# ln -s /usr/local/openssh-6.1p1 /usr/local/ssh


設定

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


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


  3. 起動スクリプトの編集
    OpenSSH 5.9p1のデフォルト起動スクリプト
    [root@XXXXX ~]# vi /etc/rc.d/init.d/sshd
    
    SSHD=/usr/sbin/sshd
    ↓
    SSHD=/usr/local/ssh/sbin/sshd

    start()の中

    /usr/bin/ssh-keygen -A
    ↓
    /usr/local/ssh/bin/ssh-keygen -A


  4. 起動スクリプトの登録
    [root@XXXXX ~]# chkconfig --add sshd
    [root@XXXXX ~]# chkconfig sshd on
    [root@XXXXX ~]# chkconfig --list sshd
    sshd            0:off   1:off   2:off   3:on    4:on    5:on    6:off


鍵の作成

  1. 一般ユーザーで作成する
    [root@XXXXX ~]# su - hoge
    [hoge@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/hoge/.ssh/id_rsa): ← 鍵のファイル名を入力(空EnterでOK)
    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:
    ~鍵情報が表示される~


  2. 作成された鍵の確認
    [hoge@XXXXX ~]$ cd .ssh
    [hoge@XXXXX ~]$ 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が既存の場合
      [hoge@XXXXX ~]$ cd ~/.ssh
      [hoge@XXXXX ~]$ cat id_rsa.pub >> authorized_keys 
      [hoge@XXXXX ~]$ rm -f ~/.ssh/id_rsa.pub                                 ← 元の鍵を削除
    • authorized_keysがない場合
      [hoge@XXXXX ~]$ cd ~/.ssh
      [hoge@XXXXX ~]$ mv id_rsa.pub authorized_keys


  4. 公開鍵の権限の変更
    [root@XXXXX ~]# chmod 400 ~/.ssh/authorized_keys


  5. フロッピーにコピー
    id_rsaファイルをフロッピーにコピーする。
    フロッピーのマウント
    [root@XXXXX ~]# cp /home/hoge/.ssh/id_rsa /mnt/floppy


フロッピーにコピーされたid_rsaファイルを使用してPuTTyの接続設定を行う。