﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-悠然居-文章分类-Linux FTP</title><link>http://www.cnitblog.com/everspring/category/7673.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 30 Sep 2011 21:13:31 GMT</lastBuildDate><pubDate>Fri, 30 Sep 2011 21:13:31 GMT</pubDate><ttl>60</ttl><item><title>实战vsftp-2.04配置</title><link>http://www.cnitblog.com/everspring/articles/49853.html</link><dc:creator>everspring</dc:creator><author>everspring</author><pubDate>Sun, 05 Oct 2008 02:30:00 GMT</pubDate><guid>http://www.cnitblog.com/everspring/articles/49853.html</guid><wfw:comment>http://www.cnitblog.com/everspring/comments/49853.html</wfw:comment><comments>http://www.cnitblog.com/everspring/articles/49853.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/everspring/comments/commentRss/49853.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/everspring/services/trackbacks/49853.html</trackback:ping><description><![CDATA[<div class=t_msgfont id=message4690420>Vsftp(Very Secure FTP)以它优越的安全，稳定，快速的性能在ftp软件中占了一席之地。<br>很多大站已经采用它如如ftp.redhat.com,ftp.kde.org,ftp.gnome.org.等。<br><br>Vsftp官方最新版本下载：ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.0.4.tar.gz<br>本文所有配置文件和相关文件的下载：http://xiutuo.vxv.cn/blog/file/vsftp_conf.rar<br><br>本文采用vsftp2.0.4，它有三种实现形式：<br>&nbsp; &nbsp;1、匿名用户形式：在默认安装的情况下，系统只提供匿名用户访问<br>&nbsp; &nbsp;2、本地用户形式：以/etc/passwd中的用户名为认证方式<br>&nbsp; &nbsp;3、虚拟用户形式：支持将用户名和口令保存在数据库文件或数据库服务器中。相对于FTP的本地用户形式来说，虚拟用户只是FTP服务器的专有用户，<br>&nbsp; &nbsp;虚拟用户只能访问FTP服务器所提供的资源，这大大增强系统本身的安全性。相对于匿名用户而言，虚拟用户需要用户名和密码才能获取FTP服务器中<br>&nbsp; &nbsp;的文件，增加了对用户和下载的可管理性。对于需要提供下载服务，但又不让所有人匿名下载；既需要对下载用户进行管理，又考虑到主机安全和<br>&nbsp; &nbsp;管理方便的FTP站点来说，&nbsp; &nbsp;虚拟用户是一种极好的解决方案。<br><br>一：下载安装<br>&nbsp; &nbsp;下载到/home/xiutuo/software/目录下，由于默认编译是支持pam认证，不支持tcpwrappers和ssl。<br>&nbsp; &nbsp;我们采用默认，即：本地用户不允许登入vsftp，不能使用hosts.allow和hosts.deny<br>&nbsp; &nbsp;# rpm -e vsftpd-**&nbsp;&nbsp;//卸载原来低版本的vsftp<br>&nbsp; &nbsp;# cd /home/xiutuo/software/<br>&nbsp; &nbsp;# tar -zvxf vsftpd-2.0.4.tar.gz<br>&nbsp; &nbsp;# cd vsftpd-2.0.4<br>&nbsp; &nbsp;# make<br>&nbsp; &nbsp;把编译好的文件安装到相应目录下即可，没有相关目录请先创建。<br>&nbsp; &nbsp;# cp vsftpd /usr/local/sbin/vsftpd<br>&nbsp; &nbsp;# cp vsftpd.conf.5 /usr/local/man/man5<br>&nbsp; &nbsp;# cp vsftpd.8 /usr/local/man/man8<br>&nbsp; &nbsp;# cp vsftpd.conf /etc/<br>二：vsftp的启动和关闭--独立模式下<br>&nbsp; &nbsp;启动：<br>&nbsp; &nbsp;# /usr/local/sbin/vsftpd &amp;<br>&nbsp; &nbsp;关闭：<br>&nbsp; &nbsp;# killall vsftpd<br><br>以下的配置均采用vsftp推荐的独立方式启动，即standalone方式启动vsftp<br>三：匿名用户vsftp配置<br>&nbsp; &nbsp;创建必要的帐号，目录： <br>&nbsp; &nbsp;# useradd nobody&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //可能你的系统已经存在此帐号，那就不用建立<br>&nbsp; &nbsp;# mkdir /usr/share/empty&nbsp;&nbsp;//可能你的系统已经存在此目录，那就不用建立<br>&nbsp; &nbsp;# mkdir /var/ftp&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //可能你的系统已经存在此目录，那就不用建立<br>&nbsp; &nbsp;# useradd -d /var/ftp ftp //可能你的系统已经存在此帐号，那就不用建立<br>&nbsp; &nbsp;# chown root:root /var/ftp //改变属主<br>&nbsp; &nbsp;# chmod og-w /var/ftp&nbsp; &nbsp;&nbsp; &nbsp;//赋予相关目录权限<br><br>&nbsp; &nbsp;a.配置匿名用户只能下载，不能上传的vsftp，vsftpd.conf内容如下：<br>&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;&nbsp;# Standalone mode<br>&nbsp; &nbsp;&nbsp; &nbsp; listen=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; listen_address=192.168.1.100 //可以通过域名来访问vsftp<br>&nbsp; &nbsp;&nbsp; &nbsp; #tcp_wrappers=YES<br>&nbsp; &nbsp;&nbsp;&nbsp;# Access rights<br>&nbsp; &nbsp;&nbsp; &nbsp; anonymous_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_root=/var/ftp<br>&nbsp; &nbsp;&nbsp; &nbsp; local_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_upload_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_mkdir_write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_other_write_enable=NO<br>&nbsp; &nbsp;&nbsp;&nbsp;# Security<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_world_readable_only=NO&nbsp;&nbsp;//可以浏览和下载有相关权限的文件（其他用户有可读和可执行权限）<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_from_port_20=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; hide_ids=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_min_port=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_max_port=60000<br>&nbsp; &nbsp;&nbsp;&nbsp;# Features<br>&nbsp; &nbsp;&nbsp; &nbsp; dirmessage_enable=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES&nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_file=/var/log/vsftpd.log <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_std_format=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ls_recurse_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; ascii_download_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; async_abor_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ftpd_banner=Welcome to xiutuo.com FTP service.<br>&nbsp; &nbsp;&nbsp;&nbsp;# Performance<br>&nbsp; &nbsp;&nbsp; &nbsp; one_process_model=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; idle_session_timeout=120<br>&nbsp; &nbsp;&nbsp; &nbsp; data_connection_timeout=300<br>&nbsp; &nbsp;&nbsp; &nbsp; accept_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_max_rate=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; max_clients=200<br>&nbsp; &nbsp;&nbsp; &nbsp; max_per_ip=4<br>&nbsp; &nbsp;&nbsp; &nbsp; #check_shell=NO<br><br>&nbsp; &nbsp; b.配置匿名用户可下载，可上传。<br>&nbsp; &nbsp;&nbsp; &nbsp;先创建一个可写目录/var/ftp/pub<br>&nbsp; &nbsp;&nbsp; &nbsp;# mkdir /var/ftp/pub<br>&nbsp; &nbsp;&nbsp; &nbsp;# chmod -R 777 /var/ftp/pub<br>&nbsp; &nbsp;&nbsp; &nbsp;配置文件vsftp.conf的内容如下：<br><br>&nbsp; &nbsp;&nbsp;&nbsp;# Standalone mode<br>&nbsp; &nbsp;&nbsp; &nbsp; listen=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; listen_address=192.168.1.100<br>&nbsp; &nbsp;&nbsp; &nbsp; #tcp_wrappers=YES<br>&nbsp; &nbsp;&nbsp;&nbsp;# Access rights<br>&nbsp; &nbsp;&nbsp; &nbsp; anonymous_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_root=/var/ftp<br>&nbsp; &nbsp;&nbsp; &nbsp; local_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; write_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_upload_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_mkdir_write_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_other_write_enable=YES<br>&nbsp; &nbsp;&nbsp;&nbsp;# Security<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_world_readable_only=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_from_port_20=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; hide_ids=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_min_port=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_max_port=60000<br>&nbsp; &nbsp;&nbsp;&nbsp;# Features<br>&nbsp; &nbsp;&nbsp; &nbsp; dirmessage_enable=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES&nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_file=/var/log/vsftpd.log <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_std_format=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ls_recurse_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; ascii_download_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; async_abor_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ftpd_banner=Welcome to xiutuo.com FTP service.<br>&nbsp; &nbsp;&nbsp;&nbsp;# Performance<br>&nbsp; &nbsp;&nbsp; &nbsp; one_process_model=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; idle_session_timeout=120<br>&nbsp; &nbsp;&nbsp; &nbsp; data_connection_timeout=300<br>&nbsp; &nbsp;&nbsp; &nbsp; accept_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_max_rate=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; max_clients=200<br>&nbsp; &nbsp;&nbsp; &nbsp; max_per_ip=4<br>&nbsp; &nbsp;&nbsp; &nbsp; #check_shell=NO<br><br>四：虚拟用户配置。<br>&nbsp; &nbsp;a.基于db的虚拟用户配置。<br>&nbsp; &nbsp;&nbsp;&nbsp;请查看linux中是否存在db4。<br>&nbsp; &nbsp;&nbsp;&nbsp;# rpm &#8211;qa | grep db4<br>&nbsp; &nbsp;&nbsp; &nbsp; db4-devel-4.2.52-7.1<br>&nbsp; &nbsp;&nbsp; &nbsp; db4-4.2.52-7.1<br>&nbsp; &nbsp;&nbsp; &nbsp; db4-utils-4.2.52-7.1<br>&nbsp; &nbsp;&nbsp; &nbsp; &#8230;&#8230;<br>&nbsp; &nbsp;&nbsp; &nbsp;如果有的话，那就不必安装db，没有的话，请安装db4的db4-devel-4.2.52-7.1，db4-4.2.52-7.1，db4-utils-4.2.52-7.1相关软件包。<br>&nbsp; &nbsp;&nbsp; &nbsp;1.建立虚拟用户数据库文件<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;在/etc/下建立login.txt，添加vsftp虚拟用户和密码。<br>&nbsp; &nbsp; &nbsp; &nbsp; # cd /etc<br>&nbsp; &nbsp; &nbsp; &nbsp; # touch login.txt<br>&nbsp; &nbsp; &nbsp; &nbsp; # vi login.txt<br>&nbsp; &nbsp; &nbsp; &nbsp; #login.txt内容如下，其中虚拟用户是test，test1，test2；他们的密码分别是password0,password1,password2。用户和密码分别各占一行。<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;test<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;password0<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;test1<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;password1<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;test2<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;password2<br>&nbsp; &nbsp; &nbsp; &nbsp; #生成虚拟用户数据库文件vsftpd_login.db，并赋予root可以读写，其他用户没有任何权限<br>&nbsp; &nbsp; &nbsp; &nbsp; # db_load -T -t hash -f /etc/login.txt /etc/vsftpd_login.db<br>&nbsp; &nbsp; &nbsp; &nbsp; # chmod 600 /etc/vsftpd_login.db <br>&nbsp; &nbsp;&nbsp; &nbsp;2.建立认证文件<br>&nbsp; &nbsp;&nbsp; &nbsp; # vi /etc/pam.d/ftp 插入如下两行<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;account required /lib/security/pam_userdb.so db=/etc/vsftpd_login<br>&nbsp; &nbsp;&nbsp; &nbsp;3.创建真实用户与虚拟用户的映射。<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;# useradd -d /home/ftpsite -s /sbin/nologin virtual<br>&nbsp; &nbsp; &nbsp; &nbsp; # cd /home/ftpsite<br>&nbsp; &nbsp; &nbsp; &nbsp; # touch test.txt<br>&nbsp; &nbsp; &nbsp; &nbsp; # chown virtual.virtual test.txt <br>&nbsp; &nbsp;&nbsp; &nbsp;4.配置文件vsftpd.conf内容如下：<br><br>&nbsp; &nbsp;&nbsp;&nbsp;# Standalone mode<br>&nbsp; &nbsp;&nbsp; &nbsp; listen=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; listen_address=192.168.1.100 //可以通过域名来访问vsftp<br>&nbsp; &nbsp;&nbsp; &nbsp; #tcp_wrappers=YES<br>&nbsp; &nbsp;&nbsp;&nbsp;# Access rights<br>&nbsp; &nbsp;&nbsp; &nbsp; anonymous_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; #anon_root=/var/ftp<br>&nbsp; &nbsp;&nbsp; &nbsp; local_enable=YES&nbsp;&nbsp;//一定要yes，否则ftp登入会提示，本地用户和匿名用户都没有访问权限的提示<br>&nbsp; &nbsp;&nbsp; &nbsp; write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_upload_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_mkdir_write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_other_write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; guest_enable=YES&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 启用虚拟用户<br>&nbsp; &nbsp;&nbsp; &nbsp; guest_username=virtual&nbsp; &nbsp;&nbsp; &nbsp; //指定虚拟用户，<br>&nbsp; &nbsp;&nbsp; &nbsp; virtual_use_local_privs=YES //虚拟用户和本地用户权限相同<br><br>&nbsp; &nbsp;&nbsp;&nbsp;# Security<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_world_readable_only=NO&nbsp;&nbsp;//可以浏览和下载有相关权限的文件（其他用户有可读和可执行权限）<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_from_port_20=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; hide_ids=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_min_port=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; pasv_max_port=60000<br>&nbsp; &nbsp;&nbsp;&nbsp;# Features<br>&nbsp; &nbsp;&nbsp; &nbsp; dirmessage_enable=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES&nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_file=/var/log/vsftpd.log <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_std_format=YES <br>&nbsp; &nbsp;&nbsp; &nbsp; xferlog_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ls_recurse_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; ascii_download_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; async_abor_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; ftpd_banner=Welcome to xiutuo.com FTP service.<br>&nbsp; &nbsp;&nbsp;&nbsp;# Performance<br>&nbsp; &nbsp;&nbsp; &nbsp; one_process_model=YES<br>&nbsp; &nbsp;&nbsp; &nbsp; idle_session_timeout=120<br>&nbsp; &nbsp;&nbsp; &nbsp; data_connection_timeout=300<br>&nbsp; &nbsp;&nbsp; &nbsp; accept_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; connect_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp; anon_max_rate=50000<br>&nbsp; &nbsp;&nbsp; &nbsp; max_clients=200<br>&nbsp; &nbsp;&nbsp; &nbsp; max_per_ip=4<br>&nbsp; &nbsp;&nbsp; &nbsp; check_shell=NO<br>&nbsp; &nbsp;&nbsp; &nbsp; 5.高级配置vsftpd.conf，增加对每个虚拟用户的配置，并对每个虚拟用户详细权限进行配置。<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;创建/etc/vsftpd_user_conf目录，并在其下分别为虚拟用户test，test1,test2增加test，test1,test2三个配置文件。<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;# mkdir /etc/vsftpd_user_conf<br>&nbsp; &nbsp; &nbsp; &nbsp; # cd /etc/vsftpd_user_conf<br>&nbsp; &nbsp; &nbsp; &nbsp; # touch test test1 test2<br>&nbsp; &nbsp; &nbsp; &nbsp; #test,test1,test2配置文件根据需要设置相关vsftp的权限，比如test用户可以下载上传，修改，test文件内容如下：<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;write_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_upload_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_mkdir_write_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_other_write_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_world_readable_only=NO&nbsp;&nbsp;//可以浏览和下载有相关权限的文件（其他用户有可读和可执行权限）<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#主配置文件vsftpd.conf内容如下：<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Standalone mode<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;listen=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;listen_address=192.168.1.100 //可以通过域名来访问vsftp<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#tcp_wrappers=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Access rights<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anonymous_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#anon_root=/var/ftp<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;local_enable=YES&nbsp;&nbsp;//一定要yes，否则ftp登入会提示，本地用户和匿名用户都没有访问权限的提示<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_upload_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_mkdir_write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_other_write_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;guest_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;guest_username=virtual&nbsp; &nbsp;&nbsp; &nbsp; //这两行的意思是采用虚拟用户形式<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;virtual_use_local_privs=YES //虚拟用户和本地用户权限相同<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;user_config_dir=/etc/vsftpd_user_conf //增加对每个虚拟用户的配置<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Security<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_world_readable_only=YES&nbsp;&nbsp;//不可以浏览和下载有相关权限的文件（其他用户有可读和可执行权限）<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;connect_from_port_20=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;hide_ids=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;pasv_min_port=50000<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;pasv_max_port=60000<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Features<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;dirmessage_enable=YES <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;xferlog_enable=YES&nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;xferlog_file=/var/log/vsftpd.log <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;xferlog_std_format=YES <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;xferlog_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ls_recurse_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ascii_download_enable=NO<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;async_abor_enable=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ftpd_banner=Welcome to xiutuo.com FTP service.<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Performance<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;one_process_model=YES<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;idle_session_timeout=120<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_connection_timeout=300<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;accept_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;connect_timeout=60<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;anon_max_rate=50000<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;max_clients=200<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;max_per_ip=4<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;check_shell=NO<br>&nbsp; &nbsp;&nbsp;&nbsp;b.基于mysql的pam认证的虚拟用户配置<br>&nbsp; &nbsp;&nbsp; &nbsp; 1.下载pam-mysql到/home/xiutuo/software,<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 下载地址：http://nchc.dl.sourceforge.net/sourceforge/pam-mysql/pam_mysql-0.5.tar.gz<br>&nbsp; &nbsp;&nbsp; &nbsp; 2.安装<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# cd /home/xiutuo/software<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# tar -zvxf pam_mysql-0.5.tar.gz<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# cd pam_mysql-0.5<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# make<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# cp pam_mysql.so /lib/security<br>&nbsp; &nbsp; &nbsp; &nbsp; 3.创建真实用户与虚拟用户的映射<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# useradd virtual<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# passwd virtual<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;#必要时使用 ： useradd -d /home/ftpsite -s /sbin/nologin virtual<br>&nbsp; &nbsp; &nbsp; &nbsp; 4.创建数据库<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# cd /usr/local/mysql/bin/<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# ./mysql &#8211;u root -h localhost -p<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;create database ftpd;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;use ftpd;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;create table user(name char(20) binary,passwd char(20) binary);<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;insert into user (name,passwd) values ('test','password');<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;insert into user (name,passwd) values ('test1','password1');<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mysql&amp;gt;insert into user (name,passwd) values ('test2','password2');<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mysql&amp;gt;grant select on ftpd.user to virtual@localhost identified by '123456';<br>&nbsp; &nbsp; &nbsp; &nbsp; 5.建立认证文件<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# cd /etc/pam.d/<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# touch ftp&nbsp; &nbsp;//如果有就不用生成了。<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;# vi ftp&nbsp; &nbsp;&nbsp; &nbsp;//内容如下：<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;auth required /lib/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0<br><br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;account required /lib/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; #注意： <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#crypt= n <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#crypt=0: 明文密码<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#crypt=1: 使用crpyt()函数(对应SQL数据里的encrypt()，encrypt()随机产生salt)<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#crypt=2: 使用MYSQL中的password()函数加密<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;#crypt=3：表示使用md5的散列方式<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;6.详细的vsftpd.conf与具体的虚拟用户的配置跟基于db的虚拟用户配置步骤4和步骤5一样。<br><br>&nbsp; &nbsp; &nbsp; &nbsp; c.对用户做磁盘限额，限额功能是系统自带，不是vsftp功能！<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;对virtual用户主目录:/home/ftpsite/限制，修改/etc/fstab文件，重新挂载/home所在分区，或者重新启动计算机<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;1.编辑/etc/fstab文件，重新挂载/home所在分区，或者重新启动计算机，使限额功能生效<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# vi /etc/fstab<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 把 <br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; LABEL=/home&nbsp; &nbsp;/home&nbsp; &nbsp;ext3&nbsp; &nbsp; defaults&nbsp; &nbsp;&nbsp;&nbsp;1 2 <br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 修改为：<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; LABEL=/home&nbsp; &nbsp;/home&nbsp; &nbsp;ext3&nbsp; &nbsp; defaults,usrquota&nbsp; &nbsp;&nbsp;&nbsp;1 2<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 或者：<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; LABEL=/home&nbsp; &nbsp;/home&nbsp; &nbsp;ext3&nbsp; &nbsp; defaults,usrquota,grpquota&nbsp; &nbsp;&nbsp;&nbsp;1 2<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# reboot<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;或者<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# mount -o remount /dev/sda2&nbsp;&nbsp;// 其中/dev/sda2的挂接点就是/home,这样可以不用启动系统。<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;# quotacheck -avu&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //说明：a-自动开启挂载文件系统的配额，v-显示信息，u-启用用户配额or g-启用组配额<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;2.限额配置文件的修改<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # edquota virtual //为用户virtual设置磁盘配额<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 或者：<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # edquota -g grp&nbsp;&nbsp;//为组grp设置磁盘配额<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 系统会自动打开配额文件,如下:<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Disk quotas for user virtual (uid 502):<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Filesystem&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;blocks&nbsp; &nbsp;&nbsp; &nbsp; soft&nbsp; &nbsp;&nbsp; &nbsp; hard&nbsp; &nbsp;&nbsp;&nbsp;inodes&nbsp; &nbsp;&nbsp;&nbsp;soft&nbsp; &nbsp;&nbsp;&nbsp;hard<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;/dev/sda2&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;424&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;13&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;0<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #第一列是启用了配额的文件系统的名称。第二列显示了用户当前使用的块数，单位为KB。随后的两列用来设置用户在该文件系统上的软硬块限度。<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;inodes 列显示了用户当前使用的i节点数量。最后两列用来设置用户在该文件系统上的软硬i节点限度.硬限是用户或组群可以使用的磁盘空间的<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;绝对最大值。达到了该限度后，磁盘空间就不能再被用户或组群使用了。软限定义可被使用的最大磁盘空间量。和硬限不同的是，软限可以在一段<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;时期内被超过。这段时期被称为过渡期（grace period），默认七天的超越。过渡期可以用秒钟、分钟、小时、天数、周数、或月数表示。如果<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;以上值中的任何一个被设置为 0，那个限度就不会被设置。我设置了硬块限度为1KB，是为了测试方便。<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # quotaon&nbsp;&nbsp;-avu&nbsp;&nbsp;//打开磁盘配额监控进程，u是用户g是组，这里我没设置g参数<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;要校验用户的配额是否被设置，我们可以使用以下命令：<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # quota virtual<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Disk quotas for user virtual (uid 502): <br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Filesystem&nbsp;&nbsp;blocks&nbsp; &nbsp;quota&nbsp; &nbsp;limit&nbsp; &nbsp; grace&nbsp; &nbsp;files&nbsp; &nbsp;quota&nbsp; &nbsp;limit&nbsp; &nbsp;grace<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;/dev/sda2&nbsp; &nbsp;&nbsp;&nbsp;424*&nbsp; &nbsp; 0&nbsp; &nbsp;&nbsp; &nbsp;1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;13&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # edquota &#8211;t（-g）来设置过渡期（grace period） //当然只针对软限制而言和另一个 edquota 命令相似，这个命令也会在文本编辑器中<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;打开当前的文件系统配额：<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Grace period before enforcing soft limits for users:<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Time units may be: days, hours, minutes, or seconds<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Filesystem&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Block grace period&nbsp; &nbsp;&nbsp;&nbsp;Inode grace period<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; /dev/sda2&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;7days&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;7days<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 按你的需要修改后存盘退出<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 用以下命令显示磁盘配额使用状态<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # repquota&nbsp;&nbsp;-a&nbsp;&nbsp;或 repquota&nbsp;&nbsp;/dev/sda2（用户配额）<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; # repquota -g -a 或 repquota -a /dev/sda2 (组的配额)</div>
<img src ="http://www.cnitblog.com/everspring/aggbug/49853.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/everspring/" target="_blank">everspring</a> 2008-10-05 10:30 <a href="http://www.cnitblog.com/everspring/articles/49853.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>