vsftp配置文件

直接使用,本地用户可以使用账号密码登录

# 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.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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/xferlog
#
# 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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# 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
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES


local_root=/var/ftp/pub/



chmod -R 777   /var/ftp/pub

总结

FTP  
C/S   TCP 控制通道及数据通道
主动模式/被动模式  服务器来讲,数据通道服务器连接客户端  vsftp   serv-u
虚拟用户映射本地用户
e-mail 
MUA   用户代理  MTA  传输代理  sendmail  postfix 
SMTP   25  服务器间传输
POP3   110   C/S   接邮件
IMAP   摘要浏览,信息还在服务器 
#vsftp
ftp运行的两种模式——xinetd运行模式和 standalone模式
1.standalone一次性启动,运行期间一直驻留在内存中,优点是对接入信号反应快,缺点是损耗了一定的系统资源,因此经常应用于对实时反应要求较高的 专业FTP服务器
2.inetd恰恰相反,由于只在外部连接发送请求时才调用FTP进程,因此不适合应用在同时连接数量较多的系统,inetd模式不 占用系统资源
3.inetd模式支持per_IP(单一IP)限制,而 standalone模式则更有利于PAM验证功能的应用
xinetd运行模式
大多数较新的系统采用的是xinetd超级服务守护进程。使用“vi /etc/xinetd.d/vsftpd” 看一下它的内容,如下:
disable = no  
socket_type = stream
wait = no
# 这表示设备是激活的,它正在使用标准的TCP Sockets。
如果“/etc/vsftpd.conf”中的有选项为“listen=YES”,注销它
standalone模式便于实现PAM验证功能。进入这种模式首先要关闭xinetd下的vsftpd,设置
“disable = yes”,或者注销掉“/etc/inetd.conf”中相应的行。然后修改“/etc/vsftpd.con
f”中的选项为“listen=YES”
它是一个安全、高速、稳定的FTP服务器; 
模式: C/S 模式 
端口:20 (传数据) 21 (传指令
控制通道与数据传输通道     被动与主动


1.默认配置: 
1>允许匿名用户和本地用户登陆。 
anonymous_enable=YES 
local_enable=YES 
2>匿名用户使用的登陆名为ftp或anonymous,口令为空;匿名用户不能离开匿名 用户家目录/var/ftp,且只能下载不能上传。 
3>本地用户的登录名为本地用户名,口令为此本地用户的口令;本地用户可以在自己家目录中进行读写操作;本地用户可以离开自家目录切换至有权限访问的其他目录,并在权限允许的情况下进行上传/下载。 
write_enable=YES 
4>写在文件/etc/vsftpd.ftpusers中的本地用户禁止登陆。 
2.配置文件格式: 
vsftpd.conf 的内容非常单纯,每一行即为一项设定。若是空白行或是开头为#的一行,将会被忽略。内容的格式只有一种,如下所示 
option=value 
要注意的是,等号两边不能加空白。 
3.匿名用户(anonymous)设置 
anonymous_enable=YES/NO(YES) 
控制是否允许匿名用户登入,YES 为允许匿名登入,NO 为不允许。默认值为YES。 
write_enable=YES/NO(YES) 
是否允许登陆用户有写权限。属于全局设置,默认值为YES。 
no_anon_password=YES/NO(NO) 
若是启动这项功能,则使用匿名登入时,不会询问密码。默认值为NO。 
ftpftp_username=ftp 
定义匿名登入的使用者名称。默认值为ftp。 
anon_root=/var/ftp 
使用匿名登入时,所登入的目录。默认值为/var/ftp。注意ftp目录不能是777的权限属性,即匿名用户的家目录不能有777的权限。 
anon_upload_enable=YES/NO(NO) 
如果设为YES,则允许匿名登入者有上传文件(非目录)的权限,只有在write_enable=YES时,此项才有效。当然,匿名用户必须要有对上层目录的写入权。默认值为NO。 
anon_world_readable_only=YES/NO(YES) 
如果设为YES,则允许匿名登入者下载可阅读的档案(可以下载到本机阅读,不能直接在FTP服务器中打开阅读)。默认值为YES。 
anon_mkdir_write_enable=YES/NO(NO) 
如果设为YES,则允许匿名登入者有新增目录的权限,只有在write_enable=YES时,此项才有效。当然,匿名用户必须要有对上层目录的写入权。默认值为NO。 
anon_other_write_enable=YES/NO(NO) 
如 果设为YES,则允许匿名登入者更多于上传或者建立目录之外的权限,譬如删除或者重命名。(如果anon_upload_enable=NO,则匿名用户 不能上传文件,但可以删除或者重命名已经存在的文件;如果anon_mkdir_write_enable=NO,则匿名用户不能上传或者新建文件夹,但 可以删除或者重命名已经存在的文件夹。)默认值为NO。 
chown_uploads=YES/NO(NO) 
设置是否改变匿名用户上传文件(非目录)的属主。默认值为NO。 
chown_username=username 
设置匿名用户上传文件(非目录)的属主名。建议不要设置为root。 
anon_umask=077 
设置匿名登入者新增或上传档案时的umask 值。默认值为077,则新建档案的对应权限为700。 
deny_email_enable=YES/NO(NO) 
若是启动这项功能,则必须提供一个档案/etc/vsftpd/banner_emails,内容为email address。若是使用匿名登入,则会要求输入email address,若输入的email address 在此档案内,则不允许进入。默认值为NO。 
banned_email_file=/etc/vsftpd/banner_emails 
此文件用来输入email address,只有在deny_email_enable=YES时,才会使用到此档案。若是使用匿名登入,则会要求输入email address,若输入的email address 在此档案内,则不允许进入。 
4.本地用户设置 
local_enable=YES/NO(YES) 
控制是否允许本地用户登入,YES 为允许本地用户登入,NO为不允许。默认值为YES。 
local_root=/home/username 
当本地用户登入时,将被更换到定义的目录下。默认值为各用户的家目录。 
write_enable=YES/NO(YES) 
是否允许登陆用户有写权限。属于全局设置,默认值为YES。 
local_umask=022 
本地用户新增档案时的umask 值。默认值为077。 
file_open_mode=0755 
本地用户上传档案后的档案权限,与chmod 所使用的数值相同。默认值为0666。 
5.欢迎语设置 
dirmessage_enable=YES/NO(YES) 
如果启动这个选项,那么使用者第一次进入一个目录时,会检查该目录下是否有.message这个档案,如果有,则会出现此档案的内容,通常这个档案会放置欢迎话语,或是对该目录的说明。默认值为开启。 
message_file=.message 
设置目录消息文件,可将要显示的信息写入该文件。默认值为.message。 
banner_file=/etc/vsftpd/banner 
当使用者登入时,会显示此设定所在的档案内容,通常为欢迎话语或是说明。默认值为无。如果欢迎信息较多,则使用该配置项。 
ftpd_banner=Welcome to BOB’s FTP server 
这里用来定义欢迎话语的字符串,banner_file是档案的形式,而ftpd_banner 则是字符串的形式。预设为无。 
6.控制用户是否允许切换到上级目录 
在默认配置下,本地用户登入FTP后可以使用cd命令切换到其他目录,这样会对系统带来安全隐患。可以通过以下三条配置文件来控制用户切换目录。 
chroot_list_enable=YES/NO(NO) 
设置是否启用chroot_list_file配置项指定的用户列表文件。默认值为NO。 
chroot_list_file=/etc/vsftpd.chroot_list 
用于指定用户列表文件,该文件用于控制哪些用户可以切换到用户家目录的上级目录。 
chroot_local_user=YES/NO(NO) 
用于指定用户列表文件中的用户是否允许切换到上级目录。默认值为NO。 
通过搭配能实现以下几种效果: 
①当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。 
②当chroot_list_enable=YES,chroot_local_user=NO时,在/etc/vsftpd.chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录。 
③当chroot_list_enable=NO,chroot_local_user=YES时,所有的用户均不能切换到其他目录。 
④当chroot_list_enable=NO,chroot_local_user=NO时,所有的用户均可以切换到其他目录。 
7.数据传输模式设置 
FTP在传输数据时,可以使用二进制方式,也可以使用ASCII模式来上传或下载数据。 
ascii_upload_enable=YES/NO(NO) 
设置是否启用ASCII 模式上传数据。默认值为NO。 
ascii_download_enable=YES/NO(NO) 
设置是否启用ASCII 模式下载数据。默认值为NO。 
8.访问控制设置 
两种控制方式:一种控制主机访问,另一种控制用户访问。 
①控制主机访问: 
tcp_wrappers=YES/NO(YES) 
设 置vsftpd是否与tcp wrapper相结合来进行主机的访问控制。默认值为YES。如果启用,则vsftpd服务器会检查/etc/hosts.allow 和/etc/hosts.deny 中的设置,来决定请求连接的主机,是否允许访问该FTP服务器。这两个文件可以起到简易的防火墙功能。 
比如:若要仅允许192.168.0.1—192.168.0.254的用户可以连接FTP服务器,则在/etc/hosts.allow文件中添加以下内容: 
vsftpd:192.168.0. :allow 
all:all :deny 
②控制用户访问: 
对于用户的访问控制可以通过/etc目录下的vsftpd.user_list和ftpusers文件来实现。 
userlist_file=/etc/vsftpd.user_list 
控制用户访问FTP的文件,里面写着用户名称。一个用户名称一行。 
userlist_enable=YES/NO(NO) 
是否启用vsftpd.user_list文件。 
userlist_deny=YES/NO(YES) 
决定vsftpd.user_list文件中的用户是否能够访问FTP服务器。若设置为YES,则vsftpd.user_list文件中的用户不允许访问FTP,若设置为NO,则只有vsftpd.user_list文件中的用户才能访问FTP。 
/etc /vsftpd/ftpusers文件专门用于定义不允许访问FTP服务器的用户列表(注意:如果 userlist_enable=YES,userlist_deny=NO,此时如果在vsftpd.user_list和ftpusers中都有某个 用户时,那么这个用户是不能够访问FTP的,即ftpusers的优先级要高)。默认情况下vsftpd.user_list和ftpusers,这两个 文件已经预设置了一些不允许访问FTP服务器的系统内部账户。如果系统没有这两个文件,那么新建这两个文件,将用户添加进去即可。 
9.访问速率设置 
anon_max_rate=0 
设置匿名登入者使用的最大传输速度,单位为B/s,0 表示不限制速度。默认值为0。 
local_max_rate=0 
本地用户使用的最大传输速度,单位为B/s,0 表示不限制速度。预设值为0。 
10.超时时间设置 
accept_timeout=60 
设置建立FTP连接的超时时间,单位为秒。默认值为60。 
connect_timeout=60 
PORT 方式下建立数据连接的超时时间,单位为秒。默认值为60。 
data_connection_timeout=120 
设置建立FTP数据连接的超时时间,单位为秒。默认值为120。 
idle_session_timeout=300 
设置多长时间不对FTP服务器进行任何操作,则断开该FTP连接,单位为秒。默认值为300 。 
11.日志文件设置 
xferlog_enable= YES/NO(YES) 
是否启用上传/下载日志记录。如果启用,则上传与下载的信息将被完整纪录在xferlog_file 所定义的档案中。预设为开启。 
xferlog_file=/var/log/vsftpd.log 
设置日志文件名和路径,默认值为/var/log/vsftpd.log。 
xferlog_std_format=YES/NO(NO) 
如果启用,则日志文件将会写成xferlog的标准格式,如同wu-ftpd 一般。默认值为关闭。 
log_ftp_protocol=YES|NO(NO) 
如果启用此选项,所有的FTP请求和响应都会被记录到日志中,默认日志文件在/var/log/vsftpd.log。启用此选项时,xferlog_std_format不能被激活。这个选项有助于调试。默认值为NO。 
12.定义用户配置文件 
在vsftpd中,可以通过定义用户配置文件来实现不同的用户使用不同的配置。 
user_config_dir=/etc/vsftpd/userconf 
设置用户配置文件所在的目录。当设置了该配置项后,用户登陆服务器后,系统就会到/etc/vsftpd/userconf目录下,读取与当前用户名相同的文件,并根据文件中的配置命令,对当前用户进行更进一步的配置。 
例 如:定义user_config_dir=/etc/vsftpd/userconf,且主机上有使用者 test1,test2,那么我们就在user_config_dir 的目录新增文件名为test1和test2两个文件。若是test1 登入,则会读取user_config_dir 下的test1 这个档案内的设定。默认值为无。利用用户配置文件,可以实现对不同用户进行访问速度的控制,在各用户配置文件中定义local_max_rate=XX, 即可。 
13.FTP的工作方式与端口设置 
FTP有两种工作方式:PORT FTP(主动模式)和PASV FTP(被动模式) 
listen_port=21 
设置FTP服务器建立连接所监听的端口,默认值为21。 
connect_from_port_20=YES/NO 
指定FTP使用20端口进行数据传输,默认值为YES。 
ftp_data_port=20 
设置在PORT方式下,FTP数据连接使用的端口,默认值为20。 
pasv_enable=YES/NO(YES) 
若设置为YES,则使用PASV工作模式;若设置为NO,则使用PORT模式。默认值为YES,即使用PASV工作模式。 
pasv_max_port=0 
在PASV工作模式下,数据连接可以使用的端口范围的最大端口,0 表示任意端口。默认值为0。 
pasv_min_port=0 
在PASV工作模式下,数据连接可以使用的端口范围的最小端口,0 表示任意端口。默认值为0。 
14.与连接相关的设置 
listen=YES/NO(YES) 
设 置vsftpd服务器是否以standalone模式运行。以standalone模式运行是一种较好的方式,此时listen必须设置为YES,此为默 认值。建议不要更改,有很多与服务器运行相关的配置命令,需要在此模式下才有效。若设置为NO,则vsftpd不是以独立的服务运行,要受到xinetd 服务的管控,功能上会受到限制。 
max_clients=0 
设置vsftpd允许的最大连接数,默认值为0,表示不受限制。若设置为100时,则同时允许有100个连接,超出的将被拒绝。只有在standalone模式运行才有效。 
max_per_ip=0 
设置每个IP允许与FTP服务器同时建立连接的数目。默认值为0,表示不受限制。只有在standalone模式运行才有效。 
listen_address=IP地址 
设置FTP服务器在指定的IP地址上侦听用户的FTP请求。若不设置,则对服务器绑定的所有IP地址进行侦听。只有在standalone模式运行才有效。 
setproctitle_enable=YES/NO(NO) 
设置每个与FTP服务器的连接,是否以不同的进程表现出来。默认值为NO,此时使用ps aux |grep ftp只会有一个vsftpd的进程。若设置为YES,则每个连接都会有一个vsftpd的进程。 
15.虚拟用户设置 
虚拟用户使用PAM认证方式。 
pam_service_name=vsftpd 
设置PAM使用的名称,默认值为/etc/pam.d/vsftpd。 
guest_enable= YES/NO(NO) 
启用虚拟用户。默认值为NO。 
guest_username=ftp 
这里用来映射虚拟用户。默认值为ftp。 
virtual_use_local_privs=YES/NO(NO) 
当该参数激活(YES)时,虚拟用户使用与本地用户相同的权限。当此参数关闭(NO)时,虚拟用户使用与匿名用户相同的权限。默认情况下此参数是关闭的(NO)。 
16.其他设置 
text_userdb_names= YES/NO(NO) 
设置在执行ls –la之类的命令时,是显示UID、GID还是显示出具体的用户名和组名。默认值为NO,即以UID和GID方式显示。若希望显示用户名和组名,则设置为YES。 
ls_recurse_enable=YES/NO(NO) 
若是启用此功能,则允许登入者使用ls –R(可以查看当前目录下子目录中的文件)这个指令。默认值为NO。 
hide_ids=YES/NO(NO) 
如果启用此功能,所有档案的拥有者与群组都为ftp,也就是使用者登入使用ls -al之类的指令,所看到的档案拥有者跟群组均为ftp。默认值为关闭。 
download_enable=YES/NO(YES) 
如果设置为NO,所有的文件都不能下载到本地,文件夹不受影响。默认值为YES。
】
/etc/vsftpd/vsftpd.conf: vsftpd 的核心配置文件 
/etc/vsftpd/ftpusers :用于指定哪些用户不能访问FTP 服务器。 黑名单 
/etc/vsftpd/user_list:指定允许使用vsftpd 的用户列表文件。 白名单
/etc/vsftpd/vsftpd_conf_migrate.sh是vsftpd 操作的一些变量和设置脚本 
/var/ftp/:默认情况下匿名用户的根目录
anon_mkdir_write_enable字段可以控制是否允许匿名用户创建目录。
anon_other_write_enable=YES
    
1、虚拟用户使用vsftpd服务器
虚拟用户是指在FTP服务器上拥有账号,并且该账号只能用于文件传输服务的用户,也称作Guest用户。该类用户可以通过输入账号以及口令来进行授权登录。登录入系统后,其登录目录为指定的目录。一般情况下,该类用户既可以下载也可以上传文件。
vsftpd的虚拟用户采用单独的用户名/口令保存方式,与系统账号(passwd/shadow)分离,这大大增强了系统的安全性。vsftpd可以采用数据库文件来保存用户/口令,如hash;也可以将用户/口令保存在数据库服务器中,如MySQL等。vsftpd验证虚拟用户,则采用PAM方式。由于虚拟用户的用户名/口令被单独保存,因此在验证时,vsftpd须要用一个系统用户的身份来读取数据库文件或数据库服务器以完成验证,这就是guest用户,这正如同匿名用户也需要有一个系统用户ftp一样。当然,guest用户也可以被认为是用于映射虚拟用户。
在虚拟用户使用vsftpd服务器之前,要对服务器进行配置,主要包括如下几个步骤:
(1)生成虚拟用户口令库文件。
(2)配置生成vsftpd的认证文件。
(3)建立虚拟用户访问所需要的目录并且设定相应的访问权限。
(4)建立配置文件。
(5)重新启动vsftpd服务器。
下面是完成上述五个步骤的基本命令和过程,如下所示:
生成虚拟用户口令库文件
//生成虚拟用户口令库文件,按照格式编辑口令文件。单数行为用户名,偶数行为用户口令
#vi login.txt
liyangsuper//用户名
real//口令
patterson//用户名
jef//口令
guest//用户名
guest//口令
//存盘退出
配置生成vsftpd的认证文件
//使用db_load命令生成口令库文件
#db_load –T –t hash –f login.txt /etc/vsftpd/vsftpd_login.db
//修改该口令库文件的权限
#chmod 600 /etc/vsftpd/vsftpd_login.db
//编辑虚拟用户所需的PAM配置文件
#vi /etc/pam.d/vsftpd
//在该文件中加入如下两行,并且保存后退出
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login.db
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login.db
建立虚拟用户访问所需要的目录并且设定相应的访问权限
#useradd –d /home/ftp virtual
#chmod 700 /home/ftp
对vsftpd的主配置文件进行配置
//为了保证安全,首先生成该文件的一个备份,然后进行修改
#cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
#vi /etc/vsftpd/vsftpd.conf
//配置相关选项如下所示
listen=YES
tcp_wrappers=YES //支持tcp_wrappers,限制访问
(/etc/hosts.allow,/etc/hosts.deny)
listen=YES的意思是使用standalone启动vsftpd,而不是super daemon(xinetd)控制它
(vsftpd推荐使用standalone方式)
anonymous_enable=NO
local_enable=YES //PAM方式此处必须为YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=YES
guest_enable=YES
guest_username=vsftpd //采用虚拟用户形式
重新启动vsftpd服务器
#service vsftpd restart
经过上面几个步骤的配置后,就可以使用虚拟用户登录vsftpd服务器了,如下所示:
使用创建的虚拟用户liyangsuper,登录成功:
#ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 Welcome to virtual FTP service.
Name (127.0.0.1:root): liyangsuper
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (127,0,0,1,119,210)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jul 09 15:26 ftp
226 Directory send OK.
能够浏览虚拟目录/home/ftp里的文件和目录
ftp> cd ftp
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (127,0,0,1,149,3)
150 Here comes the directory listing.
-rw-r--r--    1 0        0              10 Jul 09 15:26 test.c
226 Directory send OK.
测试是否能够创建目录
ftp> mkdir super
550 Permission denied.//操作被禁止
ftp> bye
221 Goodbye.
通过以上的测试可以知道,系统关于虚拟用户的默认用户权限与匿名用户的用户权限一致,都只有浏览以及下载的权限,而不具有上传和创建目录等写操作权限。
2、配置vsftpd服务器中chroot
在vsftpd服务器的默认设置中,本地用户可以切换到主目录以外的目录进行浏览访问,这样对于服务器来说是不太安全的,因为任何用户可以随时浏览到别的用户的私有信息,下面介绍如何使用chroot选项来防止这种情况的发生。
与该功能相关的选项主要包括:
chroot_local_user
chroot_list_enable
chroot_list_file
可以通过如下两种方法来设置chroot,从而杜绝上述不安全的情况发生:
(1)设置所有的本地用户执行chroot,只要将/etc/vsftpd/vsftpd.con文件中的chroot_local_ user值置为YES,即chroot_local_user=YES。
(2)设置指定的用户执行chroot,按照如下方法进行设置:
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
设置后,只有/etc/vsftpd.chroot_list文件中指定的用户才能够执行chroot命令。
3、配置vsftpd服务器在非标准端口工作
在使用FTP服务的过程中,可以使该服务在非标准端口(非21端口)工作,不过要完成这项工作,须要使vsftpd服务器运行在独立启动方式下,而且要配置vsftpd的主配置文件/etc/vsftpd/vsftpd.conf,将listen_port=10003或者是其他端口号的选项加入该文件即可,然后要重新启动vsftpd守护进程:
#service vsftpd restart
下面是对该功能进行实例验证:
使用匿名用户登录到服务器的10003端口,成功:
#ftp 127.0.0.1 10003
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 1.1.3)
Name (127.0.0.1:root): anonymous
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bye
221 Goodbye.
测试以前使用的21端口,该端口已经不再有用:
# ftp 127.0.0.1
ftp: connect: Connection refused
4、配置虚拟FTP服务器
所谓虚拟FTP服务器,是指一台机器上有多个IP地址,并且可以向外提供多FTP服务,这些服务器在逻辑上是独立的,有不同的访问控制表和不同的下载内容。
配置虚拟FTP服务器的步骤如下所示:
(1)为一个服务器配置多个IP地址。假设原来的主机内部地址为210.77.27.222,可再绑定一个IP地址如下:
向接口添加一个新的IP210.77.27.223
#/sbin/ifconfig eth0:0 210.77.27.223 up 
(2)创建虚拟FTP服务器的根目录,并确保/var/newftp和/var/newftp/pub目录的拥有者和组均为root,掩码为755。
#mkdir -p /var/newftp/pub
#chmod 755 /var/newftp
#chmod 755 /var/new/ftp/pub
(3)增加虚拟FTP服务器的匿名用户账号。原先的FTP服务器使用系统用户ftp作为其匿名用户账号。需要增加一个newftp用于虚拟FTP服务器。
useradd -d /var/newftp -M newftp
(4)创建虚拟FTP服务器的配置文件。复制原来的vsftpd.conf作为虚拟FTP服务器的配置文件,并修改相关参数。
#cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd2.conf
新添或修改以下参数:
listen=YES
listen_address=210.77.27.223
ftp_username=newftp
此处需要特别注意:由于vsftpd默认是监听所有的IP地址,当设定基于IP的虚拟FTP服务器时,为防止原来的FTP服务器与虚拟FTP服务器发生监听上的冲突,原FTP服务器须要指定监听的IP地址。在这里,原来的配置文件中就要设置listen_address=//向接口添加一个新的IP210.77.27.222。
(5)启动和测试虚拟FTP服务器。
可以使用命令同时启动或关闭原FTP服务器和新加的虚拟FTP服务器,如下:
#service vsftpd restart
Shutting down vsftpd:                                    [  OK  ]
Starting vsftpd for vsftpd2:                             [  OK  ]
Starting vsftpd for vsftpd:                              [  OK  ]
启动成功后,就可以对该虚拟服务器登录进行测试,如下面所示:
测试以127.0.0.1登录:
# ftp 127.0.0.1
ftp: connect: Connection refused
ftp> bye
//测试失败,因为该服务器具有两个不同的IP
连接原来的FTP服务器,其IP地址为210.77.27.222,端口号为10003:
# ftp 210.77.27.222 10003
Connected to 210.77.27.222 (210.77.27.222).
220 Welcome to virtual FTP service.
使用匿名用户登录,成功:
Name (210.77.27.222:root): anonymous
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (210,77,27,222,51,224)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jul 09 15:26 pub
226 Directory send OK.
ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (210,77,27,222,223,123)
150 Here comes the directory listing.
-rw-r--r--    1 0        0              10 Jul 09 15:26 test.c
226 Directory send OK.
ftp> bye
221 Goodbye.
连接虚拟FTP服务器,其IP地址为210.77.27.223,端口号为10004:
# ftp 210.77.27.223 10004
Connected to 210.77.27.223 (210.77.27.223).
220 Welcome to virtual FTP service.
使用匿名用户登录,成功:
Name (210.77.27.223:root): anonymous
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (210,77,27,223,102,119)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jul 10 13:23 pub
226 Directory send OK.
进入该登录文件夹:
ftp> cd pub
250 Directory successfully changed.
ftp> ls //由于该虚拟服务器没有加入任何文件,所以ls结果为空
227 Entering Passive Mode (210,77,27,223,170,40)
150 Here comes the directory listing.
226 Directory send OK.
ftp> bye
	
	

原文地址:https://www.cnblogs.com/g2thend/p/11515592.html