SoFunction
Updated on 2025-04-25

The complete process of quickly building FTP services on CentOS server

1. Install vsftpd

1. Installation command

sudo yum install vsftpd -y

2. Start the service and set up the boot boot

sudo systemctl start vsftpd
sudo systemctl enable vsftpd

2. Configure vsftpd

Configuration file path:/etc/vsftpd/

Modify the following core parameters:

anonymous_enable=NO          # Disable anonymous loginlocal_enable=YES             # Allow local users to log inwrite_enable=YES             # Allow file uploadchroot_local_user=YES        # Restrict users to access only home directoriesallow_writeable_chroot=YES   # Allow writing to restricted directorieslocal_umask=022              # File default permissions 644
# Passive mode configuration (solve NAT/firewall issues)pasv_enable=YES
pasv_min_port=50000
pasv_max_port=50010
pasv_address=Public networkIP          # If the server needs to be filled in after NAT

After saving, restarting the service takes effect:

sudo systemctl restart vsftpd

3. Firewall and SELinux configuration

1. Firewall release port (if enabled)

sudo firewall-cmd --permanent --add-port=21/tcp
sudo firewall-cmd --permanent --add-port=50000-50010/tcp
sudo firewall-cmd --reload

2. SELinux policy (if not disabled)

sudo setsebool -P ftp_home_dir 1
sudo semanage port -a -t ftp_port_t -p tcp 50000-50010

4. Create an FTP user and test it

1. Create a user

sudo useradd -m ftpuser
sudo passwd ftpuser
sudo chmod 750 /home/ftpuser

2. Local login test

ftp localhost
# Enter the username and password and execute:ftp> put   # Upload test filesftp> ls            # Check whether the file is uploaded successfully

5. Modify the user's default directory path (optional)

sudo mkdir -p /data/ftp
sudo chown ftpuser:ftpuser /data/ftp
sudo usermod -d /data/ftp ftpuser
sudo restorecon -Rv /data/ftp  # SELinux environment needs to be executed

6. Windows remote access to FTP service

1. Access through Windows Explorer

  • Open this computer → Enter in the address bar:

ftp://Username: Password@Server IP:Port

Example:

ftp://ftpuser:[email protected]:21
  1. Operating Instructions:
    • Upload file: Drag the local file into the Explorer window.

    • Download file: Drag the server file to the local folder.

    • Restrictions: Large file transfer and breakpoint transfer are not supported, and are only suitable for simple operations.

2. Access using the command line (cmd/PowerShell)

  • Open a command prompt or PowerShell and execute the following command:
ftp 192.168.1.100  # Connect to the server
  • Enter a username and password:
Name: ftpuser
Password: ********
  • Commonly used commands:

Upload file:

put C:\

View the directory:

ls

Exit the connection:

quit

7. Safety advice

  • Disable anonymous login: Make sure the configuration is inanonymous_enable=NO
  • Use SFTP instead of FTP: Transfer files over SSH protocol (sftp user@server IP)。
  • Restrict IP access: Only trusted IPs are allowed to access FTP ports in the firewall.

8. Frequently Asked Questions

1. Upload file permission is denied

• Check directory permissions:

ls -ld /home/ftpuser  # The permission should be drwxr-x--- (750)

• Confirm configuration items:

write_enable=YES
allow_writeable_chroot=YES

2. Passive mode timeout

• Server-side check:

• confirmpasv_addressFill in correctly.

• Open50000-50010Port.

3. Check log location issues

sudo tail -f /var/log/  # View logs in real time

Summarize

Through the above steps, you have successfully set up the FTP service on the CentOS server and can remotely access and manage files through the Windows system. If you encounter connection problems, priority will be given to checking the firewall, SELinux policies and log files.

This is the article about the complete process of quickly building FTP services on CentOS server. For more related content on CentOS FTP services, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!