Skip to main content

How to install ftp server on ubuntu server 22.04


This guide will help you install and configure ftp server with vsftpd on ubuntu server. Follow the steps outline bellow to install vsftpd utility on ubuntu server 22.04.

Step 1: Update System Package Repository

sudo apt update

Wait until the update process completes.

Step 2: Install vsftpd  on Ubuntu Server

vsftpd is an open source FTP utility commonly used in ubuntu due to its simplicity. Install vsftpd by running the command bellow :

sudo apt install vsftpd -y

Step 3: Launch vsftpd

To launch the service and enable it to automatically start at boot, run the following commands :

systemctl start vsftpd
systemctl enable vsftpd

Step 4: Backup Configuration Files

Before making any changes, backup your configuration files. Create a backup copy of the default configuration using the cp command :

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

Step 5: Create FTP User

For this tutorial, we will create a dedicated FTP user. Skip  this step if you intend to give FTP access to an existing user.

Use the syntax bellow to create a new user and set the password :

sudo useradd -m [username]
sudo passwd [username]

Step 6: Configure firewall to allow FTP traffic

Run the following command to open port 20 and 21 to allow FTP traffic using ufw :

sudo ufw allow 20/tcp
sudo ufw allow 21/tcp

If you use iptables, you can run the following commands :

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

Step 7 : Connect to the FTP server

Connect to the FTP server using the following syntax :

ftp [IP Address FTP server]
ftp 192.168.1.58

or 

ftp ftpuser@192.168.1.58

Then you will asked to input the password of FTP user

Configuring vsftpd Server

Configuring the server is crucial as it allows you to customize settings to optimize performance, enable specific features, and tailor the server to meet your needs. Follow the section bellow for some basic configuration.

Change Default Directory

The FTP server uses the /srv/ftp directory as default directory. You can create a new directory and set it as the FTP user home directory. Changing and restricting FTP to a specific directory improves overall security.

Follow the steps bellow :

1. Use this syntax to create new directory

sudo mkdir /srv/ftp/[new_location]

Replace the new_location with directory  you want to create.

2. Use the following syntax to  change the default directory where ftp user will be placed upon login :

sudo usermod -d /srv/ftp/[new_location] ftp

3. Restart the vsftpd services to apply the changes.

systemctl restart vsftpd.service

Now, you can put any files you want to share via ftp into /srv/ftp directory ( if you left it as default) or the /srv/ftp/[new_location] directory (if you changed it).

Authenticate FTP Users

If you want to let authenticated user upload files, edit the vsftpd.conf file as shown the steps bellow :

1. Open vsftpd.conf file using nano or another text editor

sudo nano /etc/vsftpd.conf

2. Find the entry labeled write_enable=YES  and uncomment it ( remove # in front of the line )







3. Save and exit the file, and restart ftp service by running the following command :

sudo systemctl restart vsftpd.service

Configuring this setting allows the user make changes inside their home directory.

Securing FTP

Numerous exploits take advantage of unsecured ftp server. There are several configuration option in vsftpd.conf that help secure your FTP server. thus preventing unauthorized access, potential data breaches and system vulnerabilities.

Limit User Access

One method of securing vsftpd is to limits users to their home directory. follow the step bellow :

1. Open vsftpd.conf file in text editor

sudo nano /etc/vsftpd.conf

2. Uncomment the following line by removing the hash (#) sign :

chroot_local_user=YES




Save the file, apply the changes and exit from the text editor.

Create a User List File

The user list file enables vsftpd to deny or allow access to the listed users. The listed users will have full access to anywhere on the server. If a user is not listed, they are restricted to their specified home directory. Follow the steps below:

1. Open the /etc/vsftpd.chroot_list file in a text editor and add one user per line to create the list file.

2. Edit the vsftpd.conf file and uncomment (remove the #) the following lines:

chroot_local_user=YES

chroot_list_file=/etc/vsftpd.chroot_list

The following image illustrates the edits:






3. Still on vsftpd.conf file, another rule should be enable

anonymous_enable=NO
local_enable=YES
local_umask=022
allow_writeable_chroot=YES








4. Save the configuration and exit from vsftpd.conf file. Then restart the vsftpd service:

sudo systemctl restart vsftpd.service

Comments