Website Vidya
Linux & ServersStep-by-Step Guide

How to Setup Secure FTP Server with VSFTPD on Ubuntu 24.04

Learn how to setup secure ftp server with vsftpd on ubuntu 24.04 with TLS/SSL encryption, chroot user isolation, passive port ranges, and UFW rules.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Setup Secure FTP Server with VSFTPD on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to setup secure ftp server with vsftpd on ubuntu 24.04 with TLS/SSL encryption, chroot user isolation, passive port ranges, and UFW rules.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing VSFTPD on Ubuntu 24.04
  • Step 2: Creating a Dedicated FTP User and Directory Hierarchy
Grounded in full engineering runbookWebsiteVidya AI Engine

File Transfer Protocol (FTP) has been a cornerstone of networked file sharing and website content delivery for decades.

However, traditional plain FTP is inherently insecure because it transmits usernames, passwords, and file contents across networks in unencrypted cleartext.

To protect sensitive data from eavesdropping and man-in-the-middle attacks, administrators implement FTPS (FTP over Transport Layer Security).

VSFTPD (Very Secure FTP Daemon) is the industry-standard, lightweight, highly secure FTP server for Linux systems, renowned for its strong security model, speed, and resilience against buffer overflows.

Advertisement

In this guide, we walk through how to setup secure ftp server with vsftpd on ubuntu, enforce SSL/TLS encryption, jail users to their home directories, and configure firewall rules.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

Advertisement
  • A server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A non-root administrative user with sudo privileges.
  • UFW firewall installed.
  • An FTP client that supports FTPS (such as FileZilla or WinSCP).

Step 1: Installing VSFTPD on Ubuntu 24.04

VSFTPD is available in Ubuntu's official repositories.

First, update your APT package cache, then install the vsftpd package:

Verify that the VSFTPD systemd service is active and running:

# Update package lists:
sudo apt update

# Install VSFTPD:
sudo apt install -y vsftpd

# Verify service status and enable on boot:
sudo systemctl enable --now vsftpd
sudo systemctl status vsftpd
# Expected output: Active: active (running)

Step 2: Creating a Dedicated FTP User and Directory Hierarchy

For security reasons, avoid logging into FTP using your administrative user account.

Advertisement

Create a dedicated unprivileged user named ftpuser with disabled shell login:

Set up a dedicated FTP upload directory and enforce chroot jail directory permissions:

# Create dedicated ftpuser with no shell access:
sudo adduser --disabled-login --gecos "" ftpuser
sudo passwd ftpuser

# Create home and upload directories:
sudo mkdir -p /home/ftpuser/ftp/files

# Set ownership of ftp root to nobody:nogroup (read-only for chroot):
sudo chown nobody:nogroup /home/ftpuser/ftp
sudo chmod a-w /home/ftpuser/ftp

# Set upload directory ownership to ftpuser:
sudo chown ftpuser:ftpuser /home/ftpuser/ftp/files
sudo chmod 755 /home/ftpuser/ftp/files

Step 3: Generating an SSL/TLS Certificate for Encrypted FTPS

To enforce modern TLS encryption, generate a private cryptographic key and SSL certificate using OpenSSL.

Store the certificate and private key in /etc/ssl/private/ with restricted access permissions:

Run the following command to generate a 2048-bit RSA certificate valid for 365 days:

# Generate self-signed SSL certificate for VSFTPD:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/private/vsftpd.pem \
  -out /etc/ssl/private/vsftpd.pem \
  -subj "/C=US/ST=State/L=City/O=WebsiteVidya/CN=ftp.example.com"

# Restrict permissions to root:
sudo chmod 600 /etc/ssl/private/vsftpd.pem

Step 4: Hardening the VSFTPD Configuration (/etc/vsftpd.conf)

Back up the original configuration file, then author a hardened configuration in /etc/vsftpd.conf.

This configuration restricts anonymous access, enables local write permissions, confines users to chroot jails, mandates TLS encryption, and defines a passive port range:

Apply the following settings to /etc/vsftpd.conf:

