Install and configure vsftpd on a Linux ECS instance to enable secure FTP file transfers.
Quick deployment
Click Run now to open Terraform Explorer and automatically build an FTP site on an ECS instance.
Prerequisites
An ECS instance that meets the following requirements is created. To create one, see Create an instance using the wizard.
-
Operating system: Alibaba Cloud Linux 3/2, CentOS 7.x 64-bit, Ubuntu, or Debian.
-
IP address: The instance has a static public IP address or an associated EIP. See Elastic IP Address.
Overview
vsftpd (Very Secure FTP Daemon) is an open-source FTP server for UNIX and Linux systems. Key features:
-
High security: strict security audits and multiple mechanisms to prevent common attacks.
-
High performance: handles many concurrent connections with efficient file transfers.
-
Simple configuration: flexible, easy-to-understand options for various needs.
-
IPv6 support: native support for IPv6 networks.
Build the VSFTP service
Alibaba Cloud Linux 3 and 2/CentOS 7.x
Step 1: Install vsftpd
-
Update the system and install
vsftpd.sudo yum update -y sudo yum install vsftpd -y -
Start the FTP service and enable auto-start on boot.
sudo systemctl start vsftpd sudo systemctl enable vsftpd -
Check whether the service is started.
netstat -antup | grep ftpOutput similar to the following indicates the FTP service started successfully.

By default, vsftpd enables anonymous access. Anonymous users can log on without credentials but cannot modify or upload files.
Step 2: Configure vsftpd
-
Create a dedicated FTP user and set a password. This example uses
ftpuser.sudo useradd -d /data/ftp -s /sbin/nologin ftpuser # Specify the home directory and disable shell access sudo passwd ftpuser -
Create the FTP directory and set permissions.
sudo mkdir -p /data/ftp # Create a custom storage directory sudo chown ftpuser:ftpuser /data/ftp sudo chmod 750 /data/ftp # Permissions must be 755 or 750 -
Edit the
vsftpdconfiguration file.NoteFTP supports active and passive modes. Passive mode is recommended because most clients are behind firewalls or NAT and cannot expose their real IP addresses.
-
Back up the
vsftpdconfiguration file.sudo cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak -
Edit the configuration file.
sudo vim /etc/vsftpd/vsftpd.conf -
Set the basic security configuration.
listen=YES # Enable IPv4 listener anonymous_enable=NO # Disable anonymous access local_enable=YES # Enable local user logon write_enable=YES # Allow file uploads chroot_local_user=YES # Lock users to their home directory allow_writeable_chroot=YES # Resolve chroot write errors -
Append the passive mode configuration.
pasv_enable=YES # Enable passive mode pasv_min_port=40000 # Lower limit of the passive port range pasv_max_port=40100 # Upper limit of the passive port range pasv_address=public_ip_address # Must be set to the server's public IP address
-
-
Restart
vsftpd.sudo systemctl restart vsftpd
Step 3: Set security group rules
After building the FTP service, add inbound security group rules based on the FTP mode. See Add a security group rule.
Most clients are behind a LAN with translated IP addresses. In active mode, clients must expose their real IP addresses, or FTP connections may fail.
-
Active mode: Allow traffic on port 21.
-
Passive mode: Allow traffic on port 21 and ports 40000–40100 (the pasv_min_port to pasv_max_port range in /etc/vsftpd/vsftpd.conf). See Configuring FTP passive mode ports.
Step 4: Verify the FTP service
You can verify the FTP service with an FTP client, a browser, or a file explorer. This example uses the file explorer.
-
Test the local connection.
Test the connection from the local machine.
ftp ftpuser@localhostA
Login successfulmessage indicates a successful connection.
-
Test the client connection.
On the client computer, open the file explorer and enter the FTP address, as shown in the figure.

