一、安装vsftpd
1.1 检查系统是否已经安装过vsftpd了
[root@localhost /]# rpm -aq vsftpd
如果返回结果显示:
vsftpd-3.0.-.el7.x86_64
#此处是查找vsftpd的返回结果
如果提示已安装,但是你之前配置错了,不知道怎么搞,那么进行1.2步骤
1.2 卸载系统目前的vsftpd
停止vsftpd运行:
[root@localhost /]# /sbin/service vsftpd stop
卸载vsftpd
[root@localhost /]# rpm -e vsftpd-3.0.-.el7.x86_64
此时系统会返回以下信息
warning: /etc/vsftpd/vsftpd.conf saved as /etc/vsftpd/vsftpd.conf.rpmsave
接下来直接把上步(系统返回的提示信息)没卸载干净的东西删除
rm -rf /etc/vsftpd/vsftpd.conf.rpmsave
1.3 验证vsftpd是否卸载干净
[root@localhost /]# /sbin/service vsftpd stop
Redirecting to /bin/systemctl stop vsftpd.service
Failed to stop vsftpd.service: Unit vsftpd.service not loaded. #找不到vsftpd
[root@localhost /]# /sbin/service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service
Failed to start vsftpd.service: Unit not found. #找不到vsftpd
1.4 安装vsftpd
[root@localhost /]# yum -y install vsftpd
1.5 启动vsftpd
[root@localhost home]# systemctl start vsftpd.service
或者
[root@localhost home]# service vsftpd restart
1.6 开放端口
[root@localhost /]# firewall-cmd --zone=public --add-port=/tcp --permanent
[root@localhost /]# firewall-cmd --reload
注意ftp是21端口,sftp是22端口,也可以自己配置,但是到这一步,我们只需要了解就行,我们接着配置吧
二、分配用户
2.1 在你的linux上新建一个用户,只用来ftp不用来登录服务器
useradd Marry -s /sbin/nologin -d /var/ftp
上面的意思是,新建一个不用来登录服务器的用户,Marry,并设置他的ftp空间为/var/ftp 目录下。
接下来配置用户Marry的密码:
passwd Marry #给Marry用户设置密码
接下来按照提示输入你的密码就好
回过头来,说明下上面两个命令的意思
/* useradd 使用到3个参数:用户名,-s,-d,三个参数位置可以变动 Marry是用户名 -d 后面跟的是我们要给予Marry的家目录 */
2.2 设置上面新建用户对文件夹的操作权限
修改/var/ftp的权限为不可写
[root@localhost vsftpd]# chmod a-w /var/ftp/
这是因为我们在上面将/home/ftpuser/taotao文件的权限改为不可写了,那么我们在这个目录下创建一个images文件夹,用来上传文件。并将权限赋值给 ftpuser 用户
三、vsftpd配置
3.1 限制系统用户锁定在/home/ftpuser目录
如果设置为
chroot_local_user=YES
chroot_list_enable=YES(这行可以没有, 也可以有)
chroot_list_file=/etc/vsftpd.chroot_list
那么, 凡是加在文件vsftpd.chroot_list中的用户都是不受限止的用户
即, 可以浏览其主目录的上级目录. 所以, 如果不希望某用户能够浏览其主目录上级目录中的内容,可以如上设置, 然后在
文件vsftpd.chroot_list中不添加该用户即可(此时, 在该文件中的用户都是可以浏览其主目录之外的目录的).
或者, 设置如下
chroot_local_user=NO
chroot_list_enable=YES(这行必须要有, 否则文件vsftpd.chroot_list不会起作用)
chroot_list_file=/etc/vsftpd.chroot_list
然后把所有不希望有这种浏览其主目录之上的各目录权限的用户添加到文件vsftpd.chroot_list(此时, 在该文件中的用户都是不可以浏览其主目录之外的目录的)
中即可(一行一个用户名).
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
这里有两种方案,我采用第二种,配置如下:
chroot_local_user=NO
chroot_list_enable=YES #(这行必须要有, 否则文件vsftpd.chroot_list不会起作用)
chroot_list_file=/etc/vsftpd/chroot_list
默认chroot_list是不存在的
[root@localhost vsftpd]# vim /etc/vsftpd/chroot_list
然后加入 ftpuser ,表示只有ftpuser不能访问上级目录,重启vsftpd。
3.2 开启PASV(被动模式)
在 /etc/vsftpd/vsftpd.conf 的最下面加入
pasv_enable=YES
pasv_min_port=
pasv_max_port=
(提示:如果你处于被动模式,发现登陆上了但是,无法上下载数据,并且提示,无法显示,可能是你防火墙的端口没开,还有你的端口
pasv_min_port是最小的端口,
pasv_max_port是最大的端口,不要写错了,还有,端口开了,要重启防火墙才能生效
)
并且在userlist_enable=YES文件后面添加
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list
开启防火墙:
[root@localhost taotao]# firewall-cmd --zone=public --add-port=-/tcp --permanent
[root@localhost taotao]# firewall-cmd --reload
3.3 添加用户到
添加用户到chroot_list,等几个文件中
四、最终的vsftpd.conf 文件的配置内容如下:
sz /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. for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf. 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=YES
#
# 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 . You may wish to change this to ,
# if your users expect that ( is used by most other ftpd's)
local_umask=
#
# 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 (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=
#
# You may change the default value for timing out a data connection.
data_connection_timeout=
#
# 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() 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=YES
#
# 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
local_root=/var/public_home
tcp_wrappers=YES
use_localtime=YES
allow_writeable_chroot=YES
pasv_enable=YES
pasv_min_port=
pasv_max_port=
sz /etc/vsftpd/chroot_list
Bob
porter
sz /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.
Bob
porter
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
sz /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
之一FTP上传,第一次可以用“”“FlashFXP 5”,这个挺好用的
参考链接: