FTP server: what it is and how to set one up safely

What an FTP server does, how FTP, FTPS and SFTP differ, and how to set up secure file uploads with OpenSSH or vsftpd on Linux.

8–12 minutes
Assorted laptop and desktop hard drives

An FTP server is a program on a server that lets people log in and upload, download and manage files from another computer. This guide is for site owners and new server admins who have been asked for “FTP details”, or who want to set up file uploads on their own Linux server, and want to do it without leaving passwords exposed.

An FTP server listens on portPort A numbered door on a server. Each service listens behind its own door: web pages on 443, email on others, remote login on 22. More about Port → 21 and lets users transfer files with a client such as FileZilla. Plain FTP sends passwords and files unencrypted, so on a modern server use SFTPSFTP A secure way to copy files between your computer and a server. Like dragging files into a folder, but the folder is on the server. More about SFTP → (file transfer over SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH →, port 22) or, if you really need FTP, FTPS (FTP with TLS encryption). On Linux, SFTP is already built into OpenSSH; for FTPS, install vsftpd and switch on ssl_enable=YES.

What an FTP server does

FTP (File Transfer Protocol) is one of the oldest internet protocols. Its current form dates from 1985, long before encryption was normal. An FTP server is the software that speaks it: it waits for connections, checks a username and password, and then lets the user list folders, upload files, download them, rename them and delete them.

You meet FTP when a host gives you FTP details to upload website files to public_html, when a designer needs to push theme files to a site, or when an old scanner or backup tool can only send files by FTP.

The person connecting uses an FTP client: a desktop app such as FileZilla or WinSCP, a code editor plugin, or the command line. The server side is the program on the host, such as vsftpd, ProFTPD or Pure-FTPd on Linux, or IIS on Windows.

How FTP works: two connections and two modes

FTP is unusual because it uses two separate connections.

  1. The control connection goes to port 21. Your client sends commands over it, such as USER, PASS, LIST and STOR, and the server replies with numbered status codesHTTP status code The three-digit number a website sends back with every page, saying how it went: 200 means fine, 404 means not found, 500 means the site itself broke. More about HTTP status code →.
  2. A data connection is opened separately every time a file or folder listing is transferred.

How that data connection is opened depends on the mode:

ModeWho opens the data connectionPorts involvedWorks well behind firewalls?
ActiveThe server connects back to the clientServer port 20 to a port on the clientNo, home routers usually block it
PassiveThe client connects to the serverA port the server picks from a rangeYes, if the server firewall allows the range

Almost every client uses passive mode today. That matters when you run the server yourself: as well as port 21, the firewallFirewall A gatekeeper that decides which connections are allowed into a server and blocks the rest. More about Firewall → has to allow the range of passive ports the server hands out. If it does not, you can log in but folder listings hang, which is the single most common FTP problem. You can read more about ports in what a port number is.

FTP, FTPS and SFTP compared

Three similar names cause confusion. They are different things.

FTPFTPSSFTP
What it isThe original File Transfer ProtocolFTP wrapped in TLS encryptionA file transfer system built into SSH
EncryptedNoYesYes
Usual port21 plus passive range21 (explicit) or 990 (implicit) plus passive range22
Server softwarevsftpd, ProFTPD, Pure-FTPdSame as FTP, with TLS switched onOpenSSH, already on most Linux servers
Firewall rulesSeveral portsSeveral portsOne port
LoginUsername and passwordUsername and passwordPassword or SSH key

Plain FTP should not be used over the internet. Anyone who can see the traffic, such as someone on the same café Wi-Fi or a compromised router along the way, can read the username, password and every file in clear text.

SFTP is the best choice for most people. It is a separate protocol that runs inside an SSH connection, so it is encrypted, uses a single port and works with SSH keys. FileZilla, WinSCP and Cyberduck all support it. If your server already accepts SSH logins, it already has an SFTP server and you do not need to install anything.

FTPS is the right choice only when a device or program you cannot change insists on FTP. It keeps the FTP behaviour but encrypts it with the same TLS used by HTTPSHTTPS The secure version of the web, shown by the padlock. Everything sent between you and the site is scrambled so nobody in between can read or change it. More about HTTPS →.

Check whether you already have an SFTP server

On any Linux server where OpenSSH is running, SFTP normally works out of the box. From your own computer, try:

sftp exampleco@203.0.113.10

If you get an sftp> prompt, it works. A few commands to try:

ls
put index.html
get backup.zip
exit

In FileZilla, choose SFTP – SSH File Transfer Protocol in the Site Manager, enter the server address, port 22 and your SSH username. If you use a key, set the logon type to Key file.

If the connection is refused, check SSH first with the steps in how to connect to a server with SSH.

Give someone SFTP access to one folder only

A common need is letting a designer upload files without giving them a full shell on the server. OpenSSH can lock a group of users into their own folder. Create the group and user on Ubuntu or Debian:

sudo groupadd sftponly
sudo useradd -m -g sftponly -s /usr/sbin/nologin designer
sudo passwd designer

On AlmaLinux and Rocky Linux, use /sbin/nologin as the shell. Then add this block at the end of /etc/ssh/sshd_config:

Match Group sftponly
    ChrootDirectory %h
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no

ChrootDirectory makes the user’s home folder look like the top of the file system, so they cannot browse elsewhere. OpenSSH requires that folder to be owned by root and not writable by anyone else, so give the user a writable folder inside it:

sudo chown root:root /home/designer
sudo chmod 755 /home/designer
sudo mkdir /home/designer/uploads
sudo chown designer:sftponly /home/designer/uploads

