================================
©Copyright Sweet Potato Yao2022-04-19
Sweet Potato Yao's Blog - CSDN Blog
1. Install the FTP server
yum install -y vsftpd
Install ftp client (can be omitted)
yum install -y ftp
2. FTP service configuration
1. Enter the FTP configuration file directory
cd /etc/vsftpd
2. Backup the configuration file vsftpd.conf and remove all comments
mv vsftpd.conf vsftpd.conf.bak
grep -v "#" vsftpd.conf.bak > vsftpd.conf
3. Edit the configuration file
vi vsftpd.conf
Modified content
#修改
#是否支持匿名用户,默认YES,改成NO表示需要用户名密码登录不允许匿名登录
anonymous_enable=NO
#匿名上传。首先,文件系统上用户的家目录,要具备写权限。其次,ftp服务器要开启允许匿名上传的配置
anon_upload_enable=YES
#以下取消注释
#允许匿名用户上传,建立目录
anon_mkdir_write_enable=YES
#默认只能下载全部读的文件。这句话的意思是说,如果启动了这句话,则匿名用户只能下载所有用户都具备读权限的文件。如果有一个文件,有一个用户不剧本读权限,匿名用户就不能够下载。
anon_world_readable_only=YES
#匿名用户能否删除和修改上传的文件
anon_other_write_enable=YES
#指定匿名上传文件的umask值。umask的值可以直接影响到上传文件的权限。
anon_umask=077
#指定上传文件的默认的所有者和权限。 完成了这些指定之后,匿名用户上传的元数据就是我们指定的那些内容。
chown_uploads=YES
#chown_username=wang
#chown_upload_mode=0644
#所有系统用户都映射成guest用户,但是映射的guest账户,需要人为地去指定下。
#guest_enable=YES
#guest_username=vsftpd
#是否允许Linux用户登陆,默认是允许的,当然也可以禁止。
local_enable=YES
#是否允许Linux用户上传文件,如果用户默认允许登陆的话,linux用户登陆成功之后,默认位于自己的家目录,这时是允许上传文件的。 如果将下面的这句话,改成no,则服务拒绝linux用户上传文件,即便位于自己的家目录也不可以。
#write_enable=YES
#指定系统用户上传文件的默认权限
#local_umask=022
#非匿名用户登录所在目录,当使用Linux用户登陆成功之后,就不会默认在自己的家目录了。相反,会位于下面指定的目录里。
#local_root=/ftproot
#禁锢所有的用户在家目录中的意思是说,用户登陆成功之后,不能够随意切换目录,只能够在自己的家目录中进行操作。
chroot_local_user=YES
#ASCII码支持
async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
#登录提示信息
ftpd_banner=Welcome to FTP server.
# 这一句话优先生效
#banner_file=/etc/vsftpd/ftpbanner.txt
#设置是否使用当地时间。默认就是YES
use_localtime=YES
#虚拟用户建立独立的配置文件
user_config_dir=/etc/vsftpd/conf
listen_port=21
virtual_use_local_privs=YES
##被动模式端口
pasv_min_port=40000
pasv_max_port=40010
# 被动模式数据连接超时时长,时间单位是秒
accept_timeout=10
#主动模式数据连接超时时长,时间单位是秒
connect_timeout=10
#数据连接无数据输超时时长,时间单位是秒
data_connection_timeout=300
# 无命令操作超时时长,时间单位是秒
idle_session_timeout=300
allow_writeable_chroot=YES
3. Create a virtual user
Virtual users are created to prevent FTP users from directly logging in to the server
1. Create a virtual user profile
vi ftp_user.conf
Added content: the odd-numbered line is the account number, the even-numbered line is the password, the first line below is the account number, and the second line is the password
ftpuser
ftpuser123
2. Encrypt virtual user profiles
db_load -T -t hash -f ftp_user.conf ftp_user.db
If there is no db_load command, it needs to be installed: yum install db4 db4-utils
Change permissions and delete unencrypted configuration
chmod 600 ftp_user.db
rm -f ftp_user.conf
3. Modify FTP access rights
backup first
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
Modify permissions file
vi /etc/pam.d/vsftpd
First comment out all the configuration lines of the original auth and account in the configuration file (the virtual user will not be able to log in without commenting out), and add two lines of information
auth required pam_userdb.so db=/etc/vsftpd/ftp_user
account required pam_userdb.so db=/etc/vsftpd/ftp_user
4. Add virtual users, you can only log in to FTP, but not in the background
useradd -d /home/ftpuser -s /sbin/nologin ftpuser
Change the owner of a folder
chown -R ftpuser:ftpuser /home/ftpuser
5. Virtual User Profile
Create a virtual user profile directory
mkdir -p /etc/vsftpd/conf
Create a configuration file for a virtual user (the username of the ftpuser file and the database file just created must be the same)
vi /etc/vsftpd/conf/ftpuser
Added content:
#用户的默认登陆目录。也就是FTP用户登陆成功之后的默认路径。
local_root=/home/ftpuser/ftpuser
write_enable=YES
anon_world_readable_only=NO
#虚拟用户上传权限
anon_upload_enable=YES
#虚拟用户创建文件夹
anon_mkdir_write_enable=YES
## 虚拟的其他用户对指定用户目录的写权限
anon_other_write_enable=YES
Create an FTP transfer directory, corresponding to the local_root configuration item above
mkdir -p /home/ftpuser/ftpuser
chown ftpuser:ftpuser /home/ftpuser/ftpuser
chmod 775 /home/ftpuser/ftpuser
4. Open FTP port and FTP service
firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --permanent --zone=public --add-port=21/tcp
#被动模式的端口
firewall-cmd --permanent --zone=public --add-port=40000-40010/tcp
#重新加载生效
firewall-cmd --reload
firewall-cmd --list-all
firewall-cmd --zone=public --list-ports
5. FTP startup and setting automatic startup
#启动
systemctl start vsftpd
#设置自动启动
systemctl enable vsftpd
#查看状态
systemctl status vsftpd.service
#重启
systemctl restart vsftpd
6. FTP access address
ftp://192.168.10.100/
7. Error resolution
1、500 OOPS: vsftpd: cannot locate user specified in 'guest_username':vsftpd
注释下面的配置
#guest_enable=YES
#guest_username=vsftpd
8. Other commands
#安装filezilla
yum install -y filezilla
运行filezilla
filezilla &
#Selinux方式:查看防火墙状态
getenforce
#permissive表示:放任的;纵容的;姑息的;
#临时关闭:setenforce 0
setenforce 0 ->permissive
#永久关闭:vim /etc/sysconfig/selinux
将selinux=cnforcing改为selinux=disable
Firewall
1.关闭防火墙:service firewalld stop
2.关闭防火墙:systemctl stop firewalld.service
3.禁止防火墙开机启动:systemctl disable firewalld.service
4,查看防火墙状态:firewall-cmd --state
(Time is precious, sharing is not easy, donate and give back, ^_^)
================================
©Copyright Sweet Potato Yao2022-04-19