What Port 21 Does
An FTP session starts with a connection to port 21 of the server. On that connection the client logs in and sends commands such as listing a folder or fetching a file. The files and folder listings themselves do not travel on port 21: each transfer opens a separate data connection. This split is the source of most FTP firewall trouble. For the protocol itself, see what is FTP.
Active and Passive Mode
| Mode | Data connection |
|---|---|
| Active | Server connects back to the client, usually from port 20 |
| Passive | Client connects to a server port from a range |
In active mode the server opens a connection to the client, which fails when the client sits behind NAT or a firewall, as most do. In passive mode the server names a port and the client connects to it, so only the server's firewall must allow the connection. Passive mode is the default in current clients.
The Passive Port Range
A passive FTP server needs a fixed range of ports that the firewall allows. In vsftpd, set the range in /etc/vsftpd.conf:
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100If the server is behind NAT, it must also announce its public address with pasv_. Other FTP servers have the same setting under another name, such as PassivePorts in ProFTPD. Restart the service afterward.
Open the Firewall
On Ubuntu and Debian with ufw:
sudo ufw allow 21/tcp
sudo ufw allow 40000:40100/tcpOn AlmaLinux and Rocky Linux with firewalld:
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=40000-40100/tcp
sudo firewall-cmd --reloadA symptom of a missing passive range: the login works, and then the folder listing hangs or times out. More on rules in UFW allow port.
Plain FTP Sends Passwords in Clear Text
Plain FTP encrypts nothing. Anyone who can see the traffic between the client and the server can read the user name, the password, and the files. On the public internet that is reason enough to avoid it for anything but public downloads.
The Safer Choices
- FTPS with explicit TLS: the client connects to port 21 and upgrades the session with the AUTH TLS command. In vsftpd this needs a certificate and
ssl_.enable=YES - FTPS with implicit TLS: TLS from the first byte on port 990. It is older and less common.
- SFTP on port 22: a different protocol that runs inside SSH, uses one connection, and needs no extra server software on Linux. See how to use SFTP and port 22.
FTPS still uses passive data ports, and because the control channel is encrypted, firewalls can no longer read it to open data ports on their own. A fixed passive range is required. The full comparison is in SFTP vs FTP.
Check Whether Something Listens on Port 21
sudo ss -ltnp 'sport = :21'From another machine, nc -vz example.com 21 tests the port, and an FTP server answers a connection with a greeting line that starts with 220. To test FTPS with curl, which asks for the password:
curl -v --ssl-reqd ftp://example.com/ --user deployClose Port 21 When It Is Not Used
If you moved to SFTP, stop and disable the FTP service and remove its firewall rules:
sudo systemctl disable --now vsftpd
sudo ufw delete allow 21/tcp
sudo ufw delete allow 40000:40100/tcpWith firewalld, remove the rules with --remove-service=ftp and --remove-port=40000-40100/tcp together with --permanent, then reload. Run ss again afterward to confirm that nothing listens on port 21.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations