ページ「コマンドとか」と「OpenSSH 6.1p1」の間の差分

提供:あべたけの覚書
(ページ間の差分)
ナビゲーションに移動 検索に移動
(ページの作成:「== 起動・終了 == === 再起動 === # reboot === シャットダウン === # shutdown == メモリ状況を調べる == === free === $ free total used free shared buffers cached Mem: 505904 455412 50492 0 42016 338528 -/+ buffers/cache: 74868 431036 Swap: 1015800 0 1015800 >実質的な残りメモリ量は431036 === top === $ top top - 14:29:47 up 13:13, 1…」)
 
(ページの作成:「==目的== せっかくなのでリモートでメンテを行えるようにする。<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行目:
== 起動・終了 ==
==目的==
=== 再起動 ===
せっかくなのでリモートでメンテを行えるようにする。<br>
# reboot
クライアントはWindowsXPで[http://www.chiark.greenend.org.uk/%7Esgtatham/putty/ PuTTy]を利用し、通信はSSHで暗号化する。
=== シャットダウン ===
# shutdown


== メモリ状況を調べる ==
==準備==
=== free ===
<ul>
$ free
<li>[http://www.gzip.org/zlib/ zlib]
              total      used      free    shared    buffers    cached
<syntaxhighlight lang="bash">
Mem:       505904    455412      50492          0      42016    338528
[root@XXXXX ~]# yum install zlib-devel
-/+ buffers/cache:      74868    431036
</syntaxhighlight >
Swap:      1015800          0    1015800
<br>
>実質的な残りメモリ量は431036
</li>
=== top ===
<li>tcp_wrappers-devel
$ top
<syntaxhighlight lang="bash">
top - 14:29:47 up 13:13,  1 user,  load average: 0.05, 0.01, 0.00
[root@XXXXX ~]# yum install tcp_wrappers-devel
Tasks:  78 total,  1 running,  77 sleeping,  0 stopped,  0 zombie
</syntaxhighlight >
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
<br>
Mem:    505904k total,  456156k used,    49748k free,    42296k buffers
</li>
Swap:  1015800k total,        0k used,  1015800k free,  338520k cached
<li>[http://www.openssl.org/ OpenSSL]
</li>
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
</ul>
    1 root     15  0  2040  632  544 S    0  0.1  0:01.21 init
    2 root      RT  0    0    0    0 S    0  0.0  0:00.00 migration/0
    3 root      34  19    0    0    0 S    0  0.0  0:00.00 ksoftirqd/0
    4 root      RT  0    0    0    0 S    0  0.0  0:00.00 watchdog/0
    5 root      RT  0    0    0    0 S    0  0.0  0:00.00 migration/1
    6 root      34  19    0    0    0 S    0  0.0  0:00.00 ksoftirqd/1
    7 root      RT  0    0    0    0 S    0  0.0  0:00.00 watchdog/1
    8 root      10  -5    0    0    0 S    0  0.0  0:00.00 events/0
    9 root      10  -5    0    0    0 S    0  0.0  0:00.00 events/1
    10 root      17  -5    0    0    0 S    0  0.0  0:00.00 khelper
=== vmstat ===
$ vmstat 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
  r  b  swpd  free  buff  cache  si  so    bi    bo  in  cs us sy id wa st
  0  0      4 143220  31088 214164    0    0    4    8  60  28  0  0 99  0  0
  0  0      4 143220  31088 214164    0    0    0    3 1008  41  0  0 100  0  0
  0  0      4 143220  31096 214164    0    0    0    32 1014  53  0  0 100  0  0
  0  0      4 143220  31096 214164    0    0    0    1 1008  39  0  0 100  0  0
>5秒ごとに表示更新


== ディレクトリ操作 ==
==インストール==
=== ディレクトリを階層で作成 ===
<ol>
$ mkdir -p ~/rpm/{BUILD,SOURCES,SPECS,SRPMS,RPMS/{i386,i486,i586,i686,noarch,ppc}}
<li>'''ソースの取得'''
<syntaxhighlight lang="bash">
<下記が作成される>
[root@XXXXX ~]# wget -P /usr/local/src http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-6.1p1.tar.gz
rpm
</syntaxhighlight >
├ BUILD
<br>
├ SOURCES
</li>
├ SPECS
<li>'''ソースの解凍'''<br/>
├ SRPMS
<syntaxhighlight lang="bash">
└ RPMS
[root@XXXXX ~]# cd /usr/local/src
    ├ i386
[root@XXXXX ~]# tar zxvf openssh-6.1p1.tar.gz
    ├ i486
</syntaxhighlight >
    ├ i586
<br>
    ├ i686
</li>
    ├ noarch
<li>'''コンパイル設定'''<br/>
    └ ppc
([[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>
<li>'''sshd_confの設定'''<br/>
<syntaxhighlight lang="bash">
[root@XXXXX ~]# vi /usr/local/ssh/etc/sshd_config


== 画面表示をログとして残す ==
# Port 22
configure実行時とか
# ./configure 2>&1 | tee configure.log.abe
Port 22
  # make 2>&1 | tee make.log.abe
 
  # make install 2>&1 | tee install.log.abe
# SyslogFacility AUTH
実行したディレクトリに[configure.log.abe],[make.log.abe],[install.log.abe]が作成される
SyslogFacility AUTH
 
# PermitRootLogin yes
PermitRootLogin no                ← rootでのログインを禁止
 
# PasswordAuthentication yes
PasswordAuthentication no        ← パスワードでのログインを禁止(鍵方式によるログインのみ許可)
 
# PermitEmptyPasswords no
PermitEmptyPasswords no          ← パスワードなしでのログインを禁止
</syntaxhighlight >
<br>
</li>
<li>'''起動スクリプトのコピー'''<br/>
ソースの中にある起動スクリプトをコピーする
<syntaxhighlight lang="bash">
[root@XXXXX ~]# cp /usr/local/src/openssh-6.1p1/contrib/redhat/sshd.init /etc/rc.d/init.d/sshd
</syntaxhighlight >
<br>
</li>
<li>'''起動スクリプトの編集'''<br/>
([[OpenSSH 5.9p1のデフォルト起動スクリプト]])
<syntaxhighlight lang="bash">
[root@XXXXX ~]# vi /etc/rc.d/init.d/sshd
 
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>
 
==鍵の作成==
<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 >
<br>
</li>
</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の接続設定を行う。