Skip to main content

How to install an FTP server on a dedicated server running Debian 11?

Before installing the FTP server we should check that all currently installed software packages are up to date, to do this in the console (CLI) type:

sudo apt update

The system will then check whether the software repositories have been updated in relation to the packages currently installed. If the most recent versions of the software are currently installed on the system, you will see a message stating that no updates are possible. Otherwise, you will be informed of the number of packages available for update.

Attention

If none of the currently installed package versions are required for the use of other software (sometimes users use software that requires a specific package version), we can perform an update of the currently installed packages with the following command:

sudo apt upgrade

After executing the command, you will be informed which packages will be updated and which, if any, will be removed; to allow the update, select one of the options (yes/no):

Y/n

In our case, it will be Y or y, the entered option is then confirmed with the Enter key.

Once the currently installed packages have been correctly updated, we can move on to installing the necessary server components FTP.

1
In the console window (CLI), type the following commands and confirm by pressing Enter:
sudo apt install vsftpd
sudo apt install ufw
2
In the next step, we need to add the appropriate rules to our firewall to allow FTP and SSH connections to our dedicated server.

To do this, the following commands are executed in the console window (CLI):

sudo ufw allow ssh
sudo ufw allow 20,21,990/tcp
sudo ufw allow 40000:50000/tcp
3
We then check the status of our firewall in the console window (CLI) with the command:
sudo ufw status

4
If the status of our firewall is similar to the screenshot above in the console (CLI) window, run the following command:
sudo ufw enable

5
After executing the above command, we will be informed that the current SSH session may be disrupted during firewall activation with the new rules, we must accept this risk. The session should nevertheless not be disconnected, but if this should happen, simply establish the SSH connection to the server again.
6
In the next step, we will deal with the configuration of the FTP server. To start with, we will create a backup of the FTP server configuration file, to do this, in the console window (CLI), execute the following command:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
7
After the backup, we delete the original file with the command:
sudo rm -rf /etc/vsftpd.conf
8
Now we need to create a new configuration file for our FTP server. In the console window (CLI) we execute the following command and in the editor window we paste the lines contained below the command:
sudo nano /etc/vsftpd.conf
listen=YES
listen_ipv6=NO
connect_from_port_20=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=50000
user_sub_token=$USER
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO

9
Once the above lines have been added to the file, save the changes with ctrl+s and then exit the editor with ctrl+x.
10
After configuring the firewall and FTP server, we create a new FTP user, execute the following commands in the console window (CLI):
sudo adduser ftp_user
echo "ftp_user" | sudo tee -a /etc/vsftpd.userlist

11
The last step will be to restart our FTP server and set it to start automatically at system startup, in the console window (CLI) we execute the following commands:
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd

Once all the above steps have been completed correctly, we can move on to connecting to our FTP server. You can use FileZilla, for example, which is available on Windows and Linux. In the FileZilla window, enter the IP address of our server, the name of our FTP user, the password and click on the 'Quickconnect' button.

Done! You have installed the FTP server.