个人工具

“Vsftpd”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
实例
/etc/vsftpd.conf
第57行: 第57行:
  
 
==/etc/vsftpd.conf==
 
==/etc/vsftpd.conf==
<pre># Example config file /etc/vsftpd.conf
+
<pre>listen=<YES/NO> :设置为YES时vsftpd以独立运行方式启动,设置为NO时以xinetd方式启动(xinetd是管理守护进程的,将服务集中管理,可以减少大量服务的资源消耗)
 
+
listen_port=<port> :设置控制连接的监听端口号,默认为21
# Run standalone?  vsftpd can run either from an inetd or as a standalone
+
listen_address=<ip address> :将在绑定到指定IP地址运行,适合多网卡
# daemon started from an initscript.
+
connect_from_port_20=<YES/NO> :若为YES,则强迫FTP-DATA的数据传送使用port 20,默认YES
listen=YES
+
pasv_enable=<YES/NO> :是否使用被动模式的数据连接,如果客户机在防火墙后,请开启为YES
#
+
pasv_min_port=<n>
# Run standalone with IPv6?
+
pasv_max_port=<m> :设置被动模式后的数据连接端口范围在n和m之间,建议为50000-60000端口
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
+
message_file=<filename> :设置使用者进入某个目录时显示的文件内容,默认为 .message
# instead of an IPv4 one. This parameter and the listen parameter are mutually
+
dirmessage_enable=<YES/NO> :设置使用者进入某个目录时是否显示由message_file指定的文件内容
# exclusive.
+
ftpd_banner=<message> :设置用户连接服务器后的显示信息,就是欢迎信息
#listen_ipv6=YES
+
banner_file=<filename> :设置用户连接服务器后的显示信息存放在指定的filename文件中
#
+
connect_timeout=<n> :如果客户机连接服务器超过N秒,则强制断线,默认60
# Allow anonymous FTP? (Disabled by default)
+
accept_timeout=<n> :当使用者以被动模式进行数据传输时,服务器发出passive port指令等待客户机超过N秒,则强制断线,默认60
anonymous_enable=NO
+
accept_connection_timeout=<n> :设置空闲的数据连接在N秒后中断,默认120
#
+
data_connection_timeout=<n> : 设置空闲的用户会话在N秒后中断,默认300
# Uncomment this to allow local users to log in.
+
max_client=<n> : 在独立启动时限制服务器的连接数,0表示无限制
local_enable=NO
+
max_per_ip=<n> :在独立启动时限制客户机每IP的连接数,0表示无限制(不知道是否跟多线程下载有没干系)
#
+
local_enable=<YES/NO> :设置是否支持本地用户帐号访问
# Uncomment this to enable any form of FTP write command.
+
guest_enable=<YES/NO> :设置是否支持虚拟用户帐号访问
#write_enable=YES
+
write_enable=<YES/NO> :是否开放本地用户的写权限
#
+
local_umask=<nnn> :设置本地用户长传的文件的生成掩码,默认为077
# Default umask for local users is 077. You may wish to change this to 022,
+
local_max_rate<n> :设置本地用户最大的传输速率,单位为bytes/sec,值为0表示不限制
# if your users expect that (022 is used by most other ftpd's)
+
local_root=<file> :设置本地用户登陆后的目录,默认为本地用户的主目录
#local_umask=022
+
chroot_local_user=<YES/NO> :当为YES时,所有本地用户可以执行chroot
#
+
chroot_list_enable=<YES/NO>
# Uncomment this to allow the anonymous FTP user to upload files. This only
+
chroot_list_file=<filename> :当chroot_local_user=NO 且 chroot_list_enable=YES时,只有filename文件指定的用户可以执行chroot
# has an effect if the above global write enable is activated. Also, you will
+
anonymous_enable=<YES/NO> :设置是否支持匿名用户访问
# obviously need to create a directory writable by the FTP user.
+
anon_max_rate=<n> :设置匿名用户的最大传输速率,单位为B/s,值为0表示不限制
#anon_upload_enable=YES
+
anon_world_readable_only=<YES/NO> 是否开放匿名用户的浏览权限
#
+
anon_upload_enable=<YES/NO> 设置是否允许匿名用户上传
# Uncomment this if you want the anonymous FTP user to be able to create
+
anon_mkdir_write_enable=<YES/NO> :设置是否允许匿名用户创建目录
# new directories.
+
anon_other_write_enable=<YES/NO> :设置是否允许匿名用户其他的写权限(注意,这个在安全上比较重要,一般不建议开,不过关闭会不支持续传)
#anon_mkdir_write_enable=YES
+
anon_umask=<nnn> :设置匿名用户上传的文件的生成掩码,默认为077
#
+
anon_root=<file> :设置匿名用户登陆后的目录
# Activate directory messages - messages given to remote users when they
+
no_anon_password=<YES/NO> :设置匿名用户登陆是否询问密码
# go into a certain directory.
+
ascii_download_enable=<YES/NO>
dirmessage_enable=YES
+
ascii_upload_enable=<YES/NO> :一般为NO,启动这个可能会导致DoS的攻击
#
+
hide_ids=<YES/NO> :如果启动,所有档案拥有者与组群都为FTP,也是就ls -l之类指令看到的拥有者和组均为FTP
# If enabled, vsftpd will display directory listings with the time
+
ls_recurse_enable=<YES/NO> :启动此功能,则允许登录者使用ls -R这个指令,默认为NO
# in  your  local  time  zone.  The default is to display GMT. The
+
tcp_wrappers=<YES/NO> :设置服务器是否支持tcp_wrappers(就是支持/etc/hosts.allow和/etc/hosts.deny这两个文件)
# times returned by the MDTM FTP command are also affected by this
+
pam_service_name=vsftpd :设置PAM模块的名称
# option.
+
xferlog_enable=<YES/NO> :是否启动FTP日志记录
use_localtime=YES
+
xferlog_file=/var/log/vsftpd.log :设置日志记录文件的名称
#
+
xferlog_std_format=<YES/NO> :当设置为YES时,将使用与wu-ftpd相同的日志记录格式</pre>
# 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.
+
# Note that the default log file location is /var/log/xferlog in this case.
+
#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 on some FTP servers, ASCII support allows a denial of service
+
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
+
# predicted this attack and has always been safe, reporting the size of the
+
# raw file.
+
# ASCII mangling is a horrible feature of the protocol.
+
#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 restrict local users to their home directories.  See the FAQ for
+
# the possible risks in this before using chroot_local_user or
+
# chroot_list_enable below.
+
#chroot_local_user=YES
+
#
+
# You may specify an explicit list of local users to chroot() to their home
+
# directory. If chroot_local_user is YES, then this list becomes a list of
+
# users to NOT chroot().
+
#chroot_local_user=YES
+
#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
+
#
+
# Debian customization
+
#
+
# Some of vsftpd's settings don't fit the Debian filesystem layout by
+
# default.  These settings are more Debian-friendly.
+
#
+
# This option should be the name of a directory which is empty.  Also, the
+
# directory should not be writable by the ftp user. This directory is used
+
# as a secure chroot() jail at times vsftpd does not require filesystem
+
# access.
+
secure_chroot_dir=/var/run/vsftpd/empty
+
#
+
# This string is the name of the PAM service vsftpd will use.
+
pam_service_name=vsftpd
+
#
+
# This option specifies the location of the RSA certificate to use for SSL
+
# encrypted connections.
+
rsa_cert_file=/etc/ssl/private/vsftpd.pem</pre>
+
  
 
==匿名用户==
 
