FTPサーバ(vsFTPD)
2009, 02, 15
FTPとは、ネットワーク経由でファイルを転送するためのプロトコル。インターネットにあるサーバから、ファイルをダウンロードしたりすることがあると思うが、その場合はFTPデーモンがサーバー上で起動している状態である。 FTPを使用する場合はLinuxに登録したユーザーでアクセスするのが基本だが、ユーザーに関係なく、アクセスする仕組みとしてAnonymous(匿名)FTPサービスというのも存在する。
■FTPサーバのインストール
FTPサーバを構築するには、vsftpd パッケージをインストールする。
PuTTYでSSH方式のリモート接続による操作で今後進める
■FTPサーバの設定ファイル変更
■FTP接続ユーザ設定
■ FTPアクセス制限
会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。
■FTPサーバの起動
■FTPサーバの自動起動設定
■FTPサーバの動作確認
■外部からの接続
外部からの接続には、ルーターの設定で20番と21番のポートを開ける必要がある。
ドメイン名での接続は事前にドメイン名の取得を行っている必要がある。
■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで
■FTPサーバの停止
ファイル転送はSSH (Secure Shell)を使用する場合は、FTPサーバは停止しておく。
※vsftpd を停止したらルーターの設定で20番と21番のポートを閉じる。
■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番のポートを閉じる。