Enter the FTP username and password in the logon dialog box. After logging on, you can upload and download files.
Ubuntu and Debian
Step 1: Install VSFTP
-
Update the system and install
vsftpd.sudo apt update && sudo apt upgrade -y sudo apt install vsftpd -y -
Start
vsftpdand enable auto-start on boot.sudo systemctl start vsftpd sudo systemctl enable vsftpd
Step 2: Configure VSFTP
-
Create a dedicated FTP user.
sudo useradd -m -s /bin/bash ftpuser # Create a user and automatically generate a home directory sudo passwd ftpuser # Set the user password (a strong password is recommended) -
Create the file storage directory and set permissions.
sudo mkdir /home/ftpuser/ftp-files sudo chown ftpuser:ftpuser /home/ftpuser/ftp-files sudo chmod 755 /home/ftpuser/ftp-files -
Back up the original configuration file.
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak -
Edit the configuration file.
sudo nano /etc/vsftpd.confApply the following settings:
# Basic configuration listen=YES anonymous_enable=NO # Disable anonymous access local_enable=YES # Allow local user logon write_enable=YES # Enable write permissions chroot_local_user=YES # Lock users in their home directoryAppend the following to the file:
allow_writeable_chroot=YES # Allow writing to the chroot directory local_root=/home/ftpuser/ftp-files # Specify the root directory for the FTP user # Passive mode configuration (to resolve external network connection issues) pasv_enable=YES pasv_address=xx.xx.xx.xx # Replace with your public IP address pasv_min_port=40000 pasv_max_port=40100 -
Restart the FTP service.
sudo systemctl restart vsftpd -
A default user named ftp is created without a password during FTP installation. Change the password for this user.
sudo passwd ftpSet a strong password and skip all other prompts.
-
Add the user to the FTP user allowlist.
echo "ftp" | sudo tee -a /etc/vsftpd.userlist -
Create an FTP file directory and grant user permissions.
-
Create an FTP folder.
sudo mkdir /home/ftp -
Set folder ownership.
This example grants read, write, and full control permissions. Adjust as needed.
sudo chmod 777 /home/ftp
-
Step 3: Set security group rules
After building the FTP service, add inbound security group rules based on the FTP mode. See Add a security group rule.
Most clients are behind a LAN with translated IP addresses. In active mode, clients must expose their real IP addresses, or FTP connections may fail.
-
Active mode: Allow traffic on port 21.
-
Passive mode: Allow traffic on port 21 and ports 40000–40100 (the pasv_min_port to pasv_max_port range in /etc/vsftpd/vsftpd.conf). See Set up an FTP site on Windows.
Step 4: Verify the FTP service
You can verify the FTP service with an FTP client, a browser, or a file explorer. This example uses the file explorer.
-
Test the local connection.
Test the connection from the local machine.
ftp ftpuser@localhostA
Login successfulmessage indicates a successful connection.
-
Test the client connection.
On the client computer, open the file explorer and enter the FTP address, as shown in the figure.

Enter the FTP username and password in the logon dialog box. After logging on, you can upload and download files.
Troubleshooting
|
Issue |
Solution |
|
Timeout after |
Check the public IP address and firewall rules on both client and server. |
|
|
Set directory permissions to 755. |
|
Only empty directories are listed |
Check the |
|
|
Run |
|
Passive mode connection timeout |
Check firewall rules and the pasv_address setting. |
|
Cannot upload files |
Verify directory permissions are 755 or 750. |
Appendix
vsftpd configuration file and parameters
Files in the /etc/vsftpd directory:
-
/etc/vsftpd/vsftpd.conf: Core vsftpd configuration file. -
/etc/vsftpd/ftpusers: Blacklist file. Users in this file cannot access the FTP server. -
/etc/vsftpd/user_list: Whitelist file. Users in this file can access the FTP server.
Parameters in the vsftpd.conf configuration file:
-
Logon control parameters:
Parameter
Description
anonymous_enable=YES
Accepts anonymous users.
no_anon_password=YES
Anonymous users can log on without a password.
anon_root=(none)
Home directory for anonymous users.
local_enable=YES
Accepts local users.
local_root=(none)
Home directory for local users.
-
User permission control parameters:
Parameter
Description
write_enable=YES
Allows file uploads (global).
local_umask=022
File permissions for local user uploads.
file_open_mode=0666
File permissions for uploads. Works with local_umask.
anon_upload_enable=NO
Anonymous users can upload files.
anon_mkdir_write_enable=NO
Anonymous users can create directories.
anon_other_write_enable=NO
Anonymous user: edit and delete permissions.
chown_username=lightwiter
Username for anonymous file uploads.