How To Install an FTP server (vsftpd) on Ubuntu 20.04/20.10

How To Install an FTP server

In this tutorial, we will learn how to install and configure an FTP server on Ubuntu 20.04 which we will use to share the files from the local system to the server.

FTP stands for File Transfer Protocol. FTP is a network protocol used to transfer files locally to a server. The most widely popular open-source FTP servers are vsftpd, ProFTPD, and PureFTPD. In this tutorial, we will install vsftpd (Very Secure Ftp Daemon).

FTP stands for File Transfer Protocol. FTP is a network protocol used to transfer files local to a server. The most widely popular open-source FTP server which are vsftpdProFTPD and PureFTPD. In this tutorial we will install vsftpd (Very Secure Ftp Daemon).

Installing vsftpd on Ubuntu 20.04

We can easily install vsftpd package with the Ubuntu repository. First, we need to update the Ubuntu repositories.

Read Also: How to Change Remote URL in Git?

sudo apt update -y

To install vsftpd, run the following command.

sudo apt install vsftpd -y

Start the vsftpd service

sudo systemctl start vsftpd

Manage the Vsftpd  service

We can manage the vsftpd service with the following command.

Enable the vsftpd service with the below command.

sudo systemctl enable vsftpd

Use the below command to start the vsftpd service.

sudo systemctl start vsftpd

To check the vsftpd service status.

sudo systemctl status vsftpd

Run the below command to stop the vsftpd service.

sudo systemctl stop vsftpd

To disable the vsftpd service.

sudo systemctl disable vsftpd

And Lastly, restart the vsftpd service.

sudo systemctl restart vsftpd

Configuring vsftpd

The vsftpd server configuration is present in the /etc/vsftpd.conf file. We have to make some changes in the configuration to set up the proper vsftpd.

Edit the configuration file /etc/vsftpd.conf in your favorite editor.

sudo vim /etc/vsftpd.conf

Match with these configurations and make sure that the following lines are uncommented/added in the file.

anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
local_umask=022
anon_umask=233
anon_upload_enable=YES
anon_mkdir_write_enable=YES
file_open_mode=0777
allow_writeable_chroot=YES
pasv_min_port=60000
pasv_max_port=60003

Restart the vsftpd service.

sudo service vsftpd restart

Create the FTP User

Create a local user which we will be used for FTP and set the home directory to /var/www/domain/public_html.

Add FTP user

sudo adduser ftpuser

Change the Home directory of the user.

sudo usermod -d /var/www/domain/public_html -m ftpuser

Add the ftpuser to the www-data group

sudo usermod -a -G www-data ftpuser

Set the correct permissions on the directory /var/www/domain/public_html

sudo chgrp -R www-data /var/www/domain/public_html
sudo chmod -R g+w /var/www/domain/public_html

Set the GID on the directory recursively, so that all the files and directories which are created under the /var/www/domain/public_html are owned by the www-data group.

sudo find /var/www/domain/public_html -type d -exec chmod 2775 {} \;

Allow read and write permission on the files and directories inside the
/var/www/domain/public_html for owner and group.

sudo find /var/www/domain/public_html -type f -exec chmod ug+rw {} \;

Disable SSH Login For FTP User

We have to disable the ssh access for the user which we have created earlier. Run the following command to disable the ssh access.

echo 'DenyUsers ftpuser' >> /etc/ssh/sshd_config

Restart the SSH service

systemctl restart sshd

Configuring the Firewall

If you are running the UFW firewall, then you need to allow the FTP ports.

Note:- If the UFW firewall is inactive, and you want to activate the UFW firewall, then make sure that you have allowed the necessary ports like SSH port,

ufw allow 22
ufw allow 21
ufw allow 60000
ufw allow 60001
ufw allow 60002
ufw allow 60003
ufw allow 80
ufw allow 443

Active the UFW Firewall

ufw enable

Restart the UFW firewall service.

systemctl restart ufw

Conclusion

In this Install FTP server on Ubuntu tutorial, we have learned about what is FTP and how to install the FTP server on Ubuntu 20.04/20.10 with a UFW firewall.

If you guys have any queries related to this tutorial, then let me know in the comments section.