FTP Server Setup on Linux

FTP (File Transfer Protocol) is one of the oldest and most reliable methods for transferring files over a network. vsftpd (Very Secure FTP Daemon) is a lightweight, secure FTP server available on Linux systems. This comprehensive guide covers installing, configuring, securing, and maintaining an FTP server on Ubuntu/Debian-based Linux systems.
What is FTP and vsftpd?
FTP is a protocol for transferring files between computers over a TCP/IP network. While modern alternatives like SFTP and SCP offer better security, FTP remains useful for legacy systems and specific use cases.
vsftpd stands for "Very Secure FTP Daemon" and is the most popular FTP server for Linux because it:
- Easy Installation - Single command setup
- Easy Configuration - Simple configuration file
- Easy Maintenance - Minimal ongoing management
- Lightweight - Low system resource usage
- Secure Features - Built-in security options
- Reliable - Stable and production-tested
When to Use FTP
FTP is useful for:
- Legacy system compatibility
- Anonymous file distribution
- Internal network file sharing
- Automated backups
- Third-party vendor integrations
- Simple file upload/download scenarios
When NOT to use FTP:
- Public internet file transfers (use SFTP/HTTPS instead)
- Sensitive data transfer (no encryption by default)
- New projects (use modern alternatives)
- User authentication over untrusted networks
Prerequisites
- Ubuntu/Debian-based Linux system
- Root or sudo access
- Minimum 1GB free disk space
- Internet connectivity for package installation
- Basic understanding of Linux file permissions
Step 1: Install vsftpd
Update your package manager and install vsftpd:
# Update package lists
sudo apt update
# Install vsftpd
sudo apt install -y vsftpd
# Verify installation
vsftpd --version
Step 2: Understand vsftpd Configuration
The main configuration file is /etc/vsftpd.conf. Make a backup before editing:
# Backup original configuration
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.backup
# View current configuration
sudo cat /etc/vsftpd.conf | grep -v "^#" | grep -v "^$"
Step 3: Configure FTP Authentication Methods
FTP supports two authentication approaches: anonymous and authenticated.
Option A: Anonymous FTP Access
This allows anyone to download files without credentials:
sudo nano /etc/vsftpd.conf
Find and modify these settings:
# Enable anonymous login
anonymous_enable=YES
# Set anonymous user (default: ftp)
ftp_username=ftp
# Allow directory listing
anon_list_enable=YES
# Allow file downloads
anon_read_only=YES
# Set anonymous home directory
anon_root=/srv/ftp
Option B: Authenticated FTP Access
Allow system users to login with their credentials:
# Disable anonymous access
anonymous_enable=NO
# Enable local user logins
local_enable=YES
# Allow local users to write
write_enable=YES
# Restrict users to home directory (recommended)
chroot_local_user=YES
Step 4: Set Default Directory Structure
vsftpd automatically creates an FTP user with /srv/ftp as the home directory:
# Create FTP directory if it doesn't exist
sudo mkdir -p /srv/ftp
# Set permissions (readable by ftp user)
sudo chmod 555 /srv/ftp
# Change ownership
sudo chown ftp:ftp /srv/ftp
# Verify
ls -la /srv/ftp
Relocate FTP Home Directory
To use a different directory:
# Create your custom directory
sudo mkdir -p /home/ftp-storage
# Change ownership
sudo chown ftp:ftp /home/ftp-storage
# Set read-only permissions
sudo chmod 555 /home/ftp-storage
# Edit vsftpd configuration
sudo nano /etc/vsftpd.conf
# Find "anon_root" and change to:
anon_root=/home/ftp-storage
Restart the service:
sudo systemctl restart vsftpd
Step 5: Enable Upload Capabilities
For Authenticated Users
Enable write permissions for authenticated system users:
# Edit configuration
sudo nano /etc/vsftpd.conf
# Set write permissions
write_enable=YES
# Allow creating directories
anon_mkdir_write_enable=NO
For Anonymous Users (NOT RECOMMENDED)
Warning: Enabling anonymous FTP upload is an extreme security risk. Only use in controlled internal networks.
# Enable anonymous upload (DANGEROUS!)
anon_upload_enable=YES
# Create writable upload directory
sudo mkdir -p /srv/ftp/uploads
sudo chown ftp:ftp /srv/ftp/uploads
sudo chmod 755 /srv/ftp/uploads
# Set in configuration
anon_root_write_enable=NO
anon_mkdir_write_enable=YES
Step 6: Implement Security Hardening
6A: Chroot Restrictions
Confine FTP users to their home directories:
# Restrict local users to home directories
chroot_local_user=YES
# This is very important for security
# Users cannot navigate above their home directory
6B: User Blacklisting
Prevent specific system users from accessing FTP:
# Edit userlist
sudo nano /etc/ftpusers
# Add users (one per line) that should NOT have FTP access
root
daemon
bin
sys
sync
games
man
lp
mail
6C: FTPS Encryption (SSL/TLS)
Enable encrypted FTP connections:
# Edit configuration
sudo nano /etc/vsftpd.conf
# Enable SSL/TLS
ssl_enable=YES
# Use only TLS (more secure)
ssl_tlsv1=NO
ssl_tlsv1_1=NO
ssl_tlsv1_2=YES
ssl_tlsv1_3=YES
# Certificate and key paths
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.key
# Require TLS for control and data connections
force_local_data_ssl=YES
force_local_logins_ssl=YES
Generate Self-Signed Certificate
# Generate self-signed certificate (valid 365 days)
sudo openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/ssl/private/vsftpd.key \
-out /etc/ssl/certs/vsftpd.pem \
-subj "/C=IN/ST=State/L=City/O=Organization/CN=ftp.example.com"
# Set permissions
sudo chmod 600 /etc/ssl/private/vsftpd.key
sudo chmod 644 /etc/ssl/certs/vsftpd.pem
6D: Shell Restrictions
Allow FTP-only access without shell login:
# Create FTP-only shell
echo "/usr/sbin/nologin" | sudo tee -a /etc/shells > /dev/null
# For specific user
sudo usermod -s /usr/sbin/nologin ftpuser
# This user can use FTP but cannot SSH
6E: Connection Limits
Limit concurrent connections:
# Edit configuration
sudo nano /etc/vsftpd.conf
# Maximum client connections
max_clients=100
# Maximum connections per IP
max_per_ip=5
Step 7: Service Management
Start the Service
# Start vsftpd
sudo systemctl start vsftpd
# Enable auto-start on boot
sudo systemctl enable vsftpd
# Check status
sudo systemctl status vsftpd
Restart After Configuration Changes
# Restart service
sudo systemctl restart vsftpd
# Check logs for errors
sudo journalctl -u vsftpd -n 20
# Monitor real-time logs
sudo tail -f /var/log/vsftpd.log
Step 8: Configure Firewall
Allow FTP traffic through the firewall:
# UFW (Ubuntu)
sudo ufw allow 21/tcp
sudo ufw allow 22/tcp
sudo ufw allow 990/tcp # FTPS explicit
sudo ufw allow 989/tcp # FTPS implicit
# Firewalld (Red Hat)
sudo firewall-cmd --add-service=ftp --permanent
sudo firewall-cmd --reload
For Passive Mode FTP
If using passive mode, configure a port range:
# Edit configuration
sudo nano /etc/vsftpd.conf
# Add
pasv_enable=YES
pasv_min_port=60000
pasv_max_port=60100
# Allow these ports in firewall
sudo ufw allow 60000:60100/tcp
Step 9: Connect to FTP Server
From Linux Command Line
# Anonymous connection
ftp ftp.example.com
# Authenticated connection
ftp [email protected]
# Using a script
echo -e "open ftp.example.com\nuser username password\ncd directory\nget filename\nbye" | ftp -n
Using GUI Applications
- FileZilla - Cross-platform FTP client
- Nautilus (GNOME) - Built-in file manager
- Dolphin (KDE) - Built-in file manager
- WinSCP - Windows client for SFTP
Example Connection Commands
# Using curl
curl -u username:password ftp://ftp.example.com/path/file
# Using wget
wget --ftp-user=username --ftp-password=password \
ftp://ftp.example.com/path/file
# Using lftp (advanced)
lftp -u username,password ftp://ftp.example.com
Troubleshooting
Issue 1: Connection Refused
# Check if service is running
sudo systemctl status vsftpd
# Check if listening on port 21
sudo netstat -tulnp | grep ftp
# Check firewall rules
sudo ufw status
Issue 2: Authentication Failed
# Verify user exists
id username
# Check user shell is not restricted
grep username /etc/shells
# Check vsftpd logs
sudo journalctl -u vsftpd -n 50
Issue 3: Passive Mode Connection Issues
# Verify passive mode is enabled
grep "pasv_enable" /etc/vsftpd.conf
# Check port range is allowed in firewall
sudo ufw status numbered
Issue 4: Slow Transfers
# Check network connectivity
ping -c 4 192.168.1.100
# Monitor bandwidth
iftop -i eth0
# Check CPU usage
top -b -n 1 | head -20
Best Practices
- Use FTPS for sensitive data - Enable SSL/TLS encryption
- Restrict users to home directories - Enable chroot_local_user
- Disable anonymous upload - Set anon_upload_enable=NO
- Regular backups - Backup configuration files
- Monitor logs - Watch for suspicious activity
- Limit connections - Set max_clients and max_per_ip
- Update regularly - Keep vsftpd and system updated
- Remove default accounts - Delete unused FTP users
- Use strong passwords - Enforce password policies
- Audit access logs - Review /var/log/vsftpd.log
Conclusion
vsftpd provides a lightweight, secure FTP server solution for Linux. With proper configuration and security hardening, it's suitable for internal file sharing, legacy system support, and controlled file distribution. Always prioritize security by using FTPS, restricting user access, and monitoring your server regularly.