==匿名用户==

2010年7月2日 (五) 22:01的版本

vsftpd,ftp服务端

stand alone和super daemon

stand alone指的是一直运行vsftpd,占用资源,提供ftp服务。super daemon指的是有需要时由xinted启动vsftpd服务。如果服务器不是那种长期开ftp,提供大量的上传下载服务的话,会选择后者。

安装

安装

sudo apt-get install vsftpd

查看是否打开21端口

qii@ubuntu:~$ sudo netstat -tulnp| grep 21
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      15601/vsftpd    

登录

ftp localhost

输入Ubuntu的用户名、密码登录

ls

会显示home目录的文件

文件结构

匿名用户根路径

/srv/ftp

配置文件

/etc/vsftpd.conf

查阅配置文件详细信息

man 5 vsftpd.conf

设定log保存位置,默认如下

xferlog_file=/var/log/vsftpd.log

运行

standalone

最普遍的方式

sudo service vsftpd start

super daemon

需要修改vsftpd.conf

listen=NO

这里若不改成NO,会出现下列错误

500 OOPS: could not bind listening IPv4 socket

安装xinetd

sudo apt-get install xinetd
sudo vi /etc/xinetd.conf
service ftp
{
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /usr/sbin/vsftpd
        log_on_success          += DURATION USERID
        log_on_failure          += USERID
        nice                    = 10
        disable                 = no
}

