アクセスログ解析(Awstats)

2009, 02, 15

Awstats は視覚的に綺麗で、見やすいログ解析ツールだ。
日別・時間別・アクセス先など様々な統計情報を把握することが出来る。

■Awstatsのインストール
以下のコマンドでAwstatsをインストールする。
[root@linux ~]# yum -y install awstats

awstatsを使うには、perlも必要。perl -vと入力して、
以下のような情報が返ってくれば、perlはインストールされている。
[root@linux ~]# perl -v

This is perl, v5.8.8 built for i386-linux-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


■ Awstatsの設定ファイルの編集
まず不要な設定ファイルを削除しておく
[root@linux ~]# rm -f /etc/awstats/awstats.localhost.localdomain.conf

awstatsへ移動。
[root@linux ~]# cd /etc/awstats

etc/awstats/のawstats.server.yokensaka.com.conf を awstats.conf に変更。
[root@linux awstats]# mv awstats.linux.yokensaka.com.conf awstats.conf

続いて、root権限で、このawstats.confを編集。
[root@linux awstats]# su -

[root@linux ~]# vi /etc/awstats/awstats.conf

SiteDomain="linux.yokensaka.com"
↓
SiteDomain="yokensaka.com" ←独自ドメイン名に変更

DNSLookup=2
↓
DNSLookup=1   ← 1に変更(DNSの逆引きにする設定に変更)

DirIcons="/awstatsicons"
↓
DirIcons="/icon" ← アイコンのディレクトリー名を変更

SkipHosts="127.0.0.1"
↓ 内部のクライアントはスキップするように変更
SkipHosts="127.0.0.1 REGEX[^192\.168\.1\.]"
Lang="auto"
↓
Lang="jp" ← jpに変更

#LoadPlugin="tooltips"
↓ #を削除(該当する部分にマウスを当てるとヘルプが表示される。)
LoadPlugin="tooltips"

※ 最後にこのままだとアイコンが表示されないので、アイコンの入ってるフォルダ
/usr/share/awstats/wwwroot/icon を /var/www/html へコピーしておく。


■ awstats.plアクセス制限
[root@linux ~]# vi /etc/httpd/conf.d/awstats.conf
最終行へ追加

<Files "awstats.pl">
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 ← サーバー自身からのアクセスを許可
    Allow from 192.168.1. ← 内部ネットワークからのアクセスを許可
    Allow from xxx.xxx.xxx.xxx ← 特定の外部IP(xxx.xxx.xxx.xxx)からのアクセスを許可
</Files>

Apache設定反映
[root@linux ~]# /etc/rc.d/init.d/httpd reload 
httpd を再読み込み中: [ OK ]

会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。

■ httpdの設定ファイルの編集
httpdの設定ファイルの編集
[root@linux ~]# vi /etc/httpd/conf/httpd.conf
長すぎるURI(414 Error)はログに記録しない
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
         ↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

ログの記録内容変更
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common
この下に以下を追加
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log

以上で設定は完了ですので、一度httpdを再起動させる。
[root@linux ~]# service httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中:                                            [  OK  ]


■ ログファイルからデータファイルの作成
続いて、ログファイルからデータファイルの作成。
[root@linux ~]# /usr/share/awstats/tools/awstats_updateall.pl now
Running '"/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=default -configdir="/etc/awstats"' to update config default
Create/Update database for config "/etc/awstats/awstats.conf" by AWStats version 6.7 (build 1.892)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 3
 Found 3 dropped records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.

これで、/etc/cron.hourly/awstats が一時間毎に実行される。セットアップして1時間たってから、 http://サーバーアドレス/awstats/awstats.pl にアクセスすれば、解析結果が見れるようになっているはず。

Webサーバ(Apache)

2009, 02, 15

Apache はインターネットで最も普及しているオープンソースの Web サーバソフトウェアー。Apache は標準でインストールされているのでサーバーの設定に移る。

