Part 7. How to install an FTP server on Debian 11?

Introduction

This page is part of a full tutorial on how to install a web werver on a virtual machine. This seventh and last part of the tutorial explains how to install phpMyAdmin on our server. FTP stands for File Transfert Protocol. FTP is a network protocol for transmitting files between computers. FTP is mostly used for sending files on a remote computer, typicaly a web server.

The following assume a virtual machine has been created and Debian 11 is already installed with Apache, PHP and MariaDB. If not, please go to the home page and follow the guide.

The FTP server installed in the following is vsftpd (Very Secure FTP daemon). vsftp is an FTP server for Unix-like systems.

Before installing vsftp, update your system:

sudo apt update && sudo apt -y upgrade

Install vsftp

Debian 11’s default software repositories include vsftp. Let's install the vsftpd package:

sudo apt install vsftpd

Check vsftp installation

Check your vsftp version with the following command:

sudo vsftpd -versions
student@debianwebserver:~$ sudo vsftpd -versions
vsftpd: version 3.0.3

You can also check the deamon status with the following command:

sudo systemctl status vsftpd
student@debianwebserver:~$ sudo systemctl status vsftpd
● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset>
     Active: active (running) since Sun 2022-12-11 08:10:00 CET; 12min ago
    Process: 1142 ExecStartPre=/bin/mkdir -p /var/run/vsftpd/empty (code=exited>
   Main PID: 1144 (vsftpd)
      Tasks: 1 (limit: 4563)
     Memory: 748.0K
        CPU: 90ms
     CGroup: /system.slice/vsftpd.service
             └─1144 /usr/sbin/vsftpd /etc/vsftpd.conf

Dec 11 08:10:00 debianwebserver systemd[1]: Starting vsftpd FTP server...
Dec 11 08:10:00 debianwebserver systemd[1]: Started vsftpd FTP server.

Remote connection

If you followed this guide from the beginning, your ftp server it should be operational right now.

On the host computer run your ftp client (for example filezilla). Connect to your server with the following:

First remote connection to the ftp server

In trouble?

If your installation is not working, here are some troubleshooting tips.

You sometime need to add the ftp user to the system:

sudo useradd --system ftp 

If your system has a firewall installed, open the FTP ports:

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

Configuring vsftp

The vsftp configuration file is /etc/vsftpd.conf. Edit this file to set a custom configuration:

sudo nano /etc/vsftpd.conf

Set a custom welcome message by adding this line in the file:

ftpd_banner=Welcome on the virtual web server

Set the root ftp directory by adding this line:

local_root=/home/username/www/

To allow users to write files, add this line:

write_enable=YES

Users can now send files to the server. But the files don't have read/write permission. Add the following line in the vsftp configuation file to change file permissions:

local_umask=0002
file_open_mode=0777

The default behavior of the server is to hide hidden files. Since our server can have files like .htaccess which is a hidden file, we disable this option. Add the following line to show hidden files in the ftp client:

force_dot_files=YES

Save the file, and restart the ftp server:

sudo systemctl restart vsftpd

When the client connect to the server via FTP, the welcome message is displayed and the root directory has changed:

Custom vsftp configuration from the client side

The server is now ready to use!

See also


Last update : 12/11/2022