停止vsftpd,启动xinetd

sudo service vsftpd stop
sudo service xinetd start

查看端口

qii@ubuntu:~$ sudo netstat -tulnp| grep 21
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      16787/xinetd  

/etc/vsftpd.conf

listen=<YES/NO> :设置为YES时vsftpd以独立运行方式启动,设置为NO时以xinetd方式启动(xinetd是管理守护进程的,将服务集中管理,可以减少大量服务的资源消耗)
listen_port=<port> :设置控制连接的监听端口号,默认为21
listen_address=<ip address> :将在绑定到指定IP地址运行,适合多网卡
connect_from_port_20=<YES/NO> :若为YES,则强迫FTP-DATA的数据传送使用port 20,默认YES
pasv_enable=<YES/NO> :是否使用被动模式的数据连接,如果客户机在防火墙后,请开启为YES
pasv_min_port=<n>
pasv_max_port=<m> :设置被动模式后的数据连接端口范围在n和m之间,建议为50000-60000端口
message_file=<filename> :设置使用者进入某个目录时显示的文件内容,默认为 .message
dirmessage_enable=<YES/NO> :设置使用者进入某个目录时是否显示由message_file指定的文件内容
ftpd_banner=<message> :设置用户连接服务器后的显示信息,就是欢迎信息
banner_file=<filename> :设置用户连接服务器后的显示信息存放在指定的filename文件中
connect_timeout=<n> :如果客户机连接服务器超过N秒,则强制断线,默认60
accept_timeout=<n> :当使用者以被动模式进行数据传输时,服务器发出passive port指令等待客户机超过N秒,则强制断线,默认60
accept_connection_timeout=<n> :设置空闲的数据连接在N秒后中断,默认120
data_connection_timeout=<n> : 设置空闲的用户会话在N秒后中断,默认300
max_client=<n> : 在独立启动时限制服务器的连接数,0表示无限制
max_per_ip=<n> :在独立启动时限制客户机每IP的连接数,0表示无限制(不知道是否跟多线程下载有没干系)
local_enable=<YES/NO> :设置是否支持本地用户帐号访问
guest_enable=<YES/NO> :设置是否支持虚拟用户帐号访问
write_enable=<YES/NO> :是否开放本地用户的写权限
local_umask=<nnn> :设置本地用户长传的文件的生成掩码,默认为077
local_max_rate<n> :设置本地用户最大的传输速率,单位为bytes/sec,值为0表示不限制
local_root=<file> :设置本地用户登陆后的目录,默认为本地用户的主目录
chroot_local_user=<YES/NO> :当为YES时,所有本地用户可以执行chroot
chroot_list_enable=<YES/NO> 
chroot_list_file=<filename> :当chroot_local_user=NO 且 chroot_list_enable=YES时,只有filename文件指定的用户可以执行chroot
anonymous_enable=<YES/NO> :设置是否支持匿名用户访问
anon_max_rate=<n> :设置匿名用户的最大传输速率,单位为B/s,值为0表示不限制
anon_world_readable_only=<YES/NO> 是否开放匿名用户的浏览权限
anon_upload_enable=<YES/NO> 设置是否允许匿名用户上传
anon_mkdir_write_enable=<YES/NO> :设置是否允许匿名用户创建目录
anon_other_write_enable=<YES/NO> :设置是否允许匿名用户其他的写权限(注意,这个在安全上比较重要,一般不建议开,不过关闭会不支持续传)
anon_umask=<nnn> :设置匿名用户上传的文件的生成掩码,默认为077
anon_root=<file> :设置匿名用户登陆后的目录
no_anon_password=<YES/NO> :设置匿名用户登陆是否询问密码 
ascii_download_enable=<YES/NO>
ascii_upload_enable=<YES/NO> :一般为NO,启动这个可能会导致DoS的攻击
hide_ids=<YES/NO> :如果启动,所有档案拥有者与组群都为FTP,也是就ls -l之类指令看到的拥有者和组均为FTP
ls_recurse_enable=<YES/NO> :启动此功能,则允许登录者使用ls -R这个指令,默认为NO
tcp_wrappers=<YES/NO> :设置服务器是否支持tcp_wrappers(就是支持/etc/hosts.allow和/etc/hosts.deny这两个文件)
pam_service_name=vsftpd :设置PAM模块的名称
xferlog_enable=<YES/NO> :是否启动FTP日志记录
xferlog_file=/var/log/vsftpd.log :设置日志记录文件的名称
xferlog_std_format=<YES/NO> :当设置为YES时,将使用与wu-ftpd相同的日志记录格式

