Image

Knowledge base → Installing and configuring vsftpd FTP server on Ubuntu 20.04

[Virtual servers]
Date of publication: 06.06.2023

To transfer data to the server, work with files and folders, you need to install an FTP server. We chose Ubuntu 20.04 as the server, vsftpd as the service. This FTP server differs from the popular proftpd in its simplicity and quick setup. Any client can be used: filezilla, total commander or mc.

We make all settings from the root user, if you are using a regular user, add sudo before the command.


1. Install the service

apt update
apt install vsftpd
systemctl start vsftpd
systemctl enable vsftpd


2. Let's set it up

Let's make a copy of the original settings:

cp /etc/vsftpd.conf  /etc/vsftpd.conf_default

Add a user and specify a password for it:

useradd -m testuser
passwd testuser

Set up a firewall, in our case iptables:

iptables -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
/sbin/iptables-save > /etc/iptables/rules.v4

In most cases, the user needs write permissions, let's allow this in the server settings:

nano /etc/vsftpd.conf

write_enable=YES

Save the settings file Ctrl +O and Enter, Ctrl + X to exit the editor. Let's restart the service:

systemctl restart vsftpd.service


The basic setup is done, but it is often necessary to set up ftp access for a specific directory, such as a domain (website) folder. To do this, we need to change the user's default directory, add the user to the www-data group, and allow folders and files to be writable by the group. By default, the entry is only for the user.

usermod -d /var/www/ testuser
usermod -a -G www-data testuser
find /var/www -type d -exec chmod 775 {} \;
find /var/www -type f -exec chmod 664 {} \;


Done, now our user can work with files and folders for the specified path. If you have multiple sites, you can add an ftp user for each. By default, the user has access only to the specified folder, including subfolders, and cannot go higher than the one specified by us.





No Comments Yet