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.
In the console window (CLI), type the following commands and confirm by pressing Enter:
sudo apt install vsftpdsudo apt install ufw
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 sshsudo ufw allow 20,21,990/tcpsudo ufw allow 40000:50000/tcp
We then check the status of our firewall in the console window (CLI) with the command:
sudo ufw status
If the status of our firewall is similar to the screenshot above in the console (CLI) window, run the following command:
sudo ufw enable
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.
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
After the backup, we delete the original file with the command:
sudo rm -rf /etc/vsftpd.conf
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=YESlisten_ipv6=NOconnect_from_port_20=YESanonymous_enable=NOlocal_enable=YESwrite_enable=YESchroot_local_user=YESallow_writeable_chroot=YESsecure_chroot_dir=/var/run/vsftpd/emptypam_service_name=vsftpdpasv_enable=YESpasv_min_port=40000pasv_max_port=50000user_sub_token=$USERuserlist_enable=YESuserlist_file=/etc/vsftpd.userlistuserlist_deny=NO
Once the above lines have been added to the file, save the changes with ctrl+s and then exit the editor with ctrl+x.
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
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.