# Back up original config:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak

# Write hardened configuration:
cat << 'EOF' | sudo tee /etc/vsftpd.conf
# General Settings
listen=YES
listen_ipv6=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES

# Chroot Jail Settings
chroot_local_user=YES
chroot_list_enable=NO
user_sub_token=$USER
local_root=/home/$USER/ftp
allow_writeable_chroot=YES

# Passive Mode Ports
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100

# SSL/TLS Encryption Directives
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1_2=YES
ssl_tlsv1_3=YES
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
EOF

# Restart VSFTPD to apply changes:
sudo systemctl restart vsftpd

Step 5: Opening Firewall Ports in UFW

FTP utilizes port 21 for command control and port 20 for active data transfers.

In passive mode, the client initiates connections to a designated high-numbered port range (40000 to 40100 defined in our configuration):

Open command ports and the passive port range in UFW:

# Allow standard FTP command ports:
sudo ufw allow 20/tcp comment 'FTP Data'
sudo ufw allow 21/tcp comment 'FTP Control'

# Allow passive port range:
sudo ufw allow 40000:40100/tcp comment 'VSFTPD Passive Ports'

# Verify active UFW rules:
sudo ufw status

Step 6: Testing Encrypted FTPS Connection with FileZilla

Connect to your FTPS server using a client like FileZilla or WinSCP to verify TLS handshake and file transfers:

Configure your connection profile using these parameters:

FileZilla SettingValue to ConfigurePurpose
HostYOUR_SERVER_IP or domain.comTarget server endpoint
ProtocolFTP - File Transfer ProtocolStandard protocol family
EncryptionRequire explicit FTP over TLSMandates encrypted command and data channels
Logon TypeNormalAuthenticates with username and password
User / Passwordftpuser / password set in Step 2Unprivileged jailed account credentials

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

500 OOPS: vsftpd: refusing to run with writable root inside chroot()

Cause: The user's home root directory has write permissions enabled while chroot_local_user=YES is active.

Resolution: Ensure allow_writeable_chroot=YES is included in /etc/vsftpd.conf, or remove write permissions from /home/ftpuser/ftp using chmod a-w.

sudo chmod a-w /home/ftpuser/ftp && sudo systemctl restart vsftpd

Directory listing hanging or timing out in FileZilla

Cause: Passive port range (40000-40100) is blocked by UFW or an external cloud security group.

Resolution: Open TCP ports 40000 through 40100 in both UFW and your cloud provider network firewall.

sudo ufw allow 40000:40100/tcp

530 Non-anonymous sessions must use encryption

Cause: Client attempted an unencrypted plain FTP connection while force_local_logins_ssl=YES is enforced.

Resolution: Configure your FTP client to connect using 'Require explicit FTP over TLS' (FTPS).

cat /etc/vsftpd.conf | grep force_local_logins_ssl

Security Best Practices and Hardening

Never allow anonymous uploads in production; ensure anonymous_enable=NO remains set in /etc/vsftpd.conf.

Confine all FTP users to their home directory chroot jail to prevent unauthorized traversing of root filesystems.

Consider using SFTP (SSH File Transfer Protocol) over port 22 as a firewall-friendly, modern alternative to FTPS if passive port configuration is undesirable.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
FTPS is File Transfer Protocol over SSL/TLS, requiring multiple ports (21 for control and a passive port range for data). SFTP is SSH File Transfer Protocol, running entirely over an encrypted SSH connection on a single port (usually 22). SFTP is generally preferred for simple firewall routing.
In active mode, the server initiates the data connection back to the client, which consumer NAT firewalls block. In passive mode, the client initiates all data connections to the server's passive port range, making it firewall-compatible.
Yes. You can point rsa_cert_file and rsa_private_key_file in /etc/vsftpd.conf to your Certbot certificates located at /etc/letsencrypt/live/domain.com/fullchain.pem and privkey.pem.
Add the username to /etc/ftpusers, which contains a blacklist of user accounts forbidden from logging into VSFTPD.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout