How to set up an FTP server on Ubuntu 16.04
An FTP server is the best solution if you want to upload files to a server or give employees access to set up a website. This guide covers installing and configuring vsftpd on Ubuntu 16.04.
Installation
sudo apt-get update
sudo apt-get install vsftpdConfiguration
Back up the default config and open it for editing:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
sudo nano /etc/vsftpd.confApply the following settings:
# Disable anonymous login
anonymous_enable=NO
# Allow local users
local_enable=YES
# Allow uploads
write_enable=YES
# Restrict users to their home directories
chroot_local_user=YES
allow_writeable_chroot=YES
# Passive mode settings
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
# Show hidden files (optional)
force_dot_files=YESCreating an FTP user
sudo adduser ftpuser
sudo passwd ftpuserTo prevent the user from logging in via SSH:
sudo usermod -s /usr/sbin/nologin ftpuser
echo "/usr/sbin/nologin" | sudo tee -a /etc/shellsUFW firewall rules
If UFW is enabled, open the required ports:
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 40000:40100/tcp
sudo ufw reloadStarting and enabling vsftpd
sudo systemctl start vsftpd
sudo systemctl enable vsftpdConnecting to the FTP server
Use any FTP client (FileZilla, lftp, command-line ftp) to connect:
- Host: your server IP
- Port: 21
- Username/Password: the FTP user credentials
You should land in the user's home directory with upload permissions.
Troubleshooting
- 500 OOPS: vsftpd: refusing to run with writable root inside chroot: add
allow_writeable_chroot=YESto the config. - Connection refused on passive ports: ensure UFW/iptables rules allow the passive port range.