CentOS8.4 Vsftpd服务配置(FTP协议)

目录

Vsftpd服务简介

基本操作

Vsftpd服务主配置文件

配置参数

题一

匿名用户权限

配置过程

登录验证

题二

限制切换目录

配置过程

登录验证 

关闭限制

登录验证

题三

虚拟用户访问

配置过程

登录验证

题四

用户黑白名单

配置过程

登录验证

启用黑名单

登录验证

启用白名单

登录验证

注意事项

易错点


Vsftpd服务简介

vsftpd(Very Secure FTP Daemon 非常安全的FTP服务器)是一款运行在类UNIX操作系统上的FTP服务端程序

文件传输协议(File Transfer Protocol,FTP)是能够让用户在互联网中上传、下载文件的协议,可跨平台传输文件,如linux和windows主机间的文件传输。

数据传输类型,主动模式(PORT模式):服务端主动向客户端发起连接请求;被动模式(PASV模式):服务端等待客户端的连接请求

基本操作

[root@CentOS8 ~]# systemctl start vsftpd
启动
[root@CentOS8 ~]# systemctl status vsftpd
查询状态
[root@CentOS8 ~]# systemctl stop vsftpd
停止
[root@CentOS8 ~]# systemctl enabled vsftpd
设置开机自启动

[root@CentOS8 ~]# rpm -ql vsftpd    查询rpm格式的vsftpd安装包在安装后会释放什么文件
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/lib/.build-id
/usr/lib/.build-id/fa
/usr/lib/.build-id/fa/c1e87675fb05d9f43d7de573ad82098fa34931
/usr/lib/systemd/system-generators/vsftpd-generator
/usr/lib/systemd/system/vsftpd.service
/usr/lib/systemd/system/vsftpd.target
/usr/lib/systemd/system/vsftpd@.service
/usr/sbin/vsftpd
/usr/share/doc/vsftpd
/usr/share/doc/vsftpd/AUDIT
/usr/share/doc/vsftpd/BENCHMARKS
/usr/share/doc/vsftpd/BUGS
/usr/share/doc/vsftpd/COPYING
/usr/share/doc/vsftpd/Changelog
/usr/share/doc/vsftpd/EXAMPLE
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/README
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE/vsftpd.xinetd
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD/README
/usr/share/doc/vsftpd/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG/README
/usr/share/doc/vsftpd/EXAMPLE/PER_IP_CONFIG/hosts.allow
/usr/share/doc/vsftpd/EXAMPLE/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_HOSTS
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_HOSTS/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/README
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/logins.txt
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/vsftpd.conf
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS/vsftpd.pam
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS_2
/usr/share/doc/vsftpd/EXAMPLE/VIRTUAL_USERS_2/README
/usr/share/doc/vsftpd/FAQ
/usr/share/doc/vsftpd/INSTALL
/usr/share/doc/vsftpd/LICENSE
/usr/share/doc/vsftpd/README
/usr/share/doc/vsftpd/README.security
/usr/share/doc/vsftpd/REWARD
/usr/share/doc/vsftpd/SECURITY
/usr/share/doc/vsftpd/SECURITY/DESIGN
/usr/share/doc/vsftpd/SECURITY/IMPLEMENTATION
/usr/share/doc/vsftpd/SECURITY/OVERVIEW
/usr/share/doc/vsftpd/SECURITY/TRUST
/usr/share/doc/vsftpd/SIZE
/usr/share/doc/vsftpd/SPEED
/usr/share/doc/vsftpd/TODO
/usr/share/doc/vsftpd/TUNING
/usr/share/doc/vsftpd/vsftpd.xinetd
/usr/share/man/man5/vsftpd.conf.5.gz
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub

[root@CentOS8 ~]# netstat -tlnp | grep ftp    查询vsftpd服务启用了什么端口
tcp6       0      0 :::21                   :::*                    LISTEN      40535/vsftpd   

Vsftpd服务主配置文件

位于/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.
#
# 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           是否允许本地用户登录
#
# 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            本地用户权限的掩码,-rw-r--r--
#
# 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   ftp-data的端口
#
# 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            是否监听ipv6地址的主机服务请求

pam_service_name=vsftpd    ftp的可插拔认证模块配置文件名
userlist_enable=YES        是否启用用户名单

配置参数