Check the configuration, then reload SSH (the service is called ssh on Ubuntu and Debian, sshd on AlmaLinux and Rocky):

sudo sshd -t
sudo systemctl reload ssh

sshd -t prints nothing when the file is valid. Keep your current SSH session open while you test the new user from a second window.

How to set up an FTPS server with vsftpd

Only do this if something really needs FTP. vsftpd (“very secure FTP daemon”) is the usual choice on Linux because it is small and has a good security record.

1. Install vsftpd

On Ubuntu and Debian:

sudo apt update
sudo apt install vsftpd

On AlmaLinux and Rocky Linux:

sudo dnf install vsftpd
sudo systemctl enable --now vsftpd

The configuration file is /etc/vsftpd.conf on Ubuntu and Debian, and /etc/vsftpd/vsftpd.conf on AlmaLinux and Rocky. Make a copy before editing it.

2. Set the basic options

Make sure these lines are present and not commented out with #:

anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
  • anonymous_enable=NO stops anyone logging in without a password.
  • local_enable=YES lets normal Linux users log in, and write_enable=YES lets them upload.
  • chroot_local_user=YES locks each user into their home folder. Without allow_writeable_chroot=YES, vsftpd refuses logins to a writable home folder with the error 500 OOPS: vsftpd: refusing to run with writable root inside chroot().
  • The two pasv_ lines fix the passive port range so you can open it in the firewall. Any unused range above 1024 works.

3. Turn on TLS encryption

You need a certificate for the server’s hostname, for example one from Let’s Encrypt for ftp.example.com. Then add:

ssl_enable=YES
rsa_cert_file=/etc/letsencrypt/live/ftp.example.com/fullchain.pem
rsa_private_key_file=/etc/letsencrypt/live/ftp.example.com/privkey.pem
force_local_logins_ssl=YES
force_local_data_ssl=YES

The two force_ lines refuse any login or transfer that is not encrypted, so a misconfigured client fails safely instead of sending the password in clear text. On Ubuntu, remove or comment out any older rsa_cert_file lines that point to the ssl-cert-snakeoil test certificate, so each option appears only once.

Restart the service and check it is running:

sudo systemctl restart vsftpd
sudo systemctl status vsftpd

4. Open the firewall

Allow port 21 and the passive range. On Ubuntu with UFW:

sudo ufw allow 21/tcp
sudo ufw allow 40000:40100/tcp

On AlmaLinux and Rocky with firewalld:

sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=40000-40100/tcp
sudo firewall-cmd --reload

If your host also has a cloud firewall in its control panelControl panel A website you log into to manage your hosting with buttons and forms, instead of typing commands. cPanel and Plesk are the common ones. More about Control panel →, open the same ports there. The general approach is covered in how to set up a firewall on Linux.

On AlmaLinux and Rocky Linux, SELinux may block uploads even when the file permissions look right. If logins work but uploads fail with “553 Could not create file”, run sudo setsebool -P ftpd_full_access on and try again.

5. Test the connection

From another computer, check that the server offers encryption:

openssl s_client -connect ftp.example.com:21 -starttls ftp

You should see the certificate details and a line saying Verification: OK. Then connect with FileZilla, choosing FTP – File Transfer Protocol and Require explicit FTP over TLS as the encryption. Upload a small test file and delete it again.

FTP on cPanel hosting

On cPanelcPanel The most popular hosting control panel: a website where you manage your email, files, databases and domains with point-and-click tools instead of commands. More about cPanel → hosting the FTP server is already installed and run by your host. You create logins in cPanel, Files, FTP Accounts, where you can limit each account to one folder and set a disk quota. The same screen shows the hostname and port to use. Your main cPanel username and password can usually connect over SFTP too, if your host allows SSH. Use FTP accounts for people who only need to reach one site’s folder, and remove them when the work is finished. See how to use cPanel for where it sits.

Common problems

SymptomCauseFix
Login works, then folder listing times outPassive ports blocked by a firewallOpen the pasv_min_port to pasv_max_port range on the server and any cloud firewall
“Connection refused” on port 21vsftpd not running, or port 21 not allowedRun systemctl status vsftpd and check the firewall
530 Login incorrectWrong password, or the user’s shell is not listed in /etc/shellsReset the password, or add the shell to /etc/shells
500 OOPS: refusing to run with writable root inside chroot()Home folder is writable and chroot is onAdd allow_writeable_chroot=YES or use a root-owned home with a writable subfolder
553 Could not create fileNo write permission, write_enable=NO, or SELinuxCheck folder ownership, set write_enable=YES, check the SELinux boolean
Passive mode connects to a private addressServer is behind NAT and advertises its internal IPSet pasv_address= to the public IP
SFTP connects but drops straight away for a chrooted userChroot folder not owned by rootRun chown root:root and chmod 755 on the user’s home folder

On Ubuntu, vsftpd logs to /var/log/vsftpd.log; SFTP messages appear in sudo journalctl -u ssh.

Keeping file transfer safe

  • Prefer SFTP with SSH keys over any password-based FTP.
  • Never allow plain FTP over the internet: force TLS or switch it off.
  • Give each person their own login, locked to the folder they need.
  • Remove logins when a contractor’s work is done.
  • Check which ports are really open from outside with a port checker.

Official documentation

Get the next guide

One email when there is something worth reading: new guides, errors going around, and hosting changes that affect your site.

No tracking pixels, and one click to leave.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.