vsftpd服务安装
1、安装vsftpd
yum -y install vsftpd
2、修改配置
配置文件保存在/etc/vsftpd/vsftpd.conf,具体配置说明如下,大家按照自己的需求进行设置,不可以将下面的全部拷贝,会报错
#About host settings
connect_from_port_20=YES
#主动式连线使用的FTP伺服器的埠号吗?这就是ftp-data的埠号;
listen_port=21
#vsftpd使用的命令通道之埠号,如果您想要使用非正规的埠号,在这个设定项目修改吧!不过你必须要知道,这个设定值仅适合以stand alone的方式来启动喔! (对于super daemon无效)
dirmessage_enable=YES
#当使用者进入某个目录时,会显示该目录需要注意的内容,显示的档案预设是.message ,你可以使用底下的设定项目来修订!
message_file=.message
#当dirmessage_enable=YES时,可以设定这个项目来让vsftpd寻找该档案来显示讯息!
listen=NO
#若设定为YES表示vsftpd是以standalone的方式来启动的!
pasv_enable=YES
#启动被动式连线模式(passive mode),一定要设定为YES的啦!
use_localtime=YES
#是否使用本地时间? vsftpd预设使用GMT时间(格林威治),所以会比台湾晚8小时,建议设定为YES吧!
write_enable=YES
#如果你允许使用者上传资料时,就要启动这个设定值;
connect_timeout=60
#单位是秒,在资料连接的主动式连线模式下,我们发出的连接讯号在60秒内得不到用户端的回应,则不等待并强制断线咯。
accept_timeout=60
#当使用者以被动式PASV来进行资料传输时,如果主机启用passive port并等待client超过60秒而无回应,那么就给他强制断线!这个设定值与connect_timeout类似,不过一个是管理主动连线,一个管理被动连线。
data_connection_timeout=300
#如果伺服器与用户端的资料连线已经成功建立(不论主动还是被动连线),但是可能由于线路问题导致300秒内还是无法顺利的完成资料的传送,那用户端的连线就会被我们的vsftpd强制剔除!
idle_session_timeout=300
#如果使用者在300秒内都没有命令动作,强制离线!
max_clients=50
#如果vsftpd是以stand alone方式启动的,那么这个设定项目可以设定同一时间,最多有多少client可以同时连上vsftpd哩! ?
max_per_ip=5
#与上面max_clients类似,这里是同一个IP同一时间可允许多少连线?
pasv_min_port=0, pasv_max_port=0
#上面两个是与passive mode使用的port number有关,如果您想要使用65400到65410这11个port来进行被动式连线模式的连接,可以这样设定pasv_max_port=65410以及pasv_min_port=65400。如果是0的话,表示随机取用而不限制。
#ftpd_banner=一些文字說明
#当使用者连线进入到vsftpd时,在FTP用户端软体上头会显示的说明文字。不过,这个设定值资料比较少啦!建议你可以使用底下的设定值来取代这个项目;
banner_file=/etc/vsftpd/welcome.txt
#这个项目可以指定某个纯文字档作为使用者登入vsftpd伺服器时所显示的欢迎字眼。
#
#
#
#Entity user settings
#
guest_enable=NO
#若这个值设定为YES时,那么任何非anonymous登入的帐号,均会被假设成为guest (访客)喔!至于访客在vsftpd当中,预设会取得ftp这个使用者的相关权限。但可以透过guest_username来修改。
guest_username=ftp
#在guest_enable=YES时才会生效,指定访客的身份而已。
local_enable=YES
#这个设定值必须要为YES时,在/etc/passwd内的帐号才能以实体用户的方式登入我们的vsftpd主机喔!
write_enable=YES
#是否允许实体用户写入
local_max_rate=60000
#实体用户的传输速度限制,单位为bytes/second, 0为不限制。
chroot_local_user=YES
#将使用者限制在自己的家目录之内(chroot)!这个设定在vsftpd当中预设是NO,因为有底下两个设定项目的辅助喔!所以不需要启动他
#但如果启动了他,则表示实体用户默认就已经被chroot,写在/etc/vsftpd/chroot_list里的用户反而是没有被chroot的.
chroot_list_enable=YES
#是否启用将某些实体用户限制在他们的家目录内?预设是NO ,不过,如果您想要让某些使用者无法离开他们的家目录时,可以考虑将这个设定为YES ,并且规划下个设定值
chroot_list_file=/etc/vsftpd/chroot_list
#如果chroot_list_enable=YES那么就可以设定这个项目了!他里面可以规定那一个实体用户会被限制在自己的家目录内而无法离开! (chroot)一行一个帐号即可!
userlist_enable=YES
#是否借助vsftpd的抵挡机制来处理某些不受欢迎的帐号,与底下的设定有关;
userlist_deny=YES
#当userlist_enable=YES时才会生效的设定,若此设定值为YES时,则当使用者帐号被列入到某个档案时,在该档案内的使用者将无法登入vsftpd伺服器!该档案档名与下列设定项目有关。
userlist_file=/etc/vsftpd/user_list
#若上面userlist_deny=YES时,则这个档案就有用处了!在这个档案内的帐号都无法使用vsftpd喔!
#
#
#
#Anonymous settings
#
anonymous_enable=YES
#设定为允许anonymous登入我们的vsftpd主机!预设是YES ,底下的所有相关设定都需要将这个设定为anonymous_enable=YES之后才会生效!
anon_root=/var/ftp
anon_world_readable_only=YES
#仅允许anonymous具有下载可读档案的权限,预设是YES。
anon_other_write_enable=YES
#是否允许anonymous具有写入的权限?预设是NO!如果要设定为YES,那么开放给anonymous写入的目录亦需要调整权限,让vsftpd的PID拥有者可以写入才行!
anon_mkdir_write_enable=YES
#是否让anonymous具有建立目录的权限?预设值是NO!如果要设定为YES,那么anony_other_write_enable必须设定为YES !
#是否让anonymous具有上传资料的功能,预设是NO,如果要设定为YES ,则anon_other_write_enable=YES必须设定。
deny_email_enable=YES
#将某些特殊的email address抵挡住,不让那些anonymous登入!如果以anonymous登入主机时,不是会要求输入密码吗?密码不是要您输入您的email address吗?如果你很讨厌某些email address ,就可以使用这个设定来将他取消登入的权限!需与下个设定项目配合:
#banned_email_file=/etc/vsftpd/banned_emails
#如果deny_email_enable=YES时,可以利用这个设定项目来规定哪个email address不可登入我们的vsftpd喔!在上面设定的档案内,一行输入一个email address即可!
no_anon_password=YES
#当设定为YES时,表示anonymous将会略过密码检验步骤,而直接进入vsftpd伺服器内喔!所以一般预设都是NO的!
anon_max_rate=40000
#这个设定值后面接的数值单位为bytes/秒,限制anonymous的传输速度,如果是0则不限制(由最大频宽所限制),如果您想让anonymous仅有30 KB/s的速度,可以设定『anon_max_rate=30000』
anon_umask=077
#限制anonymous的权限!如果是077则anonymous传送过来的档案权限会是-rw-------喔!
#
#
#
# About system settings
ascii_download_enable=YES
#如果设定为YES ,那么client就可以使用ASCII格式下载档案。
ascii_upload_enable=YES
#与上一个设定类似的,只是这个设定针对上传而言!预设是NO
one_process_model=NO
#这个设定项目比较危险一点~当设定为YES时,表示每个建立的连线都会拥有一支process在负责,可以增加vsftpd的效能。不过,除非您的系统比较安全,而且硬体配备比较高,否则容易耗尽系统资源喔!一般建议设定为NO的啦!
tcp_wrappers=YES
#当然我们都习惯支援TCP Wrappers的啦!所以设定为YES吧!
xferlog_enable=YES
#当设定为YES时,使用者上传与下载档案都会被纪录起来。记录的档案与下一个设定项目有关:
xferlog_file=/var/log/vsftpd.log
#如果上一个xferlog_enable=YES的话,这里就可以设定了!这个是登录档的档名啦!
xferlog_std_format=NO
#是否设定为wu ftp相同的登录档格式? !预设为NO ,因为登录档会比较容易读!不过,如果您有使用wu ftp登录档的分析软体,这里才需要设定为YES
nopriv_user=nobody
#我们的vsftpd预设以nobody作为此一服务执行者的权限。因为nobody的权限相当的低,因此即使被入侵,入侵者仅能取得nobody的权限喔!
pam_service_name=vsftpd
#这个是pam模组的名称,我们放置在/etc/pam.d/vsftpd即是这个咚咚!
下面提供一个可用的配置文件
# 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
#
# 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=Y=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
allow_writeable_chroot=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=NO
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
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list
创建用户和权限
1、新建用户
userad -d /ftp/test -M -s /sbin/nologin test
-d 指定用户目录
-M 不在home下建立用户的宿主目录
-s 不允许登录shell
2、修改权限
修改密码并修改文件夹权限
echo "123456" | passwd --stdin test
chown -R test.test /ftp/test
3、vsftp权限设置
在/etc/shells中添加/sbin/nologin 当userlist_enable=YES、userlist_deny=NO、userlist_file=/etc/vsftpd/user_list的时候,user_list扮演白名单的角色。当userlist_enable=YES、userlist_deny=YES的时候,user_list扮演黑名单的角色。 我们这里当做白名单来使用,所以在/etc/vsftpd/user_list中添加新创建的用户test
其他环境配置
防火墙开放端口,主要开放20、21端口
firewall-cmd --add-service=ftp --permanent
firewall-cmd --reload
selinux 关闭
查看selinux状态
getenforce
关闭selinux方法:
(1)不重启的头闭 [root@localhost ~]# setenforce 0 #重启Linux电脑后失效
(2)重启电脑的关闭 [root@localhost ~]# vi /etc/selinux/config
把SELINUX=enforce 改成disabled就可以了,重启电脑,永久生效
启动vsftpd服务
启动
systemctl start vsftpd
查看状态
systemctl status vsftpd
重启
systemctl restart vsftpd
停止
systemctl stop vsftpd
使用客户端连接ftp
打开相关ftp工具
输入host:服务器ip
用户名:test
密码:123456
端口:21
点击连接即可