匿名用户

先备份

sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.old

打开

sudo vi /etc/vsftpd.conf

允许匿名访问

# Allow anonymous FTP? (Disabled by default)
anonymous_enable=YES

允许匿名上传

anon_upload_enable=YES

认证FTP配置

设定vsftp认证系统用户,并允许他们上传文件,编辑 /etc/vsftpd.conf:

local_enable=YES
write_enable=YES

重启vsftp

sudo service vsftpd restart

系统用户登录ftp便进入他们的home目录

Chroot

限制所有

限制登录用户访问其他目录,改之前登录显示的路径比如是 /home/qii ,改之后则是 /。

chroot_local_user=YES

开放所有,限制特定

可指定一组用户限制

chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

随后创建列表

sudo vi  /etc/vsftpd.chroot_list

一行一个用户名 重启vsftp

sudo service vsftpd restart

限制所有,开放特定

上面的规则是限制 /etc/vsftpd.chroot_list 中的用户,反过来限制一切,只解禁 /etc/vsftpd.chroot_list 的用户。这样:

chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

账号登录

/etc/ftpusers文件

该文件内的用户一律禁止ftp连接,默认列表包括了root, daemon, nobody等。需要禁止某个用户,添加进来便是。

这个文件是由PAM模块的 /etc/pam.d/vsftpd 指定的

qii@ubuntu:~$ sudo cat /etc/pam.d/vsftpd
# Standard behaviour for ftpd(8).
auth    required        pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed

# Note: vsftpd handles anonymous logins on its own. Do not enable pam_ftp.so.

# Standard pam includes
@include common-account
@include common-session
@include common-auth
auth    required        pam_shells.so

userlist_file 文件

vsftpd自订的列表,跟/etc/ftpusers类似,具体文件名和路径是由用户自己指定的。这边设成 /etc/vsftpd.user_list

添加配置文件字段:

userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd.user_list

限制一切,开放特定

上述2个方法都是限制列表文件中的用户,如果要反过来,限制一切用户登录,只允许列表文件中的用户,用 userlist_file,这样:

userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd.user_list

root登录

之所以限制root这类账号登录就是托上面几个文件,要是你非要用系统账号登录,如上所述,将列表文件中的特定用户名删除便是。

限制

限制连接数

前者为服务器最大支持连接数,后者为每个ip允许最多连接数。

max_clients=数字
max_per_ip=数字

错误提示分别是

qii@ubuntu:~$ ftp localhost 
Connected to localhost.
421 There are too many connected users, please try later.
qii@ubuntu:~$ ftp localhost 
Connected to localhost.
421 There are too many connections from your internet address.

限制下载速度

单位是字节,所以需要换算。比如我想让匿名用户和vsFTP上的用户都以80KB下载,所以这个数字应该是1024x80=81920

anon_max_rate=数字 #匿名用户下载速度
local_max_rate=数字 #普通用户下载速度

super daemon限制连接数

instances 是服务器最多的连接数,per_source 是单个IP地址最多的连接数。

service ftp
{
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /usr/sbin/vsftpd
        server_args             = /etc/vsftpd.conf 
        log_on_success          += DURATION USERID
        log_on_failure          += USERID
        nice                    = 10
        disable                 = no
        per_source              = 10   
        instances               = 10  
}

错误提示都是

qii@ubuntu:~$ ftp localhost 
Connected to localhost.
421 Service not available, remote server has closed connection

定制错误提示,添加

banner_fail       = /etc/vsftpd.busy_banner

编辑提示内容

sudo vi /etc/vsftpd.busy_banner

比如

qii@ubuntu:~$ ftp localhost 
Connected to localhost.
服务器大姨妈中

super daemon限制主机访问

只允许指定主机访问

在配置文件/etc/xinetd.d/vsftpd的{}中添加如下的配置语句:

only_from <主机表> 

如 only_from 192.168.1.0 表示只允许192.168.1.0网段内的主机访问。

指定不能访问的主机

no_access <主机表> 

如:no_access 192.168.1.0 表示只有192.168.1.0网段内的主机不能访问。

主机表

关于主机表的书写形式,见下表:

访问控制表时主机表的书写语法
选项值 含义 
Hostname 可解析的主机名 
IP Address 十进制表示的IP地址 
Net_name 在/etc/networks中定义的网络名 
x.x.x.0 x.x.0.0 x.0.0.0 0.0.0.0 0作为通配符看待。如:191.72.61.0匹配从191.72.61.0到191.72.61.255的所有IP地址。0.0.0.0表示匹配所有的IP地址 
x.x.x.{a,b,.} x.x.{a,b,.} x.{a,b,.} 指定主机表。如:191.72.61.{1,3,123}表示包含地址191.72.61.1、191.72.61.2和191.72.61.123 
IPAddress/netmask 定义要匹配的网络或子网。如:172.19.16/20匹配从172.19.16.0到172.19.31.255 

欢迎信息

dirmessage_enable=YES

然后编辑各用户home目录下的.message

vi .message
qii@ubuntu:~$ cat .message 
欢迎来到vsftpd
qii@ubuntu:~$ ftp localhost 
Connected to localhost.
220 (vsFTPd 2.2.2)
Name (localhost:qii): qii
331 Please specify the password.
Password:
230-欢迎来到vsftpd
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

若是匿名用户,就放到

/var/ftp

虚拟路径

比如我的ftp的默认目录是/srv/ftp,我想把/mnt/LinG/WinSoft文件夹,映射到/srv/ftp目录中,我就如下操作 命令:

#mount --bind [原有的目录] [新目录]

先创建文件夹

sudo mkdir /srv/ftp/WinSoft

执行mount命令

sudo mount --bind /mnt/LinG/WinSoft /srv/ftp/WinSoft

实例

Vsftpd实例

Vsftpd虚拟用户设置

Vsftpd和mysql配置