Ubuntu

Ubuntu FTP 22.04 Server Configuration

The File Transfer Protocol (FTP) is a standard protocol for communicating and transferring files between a server and a client. FTP utilizes a client-server architecture. We will cover the steps to configure FTP on Ubuntu 22.04.

Configuring FTP on Ubuntu 22.04

FTP is available on Ubuntu, but you need an FTP daemon that will offer a secure tunnel to encrypt the data flow in the FTP server. VSFTPD (very secure FTP daemon) is a reliable FTP server for the Linux system. We will use it to configure the FTP server on Ubuntu 22.04.

Start by updating the Ubuntu repositories.

$ sudo apt update

 

To install the VSFTPD, use the following command. Add the -y to skip any prompts.

$ sudo apt install vsftpd -y

 

VSFTPD automatically gets enabled after installation. Verify its status to check if it’s running.

$ sudo systemctl status vsftpd

 
If it is not active, use the start option to change its status to active.


With FTP, you need a user to connect to the FTP server once configured. Create your user and add their details including the password. For this tutorial, our user is linuxhintftp.

$ sudo adduser <username>

 

Still, create a directory for the created user and grant the user the required permissions and ownership. Run the following commands and replace the username and the directory to match your case. Our FTP directory for this case is ftp1:

$ sudo mkdir -p /home/linuxhintftp/ftp1
$ sudo chmod -R 750 /home/linuxhintftp/ftp1
$ sudo chown linuxhintftp: /home/linuxhintftp/ftp1

 

The newly created user must be added to the /etc/vsftpd.user_list to allow the user access to the configured VSFTPD server.

$ sudo bash -cecho linuxhintftp >> /etc/vsftpd.user_list’

 

At this point, the user is correctly configured. The next step is configuring the VSFTPD server by modifying its configuration file. Use your editor to open the /etc/vsftpd.conf file.

$ sudo nano /etc/vsftpd.conf

 
There are different lines in the configuration file that you should edit. First, ensure that the option for the anonymous user is disabled. Enable the local_enable and the write_enable options to allow the user to work with the files such as uploading, downloading, etc.

Edit your configuration file to match the image below.


Furthermore, enable the access to the user home directory by un-commenting the chroot_user=YES option. You also must specify the port ranges for the passive mode for the VSFTPD. We set it to 10000 and 11000 for this case.

Use the following image to edit your configuration file to add the displayed lines. Lastly, save and exit the configuration file.


Restart the VSFTPD server to accommodate the changes we made.

$ sudo systemctl restart vsftpd

 

To test the FTP server, type the ftp command followed by the IP address of your Ubuntu 22.04.

If the configuration is successful, enter your username and password for the user that we created. Note that you must have the allow_writeable_chroot=YES un-commented on the VSFTPD configuration file. Otherwise, you will get a login failure, as in the image below.

$ ftp <your-ip>

 

Quickly fix this by adding the allow_writeable_chroot=YES and save the file.


Restart the VSFTPD and try connecting to the FTP server again. It will work this time.


The last step is to allow the FTP traffic and FTP data via ports 20 and 21, respectively. Also, enable the passive connection to the passive mode for the port ranges that you defined in your configuration file.

For that, you create a firewall like the one in the following image and replace the port ranges to match yours:

$ sudo ufw allow from any to any port 20,21,10000:11000 proto tcp

 

Verify that the firewall rules are created successfully by checking the firewall status.

$ sudo ufw status

 

That’s how to configure the FTP server on Ubuntu 22.04.

Conclusion

With the VSFTPD, you can securely configure your FTP server on Ubuntu 22.04. We’ve gone through the detailed steps that you should follow, from installing the VSFTPD, to configuring it, to testing the FTP server. You can comfortably follow along and configure your FTP server.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.