a-Column

【FreeBSD4.10】vsftpdを試す(ソース版)

ほとんどのページがrpmやらportsでの自動インストールの説明ばかりなので、ここはあえてソースで試してみる!

まずは下記のサイトよりソースをダウンロードしてくる。

http://vsftpd.beasts.org/

どうもファイルを見ると、Apacheのように1.×.×系と2.×.×系があるようだ。違いは分からないが、まずは1の系列から試してみるとする。

ソース置き場:/usr/local/src
使用するファイル:vsftpd-1.2.2.tar.gz

$tar zxvf vsftpd-1.2.2.tar.gz
$cd vsftpd-1.2.2
$make

Makefileを参照したが特に問題のありそうな設定もなかったので、そのままインストールします。

#make install

まずはどこに設定ファイルがあるのか確認。
/usr/libexec/locate.updatedbを実行しておく事。

#locate vsftpd.conf

/usr/local/man/man5/vsftpd.conf.5
/usr/local/src/vsftpd-1.2.2/EXAMPLE/INTERNET_SITE/vsftpd.conf
/usr/local/src/vsftpd-1.2.2/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf
/usr/local/src/vsftpd-1.2.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf
/usr/local/src/vsftpd-1.2.2/vsftpd.conf
/usr/local/src/vsftpd-1.2.2/vsftpd.conf.5

#cp vsftpd.conf /etc
#vi /etc/vsftpd.conf


***********vsftpd.conf引用はじめ*************************

# Example config file /etc/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.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
※anonymous_enable=YES→NO
#
# Uncomment this to allow local users to log in.
#local_enable=YES
#
※listen=YES(追加)
# Uncomment this to enable any form of FTP write command.
#write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.

***********vsftpd.conf引用おわり*************************

※anonymous_enable=YES→NOなk
※listen=YES(追加)
あまり、よく分からないので、試しに上記の2箇所のみ追加・変更します。

事前に既存のFTPサービスを停止しておきます。


#/usr/local/sbin/vsftpd &

FTPクライアントでアクセスすると・・・
下記のエラーメッセージが出現。

500 OOPS: vsftpd: both local and anonymous access disabled!



何!?アクセスできへん・・・アクセスが許可されてないらしい・・・

#vi /etc/vsftpd.conf

***********vsftpd.conf引用はじめ*************************

# Example config file /etc/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.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES←(コメントアウト)
#
listen=YES
# Uncomment this to enable any form of FTP write command.
write_enable=YES←(コメントアウト)
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022←(コメントアウト)
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES←(コメントアウト)
#
# If you want, you can arrange for uploaded anonymous files to be ownedby
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log←(コメントアウト)
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests.Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file"in
# ASCII mode.
# These ASCII options are split into upload and download because you maywish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their h
# directory. If chroot_local_user is YES, then this list becomes a listof
# users to NOT chroot().
chroot_list_enable=YES←(コメントアウト)
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES

***********vsftpd.conf引用終わり*************************

local_enable=YES
local_umask=022
connect_from_port_20=YES
write_enable=YES
chroot_list_enable=YES
xferlog_file=/var/log/vsftpd.log

上記の部分をコメントアウトする。



一旦vsftpdのプロセスを殺して、再起動する。

#kill 173 (プロセスで確認)
#/usr/local/sbin/vsftpd &

再びFTPクライアントにて接続する。

500 OOPS: vsftpd: not found: directory given in 'secure_chroot_dir':/usr/share/empty

・・・・・・・・・
今度は、/usr/share/empty がないらしいです。

#mkdir /usr/share/empty

今度こそ!

>USER cadox
331 Please specify the password.
>PASS [xxxxxx]
500 OOPS: could not open chroot() list file:/etc/vsftpd.chroot_list
ログインできません.

うわっ、今度はリストにないから駄目っぽい。

#vi etc/vsftpd.conf

chroot_list_enable=NO

上記の部分をYESからNOに設定。

ホスト 192.168.60.125 (21) に接続しています.
接続しました.
220 (vsFTPd 1.2.2)

今度は完璧!


inetd経由で起動する場合は、/etc/inetd.conf を以下のように編集。

ftp stream tcp nowait root /usr/local/sbin/vsftpd /usr/local/sbin/vsftpd

inetd経由で起動する際には、vsftpd.confの設定で、
listen=YESをコメントインしないと、下記のようなエラーが表示されます。

500 OOPS: could not bind listening IPv4 socket



******************参考**********************************

※ログインユーザーの制限をする方法。

/etc/vsftpd.ftpusers

(設定例)
# The ftpusers file is deprecated. Use deny-uid/deny-gid in ftpaccess.
#↓変更(rootをコメントアウトする)
#root
bin
daemon
games
nobody
test


vsftpd.confの主な設定

匿名FTPを許可する
anonymous_enable=YES←NO

ローカルユーザーを許可する
local_enable=YES

書き込みを許可する
write_enable=YES

マスク設定(ftpしたファイルのアクセス権)
以下の場合はファイルがすべて755になります(777-022=755(rwx-rx-rx))
マスクを077にすると700になります(777-077=700(rwx- - ))
local_umask=022

匿名FTPのアップロードを許可する
#anon_upload_enable=YES

匿名FTPのディレクトリ作成等を許可する
#anon_mkdir_write_enable=YES

Anounimousftpでログインとき/var/ftp/.messageを表示
dirmessage_enable=YES

xferlogを有効にする
xferlog_enable=YES

FTPデータの接続ポートは20番
connect_from_port_20=YES


#chown_uploads=YES
#chown_username=whoever

xferlog_fileの場所を指定
#xferlog_file=/var/log/vsftpd.log

ftpコマンドがログ(/var/log/vsftpd.log)に残ります。
xferlog_std_format=YES ← NO
log_ftp_protocol=YES(追加)

アイドル時セッションのタイムアウト(10分)
#idle_session_timeout=600

データ接続時のタイムアウト(2分)
#data_connection_timeout=120

#nopriv_user=ftpsecure

#async_abor_enable=YES

#ascii_upload_enable=YES
#ascii_download_enable=YES

login時のbanner メッセージ
ftpd_banner=Welcome to GAPO FTP service.(コメントアウト#をはずしwelcommsg記入)

#deny_email_enable=YES

#banned_email_file=/etc/vsftpd.banned_emails


ここでコメントをはずし「YES」を設定するとchroot_listを有効に出来ます
「chroot」はディレクトリーを自由に移動できるということです
chroot_list_enable=YES (chrootリストを有効にする)

上を有効にした場合chroot_list_fileの場所を指定します。
/etc/vsftpd.chroot_listに「chroot」させたいユーザーを記述します。
#chroot_list_file=/etc/vsftpd.chroot_list

#ls_recurse_enable=YES

pam_service_name=vsftpd

ユーザーリストを有効にする。
userlist_enable=YES

userlist_denyにNOと書いた場合
/etc/vsftpd.user_listで記述したユーザがログイン許可ユーザとなる

userlist_denyにYESと書いた場合
/etc/vsftpd.user_listで記述したユーザがログイン拒否ユーザとなる

userlist_deny=NO


listen=YES

「tcp_wrappers=YES」に設定
/etc/hosts.denyと/etc/hosts.allowを有効にする
tcp_wrappers=YES

Last Update : 2004年10月07日 (木) 13:05