Install vsftpd
sudo apt update && sudo apt upgrade -y
sudo apt install vsftpd
Configure vsftpd
Back up the original file and edit it:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
sudo nano /etc/vsftpd.conf
Main options:
anonymous_enableallows or blocks anonymous logins. Set it toNO.local_enablelets local system users log in. Set it toYES.write_enableallows uploads and changes. Set it toYES.anon_rootis the folder for anonymous users.local_rootis the folder for local users.chroot_local_userlocks users in their home folder.
Recommended settings:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
allow_writeable_chroot=YES is needed when the user's home folder is writable. A safer layout is to make the home folder read-only and give the user a writable sub-folder (see below).
Restart the service:
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
Create an FTP user
sudo adduser ftpuser
Enter a strong password. To make a user who cannot log in by SSH, use the nologin shell, and add that shell to /etc/shells:
echo /usr/sbin/nologin | sudo tee -a /etc/shells
sudo usermod -s /usr/sbin/nologin ftpuser
Set the permissions
Make a folder for uploads:
sudo mkdir -p /home/ftpuser/files
sudo chown ftpuser:ftpuser /home/ftpuser/files
If you do not use allow_writeable_chroot, make the home folder not writable:
sudo chmod a-w /home/ftpuser
Open the firewall
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
For passive mode add to vsftpd.conf:
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100
and open that range:
sudo ufw allow 40000:40100/tcp
Restart vsftpd.
Connect
Use an FTP client such as FileZilla:
- Host: the server IP
- User:
ftpuser - Password: the user's password
- Port: 21
Warning: Plain FTP does not encrypt passwords or files. Turn on TLS in vsftpd (
ssl_enable=YES with a certificate), or use SFTP, which works through SSH with no extra server.Quick recap
- Install
vsftpd, disable anonymous logins and lock users in their home. - Open ports 20, 21 and the passive range.