How to Configure vsftpd for a User's Directory on an Ubuntu 24.04 VPS or Server
Set up vsftpd on Ubuntu 24.04 with a chrooted per-user directory, an allow list, passive ports behind ufw and mandatory TLS.
This guide sets up vsftpd on Ubuntu 24.04 LTS so that one named user can log in over FTP with TLS encryption and is locked into a directory inside their own home. Nobody else can log in, anonymous access is off, and passwords never cross the network in clear text. The steps are the same on Ubuntu 22.04 LTS and work on a VPS or a dedicated server alike.
Ubuntu 18.04 is past its standard support period; if you are still on it, upgrade first rather than exposing a new service on it.
Requirements
- Ubuntu 24.04 LTS (or 22.04) and a user with
sudorights. - The server's public IP address. The examples use
203.0.113.10. - An FTP client that supports explicit FTP over TLS, such as FileZilla, WinSCP or
lftp.
Step 1 – Install vsftpd
sudo apt update
sudo apt install vsftpd
The service starts immediately. Keep a copy of the packaged configuration before you change it:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
Step 2 – Open the firewall
FTP uses port 21 for commands and, in passive mode, a separate port per transfer. You will pin the passive ports to the range 40000–50000 in Step 4, so open that range now. If ufw is not active yet, allow SSH first so you do not lock yourself out.
sudo ufw allow OpenSSH
sudo ufw allow 20:21/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw enable
sudo ufw status
Port 990 is only needed for the legacy "implicit" FTPS mode, which this setup does not use. If your provider has its own network firewall, open the same ports in its control panel.
Step 3 – Create the FTP user and directory
Create the account. The examples use deploy; choose a strong password when asked.
sudo adduser deploy
vsftpd will lock the user into a directory (a chroot). For security it refuses to do that when the directory itself is writable by the user, so build two levels: a read-only ftp directory that becomes the user's root, and a writable files directory inside it for uploads.
sudo mkdir -p /home/deploy/ftp/files
sudo chown nobody:nogroup /home/deploy/ftp
sudo chmod a-w /home/deploy/ftp
sudo chown deploy:deploy /home/deploy/ftp/files
Check the result and add a file to test downloads with later:
sudo ls -la /home/deploy/ftp
echo "vsftpd test file" | sudo tee /home/deploy/ftp/files/test.txt
ftp should be listed as dr-xr-xr-x owned by nobody, and files as owned by deploy.
Step 4 – Configure vsftpd for the user's directory
Open /etc/vsftpd.conf. Make sure these two lines are present, uncommented, and have the values shown:
anonymous_enable=NO
local_enable=YES
Uncomment or add the following so the user may upload and is confined to the chroot:
write_enable=YES
chroot_local_user=YES
Then add these lines at the end of the file:
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=40000
pasv_max_port=50000
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
user_sub_tokenandlocal_rootsend every user to/home/<name>/ftpafter login, so the same configuration works when you add more users.pasv_min_portandpasv_max_portrestrict passive data connections to the range you opened in the firewall.userlist_deny=NOturns the user list into an allow list: only accounts named in the file can log in, and everyone else is refused before a password is even requested.
Add your user to the allow list:
echo "deploy" | sudo tee -a /etc/vsftpd.userlist
Step 5 – Encrypt connections with TLS
Plain FTP sends the password and all data unencrypted. Create a certificate for vsftpd; a self-signed one is enough to encrypt the traffic. Use the server's host name as the common name when prompted.
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.key -out /etc/ssl/certs/vsftpd.pem
In /etc/vsftpd.conf, replace the existing rsa_cert_file, rsa_private_key_file and ssl_enable lines with:
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.key
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
require_ssl_reuse=NO
ssl_ciphers=HIGH
force_local_logins_sslandforce_local_data_sslreject any login or transfer that is not encrypted.- The vsftpd build in Ubuntu 24.04 allows TLS 1.2 and has the older SSL and TLS versions switched off by default, so no protocol lines are needed.
require_ssl_reuse=NOavoids transfer failures with clients that do not reuse the TLS session for data connections. Leave it at the defaultYESif your clients cope with it.ssl_ciphers=HIGHreplaces the weak default cipher with OpenSSL's strong cipher set.
If the server has a domain name and a Let's Encrypt certificate, point the two file options at fullchain.pem and privkey.pem under /etc/letsencrypt/live/example.com/ instead; clients then connect without a certificate warning.
Restart the service to apply everything:
sudo systemctl restart vsftpd
sudo systemctl status vsftpd
Step 6 – Test the setup
From another machine, list the upload directory with curl. --ssl-reqd insists on TLS and -k accepts the self-signed certificate; you are prompted for the password.
curl -k --ssl-reqd --user deploy ftp://203.0.113.10/files/
The listing should show test.txt. Upload a file to confirm write access:
curl -k --ssl-reqd --user deploy -T upload.txt ftp://203.0.113.10/files/
Then run two negative tests. The same command without --ssl-reqd and -k must be refused because the session is not encrypted, and a login with any account that is not in /etc/vsftpd.userlist must be denied. In a graphical client, choose "Require explicit FTP over TLS" as the encryption setting, port 21, and passive mode.
Step 7 – Optional: remove shell access
A user who only needs FTP does not need an SSH shell. vsftpd authenticates through PAM, which only accepts shells listed in /etc/shells, so register the nologin shell there first and then assign it:
echo "/usr/sbin/nologin" | sudo tee -a /etc/shells
sudo usermod -s /usr/sbin/nologin deploy
Troubleshooting
- Login works but the directory listing hangs: the passive port range is blocked. Check
sudo ufw statusand any firewall in your hosting control panel. If the server sits behind NAT, setpasv_addressto its public IP. - Login refused with "refusing to run with writable root inside chroot": the chroot directory is writable. Re-run the
chownandchmod a-wcommands from Step 3 on/home/deploy/ftp. - "530 Permission denied" before the password prompt: the user is missing from
/etc/vsftpd.userlist. - "530 Login incorrect" with the right password: the user's shell is not listed in
/etc/shells, or the account appears in/etc/ftpusers, the list of accounts that are always denied FTP access. - The service does not start: run
sudo journalctl -u vsftpd -e; a misspelled option name or a space around=invsftpd.confis the usual cause.
Frequently asked questions
How do I add a second FTP user?
Repeat Step 3 with the new name and append that name to /etc/vsftpd.userlist. Because local_root uses the $USER token, no further configuration change or restart is needed.
Would SFTP be a better choice than FTP?
Often, yes. SFTP runs over the SSH service you already have, needs only port 22, and avoids the passive-port and firewall issues of FTP. Use vsftpd when a device or application can only speak FTP or FTPS.
Can the user's FTP root be somewhere other than the home directory?
Yes. local_root can point to any path, for example /var/www/$USER. The same rule applies: the directory the user is locked into must not be writable by that user, so keep a writable sub-directory inside it.
Why not simply set allow_writeable_chroot=YES?
Many guides suggest that option to silence the writable-root error. It removes a safety check that exists because a writable chroot can be abused, and the two-directory layout used here makes it unnecessary.