匿名用户参数功能
anonymous_enable=YES/NO是否允许匿名用户登录,预设YES
anon_world_readable_only=YES/NO是否允许匿名用户具有下载可读文件的权限,预设YES
|anon_other_write_enable=YES/NO是否允许匿名用户具有写入权限,预设NO,若要设为YES需要把开放给匿名用户写入的目录也需要调整权限,是anon_mkdir_write_enable的关联项
|anon_mkdir_write_enable=YES/NO是否允许匿名用户具有创建目录权限,预设NO,如果要设定为YES,为anon_other_write_enable也要设定为YES
anon_upload_enable=YES/NO是否允许匿名用户具有上传数据功能,预设NO
chown_uploads=YES/NO是否启用将所有匿名上传文件的所属用户更改为chown_username的设置
chown_username=whoever匿名上传文件所属用户名
|deny_email_enable=YES/NO是否启用拒绝某些邮箱地址登录
|

banned_email_file=

/etc/vsftpd/vsftpd.banned_emails

若deny_email_enable启用,则可以使用该文件来规定特定邮箱地址不可登录
no_anon_password=YES/NO是否需要匿名用户登录时进行口令验证
anon_max_rate=0匿名用户最大传输速度,为0时表示不限制,数值单位为B/s
anon_umask=077设置匿名用户上传文件的掩码,077表示权限为-rw-------,若想让匿名用户上传的文件能直接让匿名用户下载,则设置为073,表示权限为-rw----r--
anon_root=/var/ftp设置匿名用户的FTP根目录
本地用户参数功能
write_enable==YES/NO是否允许写入,无论是匿名用户还是本地用户,需要上传权限时都需要开启此项
local_enable=YES/NO是否允许本地用户登录
local_max_rate=0本地用户的传输速度限制,为0时表示不限制,数值单位B/s
chroot_local_user=YES/NO是否限制本地用户在自己的家目录内
|chroot_list_enable=YES/NO是否限制特定用户在自己的家目录内
|chroot_list_file=/etc/vsftpd/user_listchroot_list_enable的关联项,前者启用后需要搭配本项使用
|userlist_enable=YES/NO是否启用用户名单
|userlist_deny=YES/NO为YES时将用户名单变为黑名单,为NO时将用户名单变为白名单
|userlist_file=/etc/vsftpd/user_list使userlist_enable和userlist_deny生效的文件
local_umask=022本地用户上传文件的掩码,原理与anon_umask一致
local_root=路径设置本地用户的FTP根目录
虚拟用户参数作用
check_shell=YES/NO是否检查用户使用一个有效的shell登录,仅在没有pam验证版本时有用
guest_enable=YES/NO是否启用虚拟用户模式,预设获得ftp用户的权限,可搭配pam模块来分配不同的虚拟用户间的权限
guest_username=ftp设置虚拟用户的宿主用户,预设ftp
virtual_use_local_privs=YES/NO是否使虚拟用户有与宿主用户相同的权限,预设NO
访问控制参数作用
tcp_wrappers=YES/NO是否启用tcpwrapper与vsftpd相结合进行主机访问控制,预设YES,启用后服务器会检查/etc/hosts.allow和/etc/hosts.deny中的设置
/etc/vsftpd/ftpusersFTP服务黑名单,直接经过PAM模块认证,优先级高过userlist
/etc/vsftpd/user_listFTP服务的用户名单,使用需要开启userlist_enable,同时需要依靠userlist_deny参数来决定是黑名单还是白名单
主机相关参数作用
用户连接
listen=YES/NO是否以独立运行的方式监听服务
listen_ipv6=YES/NO是否监听ipv6地址的主机服务请求
max_clients=0最大连接数,0表不限制
max_per_ip=0每个IP同一时间最大连接数
connect_from_port_20=YES/NO是否使用20端口作为ftp-data的端口
listen_port=21vsftpd命令通道端口号,仅适合standalone方式启动, 对super daemon(xinetd)无效
listen_address=192.168.0.2多网卡多IP时可以绑定单个IP为访问IP,其他IP无法访问
pasv_max_port=0使用端口范围上限,0表不限制,默认0
pasv_min_port=0使用端口范围下限,0表不限制,默认0
pasv_enable=YES/NO启用被动式联机模式(Passive Mode)预设YES
pasv_address=nonevsftpd在pasv命令回复时跳转到指定IP地址
port_enable=YES/NO是否使用port模式,预设为NO
超时设置
connect_timeout=60主动连接模式下,若超过等待时间则强制断线
accept_timeout=60被动连接模式下,若超过等待时间则强制断线
data_connection_timeout=300数据传送超过时间会被强制删除连接
idle_session_timeout=300等待时间内没有命令操作,强制脱机
信息设置
ftpd_banner=welcome to FTP登录时显示欢迎信息,若设置了banner_file则此项无效
banner_file=/etc/vsftpd/banner定义登录信息文件的位置
|dirmessage_enable=YES/NO是否显示当用户进入某个目录时该注意的内容
|message_file=.message与dirmessage_enable为关联项
use_localtime=YES/NO是否使用本地时间,预设使用GMT(格林尼治)时间
日志设置
xferlog_enable=YES/NO是否开启日志功能
xferlog_file=/var/log/vsftpd.log日志存放路径
xferlog_std_format=YES使用标准格式
其他设置
ascii_download_enable=YES/NO是否使用ASCII格式下载文件
ascii_upload_enable=YES/NO是否使用ASCII格式上传文件
one_process_model=YES/NO是否启用每个连接都由分配一个进程运行(不推荐),需要较高的系统性能和安全性,预设NO
nopriv_user=nobody以nobody作为服务默认权限,确保被入侵后入侵者只能获得较低的权限
pam_service_name=vsftpd设置PAM使用的名称,默认/etc/pam.d/vsftpd
download_enable=YES/NO是否允许下载文件
SSL相关参数作用
ssl_enable=YES/NO是否启用ssl,预设NO
allow_anon_ssl=YES/NO是否允许匿名用户使用ssl,预设NO
force_anon_logins_ssl=YES/NO是否强制匿名用户登录时采用加密数据,预设NO
force_anon_data_ssl=YES/NO是否强制匿名用户数据传输时加密,预设NO
force_local_logins_ssl=YES/NO是否强制非匿名用户登录时采用加密数据,预设YES
force_local_data_ssl=YES/NO是否强制非匿名用户数据传输时加密,预设YES
rsa_cert_file=/etc/vsftpd/rsa_certrsa证书的路径
dsa_cert_file=/etc/vsftpd/dsa_certdsa证书的路径
ssl_sslv2=YES/NO是否激活ssl v2加密,预设NO
ssl_sslv3=YES/NO是否激活ssl v3加密,预设NO
ssl_tlsv1=YES/NO是否激活tls v1加密,预设YES
ssl_cipher=DES-CBC3-SHAssl加密方法,默认是DES-CBC3-SHA,可以更换成HIGH,安全性会更好
implicit_ssl=YES/NO是否启用隐式ssl功能
listen_port=990隐式ftp端口设置,默认21端口,当用户采用隐式ssl连接时默认使用990端口,如果不启用该项,用户连接会失败
debug_ssl=YES输出ssl相关的日志信息

题一

匿名用户权限

权限允许匿名访问并允许匿名用户上传文件、创建目录、修改目录名或删除目录

配置过程

#修改主配置文件
[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

控制台输入:12,依次添加下列参数

anonymous_enable=YES            #允许匿名访问模式
anon_upload_enable=YES          #允许匿名用户上传文件
anon_mkdir_write_enable=YES     #允许匿名用户创建目录
anon_other_write_enable=YES     #允许匿名用户修改目录名或删除目录

查看目录属主
[root@CentOS8 ~]# ls -ld /var/ftp
drwxr-xr-x. 3 root root 17 3月   7 10:43 /var/ftp

创建下一级目录up
[root@CentOS8 ~]# mkdir /var/ftp/up

更换下一级目录的属主
[root@CentOS8 ~]# chown ftp:ftp /var/ftp/up -v
'/var/ftp/up' 的所有者已从 root:root 更改为 ftp:ftp

查看目录属主
[root@CentOS8 ~]# ls -ld /var/ftp
drwxr-xr-x. 4 root root 27 3月   7 10:50 /var/ftp
[root@CentOS8 ~]# ls -ld /var/ftp/up
drwxr-xr-x. 2 ftp ftp 6 3月   7 10:50 /var/ftp/up

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode.
用户(192.168.89.128:(none)): ftp        使用匿名用户ftp登录
331 Please specify the password.
密码:
230 Login successful.                   登录成功
ftp> dir                                查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Apr 24  2020 pub
drwxr-xr-x    2 14       50              6 Mar 07 02:50 up
226 Directory send OK.
ftp: 收到 124 字节,用时 0.00秒 124.00千字节/秒。
ftp> mkdir my                           创建目录
550 Create directory operation failed.  创建失败
ftp> cd up                              切换到下一级目录up
250 Directory successfully changed.
ftp> mkdir share                        创建目录
257 "/up/share" created                 创建成功

题二

限制切换目录

权限允许本地用户登录并允许本地用户拥有写入权限,启用限制切换目录用户名单并指定名单文件位置
chroot_list=YES用户dandan无法切换目录
chroot_list=NO用户dandan可以切换目录

配置过程

#修改主配置文件
[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

在这两项的基础下
local_enable=YES                            #允许本地用户登录
write_enable=YES                            #允许本地用户拥有写入权限

控制台输入:20,增加以下参数
chroot_list_enable=YES                      #启用限制切换目录用户名单
chroot_list_file=/etc/vsftpd/chroot_list    #指定用户名单位置
allow_writeable_chroot=YES                  #当用户被锁定目录时且目录拥有写入权限时,必须开启此项才可以拥有写入权限

#创建限制切换目录用户名单
[root@CentOS8 ~]# vim /etc/vsftpd/chroot_list

dandan
写入要限制切换目录的用户

登录验证 

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode.
用户(192.168.89.128:(none)): dandan        使用蛋蛋用户登录
331 Please specify the password.
密码:
230 Login successful.                      登录成功
ftp> dir                                   查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 1001     1001            6 Mar 07 03:18 myegg
226 Directory send OK.
ftp: 收到 66 字节,用时 0.00秒 66.00千字节/秒。
ftp> pwd                                   查看当前路径
257 "/home/dandan" is the current directory
ftp> cd /var/ftp                           切换到指定目录
550 Failed to change directory.            切换失败
ftp> pwd                                   查看当前路径
257 "/var/ftp" is the current directory

关闭限制

[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

chroot_list_enable=NO
修改为NO

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode.
用户(192.168.89.128:(none)): dandan        使用蛋蛋用户登录
331 Please specify the password.
密码:
230 Login successful.                      登录成功
ftp> dir                                   查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 1001     1001            6 Mar 07 03:18 myegg
226 Directory send OK.
ftp: 收到 66 字节,用时 0.00秒 66.00千字节/秒。
ftp> pwd                                   查看当前路径
257 "/home/dandan" is the current directory
ftp> cd /var/ftp                           切换到指定目录
250 Directory successfully changed.        切换成功
ftp> pwd                                   查看当前路径
257 "/var/ftp" is the current directory

题三

虚拟用户访问

用户权限
ysxb默认权限(匿名用户权限)
yyxb写入、上传和创建目录权限

配置过程

[root@CentOS8 ~]# vim /etc/vsftpd/vuser.list    创建虚拟用户名单
格式:
用户名
密码

ysxb        #用户名
114514      #密码
yyxb        #用户名
1919810     #密码
#沼---气---池

[root@CentOS8 ~]# db_load -T -t hash -f /etc/vsftpd/vuser.list /etc/vsftpd/vuser.db
#使用db_load命令生成hash算法加密的FTP用户数据库文件vuser.db

[root@CentOS8 ~]# chmod 600 /etc/vsftpd/vuser.db    分配文件权限为拥有者(出于安全性考虑)
[root@CentOS8 ~]# rm -f /etc/vsftpd/vuser.list      删除未加密的用户名单

[root@CentOS8 ~]# useradd -d /var/ftproot -s /sbin/nologin virtual    创建FTP根目录及虚拟用户的宿主用户
[root@CentOS8 ~]# chmod -Rf 755 /var/ftproot        分配rwxr-xr-x权限,让匿名用户可以访问
[root@CentOS8 ~]# ls -ld /var/ftproot/              查看FTP根目录的拥有者及权限
drwxr-xr-x. 3 virtual virtual 92 3月   7 12:55 /var/ftproot/

创建pam认证文件
[root@CentOS8 ~]# vim /etc/pam.d/vsftpd.vu

auth    required    pam_userdb.so    db=/etc/vsftpd/vuser    #前面删除未加密的用户名单
account required    pam_userdb.so    db=/etc/vsftpd/vuser    #是为了这里配置路径用,会自动读取名为vuser且后缀为db的文件

修改主配置文件
[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

在这两行的基础下
anonymous_enable=NO            #禁止匿名用户访问
local_enable=YES               #允许本地用户访问

增加以下四行
guest_enable=YES               #启用虚拟用户模式
guest_username=virtual         #虚拟用户名称

末尾
pam_service_name=vsftpd.vu     #更改可插拔认证模块配置文件名
allow_writeable_chroot=YES     #允许锁定的FTP根目录在用户没有权限的情况下登录

[root@CentOS8 ~]# mkdir /etc/vsftpd/vusers_dir
[root@CentOS8 ~]# touch /etc/vsftpd/vusers_dir/ysxb
[root@CentOS8 ~]# vim /etc/vsftpd/vusers_dir/yyxb

anon_upload_enable=YES            #允许匿名用户拥有上传权限
anon_mkdir_write_enable=YES       #允许匿名用户拥有创建目录权限
anon_other_write_enable=YES       #允许匿名用户拥有写入权限

[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf 

末尾添加这段参数
user_config_dir=/etc/vsftpd/vusers_dir    #指定用户的配置文件目录

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): ysxb    使用野兽先辈用户登录
331 Please specify the password.
密码:
230 Login successful.                登录成功
ftp> pwd                             查看当前路径
257 "/" is the current directory
ftp> dir                             查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir ysxb                      创建目录
550 Permission denied.               创建失败
ftp> quit                            离开
221 Goodbye.

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): yyxb    使用袁野先辈用户登录
331 Please specify the password.
密码:
230 Login successful.
ftp> pwd                             查看当前路径
257 "/" is the current directory
ftp> dir                             查看当前列表里的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir yyxb                      创建目录
257 "/yyxb" created                  创建成功
ftp> dir                             查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwx------    2 1001     1001            6 Mar 07 05:21 yyxb
226 Directory send OK.
ftp: 收到 62 字节,用时 0.00秒 20.67千字节/秒。
ftp> rename yyxb cyka                重命名目录
350 Ready for RNTO.
250 Rename successful.               重命名成功
ftp> dir                             查看当前目录的文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwx------    2 1001     1001            6 Mar 07 05:21 cyka
226 Directory send OK.
ftp: 收到 62 字节,用时 0.00秒 62.00千字节/秒。

题四

用户黑白名单

pam模块ftpusers最高优先级的黑名单默认用户名单
userlist_deny=NO白名单(优先级低于ftpusers)

cyka用户可登录

dandan用户不可登录

userlist_deny=YES黑名单

cyka用户不可登录

dandan用户可登录

配置过程

#编辑pam模块的黑名单,此处使用默认配置
[root@CentOS8 ~]# vim /etc/vsftpd/ftpusers

# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): root
530 Permission denied.
登录失败。
ftp> quit
221 Goodbye.

启用黑名单

[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

userlist_deny=NO

编辑用户名单,可以发现此处的用户和ftpusers里面的名单重合,却无法登录,
原因是ftpusers黑名单的优先级比user_list白名单更高
[root@CentOS8 ~]# vim /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
cyka        #底部添加cyka用户

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): dandan
530 Permission denied.
登录失败。
ftp> quit
221 Goodbye.

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): cyka
331 Please specify the password.
密码:
230 Login successful.

启用白名单

[root@CentOS8 ~]# vim /etc/vsftpd/vsftpd.conf

userlist_deny=YES

登录验证

Windows客户端连接验证

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): dandan
331 Please specify the password.
密码:
230 Login successful.
ftp> quit
221 Goodbye.

D:\>ftp 192.168.89.128
连接到 192.168.89.128。
220 (vsFTPd 3.0.3)
用户(192.168.89.128:(none)): cyka
530 Permission denied.
登录失败。

注意事项

  • 本文颜色为紫色的字体为博主也不懂的知识,待日后知识储备足够后再补齐
  • ftp访问失败可能是因为SElinux导致,本文采取简单方法将其设为Permissive模式,不推荐在日常配置中也这样操作
  • 本文为实现简单思路直接将防火墙关闭,不推荐在日常配置中也这样操作

易错点

  • pam模块的文件路径参数db=/etc/vsftpd/vuser不需要加后缀
  • ftpusers的用户黑名单是最高优先级,如果想要使白名单的用户能够访问请记得它不在ftpusers里
  • 文件目录的权限和属主对ftp用户能否访问有直接影响,请确保分配了正确的权限
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值