Install and start the FTP service
Install VSFTPD
yum install -y vsftpd
Start the VSFTPD service
systemctl start vsftpd.service
Check if the system is already listening on port 21:
netstat -nltp | grep 21
Configure FTP permissions
Understanding VSFTP Configuration
The configuration directory is /etc/vsftpd, which contains the following configuration files:
- vsftpd.conf is the main configuration file
- ftpuusers Configure the list of users who are forbidden to access the FTP server
- user_list configure user access control
Block anonymous access and switch root
vim /etc/vsftpd/vsftpd.conf
, find the following two configurations and modify them:
Disable anonymous users, change YES to NO
anonymous_enable=NO
Prohibit switching root directory, delete
#
chroot_local_user=YES
After saving, restart the FTP service
systemctl restart vsftpd.service
Create FTP user
Create a user for using the ftp service
useradd username
Set password for user ftpuser
echo "password" | passwd username --stdin
Restrict this user to FTP access only
Restrict the user ftpuser to only access the server through FTP, but not directly log in to the server:
usermod -s /sbin/nologin ftpuser
Assign home directories to users
Create a home directory for user ftpuser and agree:
- /data/ftp is the main directory, this directory cannot upload files
- /data/ftp/pub files can only be uploaded to this directory
Create relevant directories in /data
mkdir -p /data/ftp/pub
Set access rights
chmod a-w /data/ftp && chmod 777 -R /data/ftp/pub
Set to the user's home directory:
usermod -d /data/ftp username
turn off firewall
systemctl stop firewalld.service