安装vsftpd
[root@localhost ~]# yum -y install vsftpd
查看安装路径
[root@localhost ~]# whereis vsftpd
vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz
查看目录
[root@localhost ~]# ll /etc/vsftpd/
-rw------- 1 root root 125 Mar 22 2017 ftpusers 黑名单文件,此文件里的用户不允许访问 FTP 服务器
-rw------- 1 root root 361 Mar 22 2017 user_list 白名单文件,是允许访问 FTP 服务器的用户列表
-rw------- 1 root root 4599 Mar 22 2017 vsftpd.conf 核心配置文件
-rwxr--r-- 1 root root 338 Mar 22 2017 vsftpd_conf_migrate.sh FTP服务
基于用户验证的ftp服务
第一步:编辑vsftpd.conf
[root@localhost ~]# cat /etc/vsftpd/vsftpd.conf | grep -v "#" > vsftpd.conf
配置文件注释
anonymous_enable=NO # 不允许匿名,默认是NO
local_enable=YES # YES时,/etc/passwd中的账号才能以实体用户的方式访问vsftpd主机
write_enable=YES # 具有写权限
local_umask=022 # 反掩码(755权限):777-755 = 022 (755权限)
anon_umask=022
anon_upload_enable=NO # 禁止匿名用户上传
anon_other_write_enable=NO
anon_mkdir_write_enable=NO # 禁止匿名用户建立目录
dirmessage_enable=YES # YES 开启目录标语功能
xferlog_enable=YES # YES 时,上传与下载的日志存放于xferlog_file
connect_from_port_20=NO # 不开启20端口
xferlog_std_format=YES # 设定日志使用标准的记录格式
chroot_local_user=YES # YES时,不禁锢系统用户
chroot_list_enable=YES # 禁止用户登出自己的FTP主目录
chroot_list_file=/etc/vsftpd/chroot_list # 该文件中用户不受限制,不限制在本目录
listen=YES
pam_service_name=vsftpd # pam模块名称,位于/etc/pam.d/vsftpd
userlist_enable=NO
tcp_wrappers=YES # 开启tcp_wrappers管理支持
allow_writeable_chroot=YES # 解决chroot权限问题
listen_port=38001 # ftp端口号
pasv_enable=YES #启动被动式联机(passivemode)
pasv_min_port=38003
pasv_max_port=38015
ftp_data_port=38002
local_root=/mnt/devops/njss_web_system_ftp # ftp访问目录(上传默认位置)
显示带行号
[root@localhost ~]# cat /etc/vsftpd/vsftpd.conf -n
配置文件内容
# 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
anon_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=NO
anon_other_write_enable=NO
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=NO
#
# 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=NO
#
# 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=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=NO
tcp_wrappers=YES
allow_writeable_chroot=YES
listen_port=38001
pasv_enable=YES
pasv_min_port=38003
pasv_max_port=38015
ftp_data_port=38002
local_root=/mnt/devops/njss_web_system_ftp
第二步:更新防火墙端口
添加主端口
[root@localhost ~]firewall-cmd --permanent --zone=public --add-port=38001/tcp
添加被动端口
[root@localhost ~]firewall-cmd --permanent --zone=public --add-port=38003-38015/tcp
重启防火墙
[root@localhost ~]firewall-cmd --reload
第三步:添加用户
创建用户
[root@localhost ~]useradd -d /mnt/devops/njss_web_system_ftp/ ftpuser
useradd: cannot set SELinux context for home directory /mnt/devops/njss_web_system_ftp/
[root@localhost ~]setenforce 0
[root@localhost ~]useradd -d /mnt/devops/njss_web_system_ftp/ ftpuser
设置密码
[root@localhost ~]passwd ftpuser
第四步:修改文件夹权限
赋予文件夹读写权限
[root@localhost ~]chmod 777 /mnt/devops/njss_web_system_ftp/
[root@localhost ~]ls -ld /mnt/devops/njss_web_system_ftp/
drwxrwxrwx. 4 ftpuser2 ftpuser2 84 Oct 14 12:40 /mnt/devops/njss_web_system_ftp/
第五步:vsftpd操作
查看vsftpd状态
[root@localhost ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2023-10-14 15:44:03 CST; 33min ago
Process: 8845 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 8846 (vsftpd)
CGroup: /system.slice/vsftpd.service
├─8846 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
├─9369 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
└─9375 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
Oct 14 15:44:03 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
Oct 14 15:44:03 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.
启动vsftpd
[root@localhost ~]systemctl start vsftpd
停止vsftpd
[root@localhost ~]systemctl stop vsftpd
重启vsftpd
[root@localhost ~]systemctl restart vsftpd
查看ftp端口
[root@localhost ~]# netstat -npal|grep vsftpd
tcp 0 0 0.0.0.0:38001 0.0.0.0:* LISTEN 8846/vsftpd
tcp 0 0 192.168.18.129:38001 192.168.18.129:40724 ESTABLISHED 9369/vsftpd
unix 3 [ ] STREAM CONNECTED 90261 9369/vsftpd
unix 2 [ ] DGRAM 86088 8846/vsftpd
unix 3 [ ] STREAM CONNECTED 90262 9375/vsftpd
第六步:ftp登录
[root@localhost ~]# ftp 192.168.18.129 38001
Connected to 192.168.18.129 (192.168.18.129).
220 (vsFTPd 3.0.2)
Name (192.168.18.129:root): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
卸载vsftpd
第一步:查看vsftpd
[root@localhost ~]# rpm -qa|grep vsftpd vsftpd-3.0.2-29.el7_9.x86_64
第二步:卸载vsftped
[root@localhost ~]# rpm -e vsftpd-3.0.2-29.el7_9.x86_64
返回:卸载时自己主动备份vsftp的用户列表文件 warning: /etc/vsftpd/vsftpd.conf saved as /etc/vsftpd/vsftpd.conf.rpmsave warning: /etc/vsftpd/user_list saved as /etc/vsftpd/user_list.rpmsave
第三步:删除上面的文件
[root@localhost ~]#rm -fr /etc/vsftpd
第四步:查看vsftpd是否在开机启动项
[root@localhost ~] chkconfig --list
第五步:查看vsftpd执行状态
[root@localhost ~] service vsftpd status
返回:vsftpd: unrecognized service(无法识别vsftpd。说明卸载了vsftpd了)
防火墙操作
查看防火墙状态
[root@localhost ~]# systemctl status firewalld
关闭防火墙
[root@localhost ~]#systemctl stop firewalld
启动防火墙
[root@localhost ~]#systemctl start firewalld
重启防火墙
[root@localhost ~]#firewall-cmd --reload
用户操作
查看用户
[root@localhost ~]# cat /etc/passwd
ftpuser:x:1008:1008::/mnt/devops/njss_web_system_ftp/:/bin/bash
删除用户
[root@localhost ~]#userdel -r 用户名
参考
https://www.toutiao.com/article/6724624529643012616/?channel=&source=search_tab
标签:ftp,enable,Centos7,vsftpd,卸载,YES,root,localhost From: https://blog.51cto.com/u_3172968/8005184