■Apache がインストールされてるかどうか確認する。
[root@server ~]# rpm -q httpd
httpd-2.2.3-11.el5_2.centos.4  ← パッケージ情報が表示された

パッケージ情報が表示されなければインストールする。
[root@linux ~]# yum -y install httpd 


■PHPをインストール
[root@linux ~]# yum -y install php


■Apacheの設定
Apacheの設定ファイルの編集
[root@linux ~]# vi /etc/httpd/conf/httpd.conf

エラーページ等でOS名を表示しないようにする
ServerTokens OS
             ↓
ServerTokens Prod

エラーページ等でApacheのバージョンを表示しないようにする
ServerSignature On
                ↓
ServerSignature Off

管理者のメールアドレスを設定する
ServerAdmin root@localhost
                  ↓
ServerAdmin webmaster@yokensaka.com ← 独自ドメインに変更

サーバー名を指定
#ServerName www.example.com:80
                  ↓
ServerName yokensaka.com:80 ← #をはずして独自ドメインに変更

CGIスクリプトを実行できる様にする
#AddHandler cgi-script .cgi
         ↓
AddHandler cgi-script .cgi .pl ← #をはずして.plを追加

デフォルトキャラセットを無効にする
AddDefaultCharset UTF-8
         ↓
#AddDefaultCharset UTF-8 ← #を付ける

CGIの許可、SSIの許可、シンボリックリンク許可
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks
         ↓
    Options Includes ExecCGI FollowSymLinks

.htaccessの許可
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None
         ↓
    AllowOverride All

長すぎるURI(414 Error)はログに記録しない
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
         ↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

ログの記録内容変更
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common
この下に以下を追加
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log


■Perlのパスが/usr/local/bin/perlでもCGIを実行出来るようにする。
現在のPerlの位置
[root@linux ~]# which perl
/usr/bin/perl

シンボリックリンク設定(/usr/local/bin/perlから/usr/bin/perlへリンクをはる)
[root@linux ~]# ln -s /usr/bin/perl /usr/local/bin/perl

変更後のPerlの位置
[root@linux ~]# which perl
/usr/local/bin/perl


■ドキュメントルートの所有者変更
[root@linux ~]# chown higo:higo /var/www/html/ ← ドキュメントルート所有者変更

[root@linux ~]# ll /var/www/ ← ドキュメントルート所有者変更確認
合計 32
drwxr-xr-x 2 root root 4096 2007-05-09 19:28 cgi-bin
drwxr-xr-x 3 root root 4096 2007-06-10 23:53 error
drwxr-xr-x 2 higo higo 4096 2007-05-09 19:28 html
drwxr-xr-x 3 root root 4096 2007-06-10 20:26 icons

※-Rオプションによりディレクトリの階層化にある全てのフォルダ、ファイルの所有者を変更できる。
[root@server ~]# chown -R higo /var/www/html/


■Apacheの起動
Apache(httpd)を起動する
[root@linux ~]# /etc/rc.d/init.d/httpd start
httpd を起動中:                                            [  OK  ]


■Apacheの自動起動設定
[root@linux ~]# chkconfig httpd on
[root@linux ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
           ランレベル2〜5がオンの状態であることを確認


■Apacheの動作確認

http://192.168.1.2/ でアクセスして「Apache 2 Test Page」画面が表示されればOK。

■各機能の動作確認

1.テスト用のHTMLの表示確認を行う。

テスト用のhtmlを作成
[root@linux ~]# vi /var/www/html/index.html
<html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
     <title>テストページ</title>
     </head>
     <body>
     テストページ
     </body>
     </html>

http://192.168.1.2/index.html でアクセスして、「テストページ」と表示されればOK。

2.SSIの動作確認を行なう。
テスト用のshtmlを作成
[root@linux ~]# vi /var/www/html/index.shtml
<html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
     <title>テスト</title>
     <body>
     SSIテスト
     <!--#config timefmt="%Y/%m/%d %H:%M:%S" -->
     <!--#echo var="DATE_LOCAL" -->
     </body>
</html>

http://192.168.1.2/index.shtml でアクセスして、現在の日付が表示されればOK。

3.CGIの動作確認を行なう。
テスト用のcgiを作成
[root@linux ~]# vi /var/www/html/test.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\">";
print "<title>テストページ</title>\n";
print "</head>\n";
print "<body>\n";
print "CGIテスト\n";
print "</body>\n";
print "</html>\n";

cgiのパーミッション変更
[root@linux ~]# chmod 755 /var/www/html/test.cgi

http://192.168.1.2/test.cgi でアクセスして、「CGIテスト」と表示されればOK。

4.PHPの動作確認を行なう。
テスト用のphpを作成
[root@linux ~]# vi /var/www/html/test.php
<?php
    phpinfo();
?>

http://192.168.1.2/test.php でアクセスして、PHPインフォメーション画面が表示されればOK。

■公開前の準備
ホームページを外部に公開するに当たって、ルータの設定でポート番号80番を開ける必要がある。

■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで

NTPサーバ(ntp)

2009, 02, 15

ここでは、自サーバをNTPサーバーとして立ち上げて、システム時刻を日本標準時間に合わせる。自サーバは、プロバイダーのNTPサーバより時刻を同期して、LAN内のクライアント、ルーターを自サーバの時刻と同期させるようにする。

■NTP がインストールされてるかどうか確認。
[root@linux ~]# rpm -q ntp
ntp-4.2.2p1-8.el5.centos.1  ← パッケージ情報が表示された

パッケージ情報が表示されなければNTPをインストールする。
 [root@linux ~]# yum -y install ntp 


■NTPサーバーの設定
オリジナルの設定ファイル名を変更する。
[root@linux ~]# mv /etc/ntp.conf /etc/ntp.conf.org

NTPサーバーの設定ファイルを作成
[root@linux ~]# vi /etc/ntp.conf

driftfile /var/lib/ntp/drift
server ntp1.plala.or.jp  ← server には、プロバイダーのNTPサーバーを指定
server ntp2.plala.or.jp  ← セカンダリのNTPサーバーも指定しておく


時刻同期先の公開NTPサーバーを調べるには、NTP/プロバイダ・機関別一覧を参照
利用しているISPがここに無い時は、推奨公開サーバを使用することにする。

■NTPサーバーの起動
いったん、手動でNTPサーバの時刻と同期させる。
[root@linux ~]# ntpdate ntp1.plala.or.jp
28 Dec 17:54:35 ntpdate[11526]: step time server 219.164.211.129 offset 37.009733 sec

NTPサーバーの起動
[root@linux bin]# /etc/rc.d/init.d/ntpd start
ntpd を起動中:                                             [  OK  ]


■NTPサーバーの自動起動設定
[root@linux ~]# chkconfig ntpd on
[root@linux ~]# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
           ランレベル2〜5がオンの状態であることを確認


■NTPサーバーの動作確認
[root@linux ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp1.plala.or.j 202.234.233.106  4 u   29   64    1    7.604    1.529   0.001
 ntp2.plala.or.j 202.234.233.106  4 u   28   64    1    8.008    1.347   0.001
指定したNTPサーバの前が空白の時は同期中の状態。

約15分後、再度NTPサーバーの動作確認。
[root@linux ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.plala.or.j 202.234.233.106  4 u   22   64  377    6.236   24.531   5.756
*ntp2.plala.or.j 202.234.233.106  4 u   26   64  377    6.597   34.459   8.400
指定したNTPサーバの前に*や+が表示された時は同期完了の状態。


■時刻同期設定
クライアントのPCで日付と時刻のプロパティ画面を表示し、「インターネット時刻」タブを表示。 サーバの入力欄に自サーバのIPアドレス「192.168.1.2」を入力し「今すぐ更新」ボタンを押す。 最後に「OK」ボタンを押すと、以降、自サーバより時刻を同期するようになる。

※サーバーでファイアーウォールを有効にしている場合は、サーバーの「ファイアーウォール設定」で「他のポート」に「123:udp」を追記しておく必要がある。そうしないとクライアント側で同期に失敗する。設定の方法はX Window Systemで起動し「アプリケーション・メニュー」から「システム設定」-「セキュリティレベル」を選択して「セキュリティレベルの設定ツール」を起動。「セキュリティレベル」で「ファイアウォールを有効にする」を選択し、「他のポート」に「123:udp」と入力。すでに他のポート設定が記述されてる場合は、カンマ記号(,)で区切って新しい設定を追記。
  
ルータの設定でNTPサーバーのIPアドレスを自サーバーのIPアドレス「192.168.1.2」に変更。  
これで、自サーバー、LAN内のWindowsマシン、ルーターの時刻が常に同期が取れてる状態で日本標準時間となるようになる。

FTPサーバ(vsFTPD)

2009, 02, 15

FTPとは、ネットワーク経由でファイルを転送するためのプロトコル。インターネットにあるサーバから、ファイルをダウンロードしたりすることがあると思うが、その場合はFTPデーモンがサーバー上で起動している状態である。 FTPを使用する場合はLinuxに登録したユーザーでアクセスするのが基本だが、ユーザーに関係なく、アクセスする仕組みとしてAnonymous(匿名)FTPサービスというのも存在する。

■FTPサーバのインストール
FTPサーバを構築するには、vsftpd パッケージをインストールする。
PuTTYでSSH方式のリモート接続による操作で今後進める
Using username "higo".
Authenticating with public key "imported-openssh-key"
Last login: Sun Feb 15 22:11:53 2009 from 3.1.168.192.in-addr.arpa
[higo@linux ~]$


[higo@linux ~]$ su -  ← スーパーユーザになる
パスワード(P): ← スーパーユーザのパスワードを入力

[root@linux ~]# yum install vsftpd
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * centosplus: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.i386 0:2.0.5-12.el5 set to be updated
filelists.sqlite.bz2      100% |=========================| 3.8 MB    00:00
filelists.xml.gz          100% |=========================| 2.7 MB    00:00
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 vsftpd                  i386       2.0.5-12.el5     base              137 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 137 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): vsftpd-2.0.5-12.el 100% |=========================| 137 kB    00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: vsftpd                       ######################### [1/1]

Installed: vsftpd.i386 0:2.0.5-12.el5
Complete!

FTPサーバを起動させる
[root@linux ~]# /etc/rc.d/init.d/vsftpd start
vsftpd 用の vsftpd を起動中:                               [  OK  ]


■FTPサーバの設定ファイル変更
vsftpd.conf ファイルを編集
[root@linux ~]# vi /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.

匿名ユーザ(anonymous)はログイン禁止(YES→NO)
anonymous_enable=NO

ユーザが打ち込んだ詳細なログを残す
xferlog_std_format=NO  (YES→NO)
log_ftp_protocol=YES   (次の行へ追加)

アイドル時のタイムアウトを設定(#を削除)
idle_session_timeout=600

接続時のタイムアウトを設定(#を削除、120→60)
data_connection_timeout=60

アスキーモードでのアップロードを許可する(#を削除)
ascii_upload_enable=YES

アスキーモードでのダウンロードを許可する(#を削除)
ascii_download_enable=YES

一般ユーザはホームディレクトリーより上へアクセスさせない(#を削除)
chroot_list_enable=YES

ホームディレクトリーより上へアクセスさせないユーザリスト(#を削除)
chroot_list_file=/etc/vsftpd/chroot_list

ディレクトリを削除できるようにする(#を削除)
ls_recurse_enable=YES

パッシブモードを有効にする(最下行へ追加)
pasv_promiscuous=YES

タイムスタンプ時間を日本時間に変更(最下行へ追加)
use_localtime=YES


■FTP接続ユーザ設定
ホームディレクトリーより上へアクセスさせないユーザリスト
[root@linux ~]# vi /etc/vsftpd/chroot_list
ユーザ「fedora」は、自ホームディレクトリーより上にアクセスさせない
fedora

FTP接続させないユーザリスト
[root@linux ~]# vi /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
fedora  ←ユーザ「fedora」をFTP接続させないようにリストに追加


■ FTPアクセス制限
サーバー自身、内部ネットワーク、特定の外部IP(xxx.xxx.xxx.xxx)からのアクセスを許可
[root@linux ~]# echo "vsftpd : 127.0.0.1 192.168.1. xxx.xxx.xxx.xxx" >> /etc/hosts.allow 

上記以外の全てのアクセスを禁止
[root@linux ~]# echo "vsftpd : ALL" >> /etc/hosts.deny

会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。

■FTPサーバの起動
[root@linux ~]# /etc/rc.d/init.d/vsftpd start
vsftpd用のvsftpdを起動中:                                  [  OK  ]


■FTPサーバの自動起動設定
[root@linux ~]# chkconfig vsftpd on
[root@linux ~]# chkconfig --list vsftpd
vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
           ランレベル2〜5がオンの状態であることを確認


■FTPサーバの動作確認
クライアント(IP:192.168.1.3)のコマンドプロンプトより行う。 
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

ユーザ「fedora」が拒否されるか?の確認
C:\WIMDOWS\system32>ftp
ftp> op
To 192.168.1.2
Connected to 192.168.1.2.
220 (vsFTPd 2.0.5)
User (192.168.1.2:(none)): fedora
ログインが拒否された
530 Permission denied.
Login failed.
FTP接続を終了
ftp> bye
221 Goodbye.

ユーザ「higo」がログインできるか?の確認
C:\WIMDOWS\system32>ftp
ftp> op
To 192.168.1.2
Connected to 192.168.1.2.
220 (vsFTPd 2.0.5)
User (192.168.1.2:(none)): higo
ログインできた
331 Please specify the password.
Password:
230 Login successful.
ftp>

事前に作成しておいたtest.txtをサーバへアップロードする
ftp> put c:\test.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.   アップロードできた
ftp: 19 bytes sent in 0.00Seconds 19000.00Kbytes/sec.

サーバよりファイルをダウンロードする
ftp> get test.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for test.txt (19 bytes).
226 File send OK.   ダウンロードできた
ftp: 19 bytes received in 0.00Seconds 19000.00Kbytes/sec.

FTP接続を終了
ftp> bye
221 Goodbye.


■外部からの接続
外部からの接続には、ルーターの設定で20番と21番のポートを開ける必要がある。
ドメイン名での接続は事前にドメイン名の取得を行っている必要がある。

■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで

■FTPサーバの停止
ファイル転送はSSH (Secure Shell)を使用する場合は、FTPサーバは停止しておく。
[root@linux ~]# /etc/rc.d/init.d/vsftpd stop
vsftpd を停止中:                                           [  OK  ]

起動時にFTPサーバを起動しない
[root@linux ~]# chkconfig vsftpd off
[root@linux ~]# chkconfig --list vsftpd
vsftpd          0:off  1:off  2:off  3:off  4:off  5:off  6:off
[root@linux ~]#

※vsftpd を停止したらルーターの設定で20番と21番のポートを閉じる。

リモート接続(PuTTY)

2009, 02, 12

PuTTYはWindowsで動作するSSH方式のリモート接続ソフトウェア。 Telnetによるリモートコンピュータへの接続ではパスワードが暗号化されないので、SSH(暗号化シェル)でのリモート接続を行う。 PuTTYを導入するに当って事前にSSHサーバの構築を行っている必要がある。

■PuTTY の入手
  1. PuTTY Download Page より PuTTYgen をダウンロード。

  2. PuTTY日本語化ダウンロードサイト から 日本語に対応した PuTTY をダウンロード。

  3. ダウンロードした日本語に対応した PuTTY を適当な場所に解凍。
    (最新版を確認してからダウンロード)

■秘密鍵のジェネレート
  1. ダウンロードした PuTTYgen を実行。

  2. 「Load ボタン」を押す。

  3. サーバよりコピーした秘密鍵を選択。

  4. ファイルの種類は、「All Files(*.*)」を選択。

  5. サブウィンドウが開くので、鍵を作成した時のパスワードを入力。

  6. 「Save privte key ボタン」押す。

  7. ジェネレートされた秘密鍵を適当な場所(PuTTYのフォルダ等)に名前(higo)を付けて保存。

  8. メニューより[File]-[Exit]をクリックし PuTTYgen を終了。


■PuTTY の設定
  1. 「 日本語に対応した PuTTY 」のフォルダの中の「 puttyjp.exe 」を実行。

  2. [ホスト名]の欄にホスト名かサーバーのIPアドレスを入力。(例 192.168.1.2 )

  3. プロトコルを[SSH]にする。

  4. 次に[接続→データ]を選択し、[自動ログインのユーザ名]にユーザー名入力。(例 higo )

  5. 次に[接続→SSH]のプロトコルオプションで、[優先するSSHプロトコルバージョン]を[2]に設定。

  6. 次に[ウィンドウ→変換]で受信されるデータの文字セット変換をEUC-JPに選択。

  7. 次に[接続→SSH→認証]で参照ボタンを押して、保存した秘密鍵「 **.ppk 」ファイルを指定。

  8. 次に[セッション]に戻り、「保存されたセッション」に分かりやすい名前(例192.168.1.2)を入力して保存。

  9. 保存したセッションを選択して「開く」をクリックすると、別ウインドウが開くのでパスワードを入力するとサーバーに接続できる。

※PuTTY の設定が終わってからPuTTYのフォルダを移動するとサーバーに接続できなくなるので、改めて[接続→SSH→認証]で参照ボタンを押して、保存した秘密鍵「 **.ppk 」ファイルを指定する必要がある。

■接続前の準備
外部からの接続には、ルータの設定が必要なのでルータの設定で22番のポートを開ける。

■PuTTY によるリモート接続
PuTTY を起動して、保存されたセッションにある「自宅サーバ」をダブルクリック。

Using username "higo".
Authenticating with public key "imported-openssh-key"
Passphrase for key "imported-openssh-key":        ← パスワードを入力
Last login: Wed Feb 23 00:35:41 2005 from 3.1.168.192.in-addr.arpa
[higo@linux ~]$                            ← SSHによるログインができた


■PuTTY のカスタマイズ
  1. PuTTY を起動して、保存されたセッションにある「自宅サーバ」を選択して「読込」をクリック。

  2. 端末ウィンドウの大きさを変更したいときは、ウィンドウ カテゴリーの「行」「列」で設定。 デフォルトは 80x24 になっているので、「行」を53、「列」を100、に変更。 「行」53は、キーボードの「PaguUp」「PageDown」で50行ずつスクロールするので大体の行を把握できるようにするためで、「列」は好みで変更。

  3. ウィンドウ カテゴリーの「スクロールバッファの行数」が基本では「200」になっている。 これだと以前に行った設定等の確認ができないで困る場合があるので、スクロールバッファサイズを「2000」に変更。 これは、サイト構築のための覚書を書くために、設定したことをスクロールバックして確認する必要があるため。

  4. プロバイダーによっては、一定時間入力がないと自動的に接続を切断してしまう場合がある。 接続が切れないようにしたい場合には、接続 カテゴリーの「セッションをアクティブに保つための null パケットの送信」で、 null パケットを自動送信する時間間隔 (単位: 秒) を設定する。 デフォルトは 0 (null パケットは送信しない) なので、60 秒 = 1 分おきに null パケットを送信するように設定。