PortGate

Resources · Port reference · port 21

Port 21 (FTP): what it is and how to secure it

FTP on port 21 sends passwords and files in clear text. Replace it with SFTP over the SSH you already run, and close 21.

Check command

sudo ss -tlnp | grep ':21 '

Copied.

Port 21 is FTP, and on a modern server it should be closed. FTP sends usernames, passwords and files unencrypted. SFTP does the same job over SSH, is encrypted, and needs no extra port or daemon. Every common client (FileZilla, WinSCP, Cyberduck, VS Code extensions) supports it.

What port 21 is for

FTP uses port 21 for commands and a second connection for data: port 20 in active mode, or a range of high ports in passive mode. So an FTP server usually means 21 plus a passive range open in the firewall.

Why an open 21 is risky

  • Clear text. Anyone on the path (a café Wi-Fi, a compromised router) can read the password.
  • Brute force. Bots try common usernames and passwords on 21 constantly.
  • Anonymous login. If anonymous_enable is on, anyone can list, and sometimes upload, files.
  • Web roots. FTP accounts often point at the website folder, so a stolen FTP password is a way to upload a webshell.

Check yours

sudo ss -tlnp | grep ':21 '
systemctl list-units --type=service | grep -Ei 'ftp|vsftpd|proftpd|pure-ftpd'

Fix it

  1. Make sure SFTP works first. Any user who can SSH in can use SFTP with the same key:

    sftp user@your-server
    
  2. Stop and disable the FTP server:

    sudo systemctl disable --now vsftpd     # or proftpd / pure-ftpd
    
  3. Remove the firewall rules for 21 and the passive range:

    sudo ufw status numbered
    sudo ufw delete allow 21/tcp
    

If someone needs file access but not a shell, give them an SFTP-only account locked to one folder with OpenSSH's ChrootDirectory and ForceCommand internal-sftp in a Match User block.

If FTP is truly required (an old device or partner), use FTPS (ssl_enable=YES in vsftpd), turn off anonymous access (anonymous_enable=NO), restrict 21 to the partner's IP, and keep the passive range small.

Common mistakes

  • Leaving the passive port range open after removing 21.
  • Hosting control panels that install FTP by default. Turn it off in the panel.

FAQ

Is SFTP the same as FTPS? No. SFTP runs over SSH (port 22). FTPS is FTP with TLS (ports 21 and 990, plus the passive range). SFTP is simpler to run safely.

How do I get warned? PortGate's Server Guard alerts when port 21, or any new port, opens to the internet.