How to Set Up a Secure FTP Server with Pure-FTPd on Ubuntu

Pure-FTPd is a free open-source FTP server designed with security in mind. In this tutorial, we are going to take a look at how to set up a secure FTP server on Ubuntu server with Pure-FTPd and how to enforce TLS encryption.

Note: This tutorial works on all current Ubuntu releases, including Ubuntu 20.04, 19.10, 18.04 and 16.04.

Pure-FTPd Features:

  • It supports SSL/TLS encryption and thus passwords and commands can be protected.
  • It can run on most Unix-like systems: Linux, BSDs, Solaris, Darwin, HPUX, AIX, and even iPhone.
  • Available in 21 languages.
  • Allows you to monitor active sessions.
  • Supports a virtual quota system.
  • And much more

For a complete list of features, please go to Pure-FTPd official website.

Step 1: Install Pure-FTPd on Ubuntu Server

It’s in the software repository, so issue the following command to install the FTP server.

sudo apt install pure-ftpd

Once installed, Pure-FTPd will be automatically started, as can be seen with this command:

systemctl status pure-ftpd

Output:

 pure-ftpd.service
   Loaded: loaded (/etc/init.d/pure-ftpd; bad; vendor preset: enabled)
   Active: active (running) since Mon 2016-12-12 21:51:46 EST; 23s ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/pure-ftpd.service
           └─3435 pure-ftpd (SERVER)

preset: enabled indicates it will auto-start at system boot time. If it’s not running, star it with:

sudo systemctl start pure-ftpd

And it’s listening on TCP port 21, which is the control port, as can be seen with

sudo netstat -lnpt | grep pure-ftpd

pure-ftpd secure ftp server

Anonymous access is disabled by default. From now on you can use your system account to login, but plain text FTP is insecure and strongly discouraged. To have a secure FTP server, we need to encrypt communication with TLS.

Step 2: Enforce TLS Encryption

To enable both plain-text and TLS encryption, run the following command, which create the /etc/pure-ftpd/conf/TLS file and put number 1 into the file.

echo 1 | sudo tee /etc/pure-ftpd/conf/TLS

But it’s recommended to disable plain-text and use TLS encryption only, so put the number 2 to the file instead.

echo 2 | sudo tee /etc/pure-ftpd/conf/TLS

Now we enforced TLS, we need to obtain a valid TLS certificate. A self-signed certificate is not recommended because users will see warning like the screenshot below.

nautilus ftps

Step 3: Obtain a Trusted TLS Certificate from Let’s Encrypt

Run the following command to install Let’s Encrypt client (certbot) from the default Ubuntu repository.

sudo apt install certbot

I recommend using the standalone or webroot plugin to obtain TLS certificate for Pure-FTPd.

Standalone Plugin

If there’s no web server running on your Ubuntu server, you can use the standalone plugin. Run the following command. Don’t forget to set DNS A record for your sub-domain.

sudo certbot certonly --standalone --preferred-challenges http --agree-tos --email you@example.com -d ftp.example.com

Where:

  • certonly: Obtain a certificate but don’t install it.
  • --standalone: Use the standalone plugin to obtain a certificate
  • --preferred-challenges http: Perform http-01 challenge to validate our domain, which will use port 80.
  • --agree-tos: Agree to Let’s Encrypt terms of service.
  • --email: Email address is used for account registration and recovery.
  • -d: Specify your domain name.

As you can see from the following screenshot, I successfully obtained the certificate.

pure-ftpd ubuntu server enforce TLS encryption

Using webroot Plugin

If your Ubuntu server has a web server, then it’s a good idea to use the webroot plugin to obtain a certificate because the webroot plugin works with pretty much every web server and we don’t need to install the certificate in the web server.

First, you need to create a virtual host for ftp.example.com.

Apache

If you are using Apache, then

sudo nano /etc/apache2/sites-available/ftp.example.com.conf

And paste the following lines into the file.

<VirtualHost *:80>        
        ServerName ftp.example.com

        DocumentRoot /var/www/Pure-FTPd
</VirtualHost>

Save and close the file. Then create the web root directory.

sudo mkdir /var/www/Pure-FTPd

Set www-data (Apache user) as the owner of the web root.

sudo chown www-data:www-data /var/www/Pure-FTPd -R

Enable this virtual host.

sudo a2ensite ftp.example.com

Reload Apache for the changes to take effect.

sudo systemctl reload apache2

Once virtual host is created and enabled, run the following command to obtain Let’s Encrypt certificate using webroot plugin.

sudo certbot certonly --webroot --agree-tos --email you@exmaple.com -d ftp.example.com -w /var/www/Pure-FTPd

Nginx

If you are using Nginx, then

sudo nano /etc/nginx/conf.d/ftp.example.com.conf

Paste the following lines into the file.

server {
      listen 80;
      listen [::]:80;
      server_name ftp.example.com;

      root /var/www/Pure-FTPd/;

      location ~ /.well-known/acme-challenge {
         allow all;
      }
}

Save and close the file. Then create the web root directory.

sudo mkdir -p /var/www/Pure-FTPd

Set www-data (Nginx user) as the owner of the web root.

sudo chown www-data:www-data /var/www/Pure-FTPd -R

Reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Once virtual host is created and enabled, run the following command to obtain Let’s Encrypt certificate using webroot plugin.

sudo certbot certonly --webroot --agree-tos --email you@exmaple.com -d ftp.example.com -w /var/www/Pure-FTPd

Step 4: Install the Certificate

Pure-FTPd requires that the certificate and private key are combined into one file named pure-ftpd.pem and stored under /etc/ssl/private/ directory.

Change to the /etc/letsencrypt/live/ftp.example.com/ directory.

cd /etc/letsencrypt/live/ftp.example.com/

You can use cat command to combine two files into one like below.

sudo cat fullchain.pem privkey.pem | sudo tee /etc/ssl/private/pure-ftpd.pem

Make sure only the root user can read the file.

sudo chmod 600 /etc/ssl/private/pure-ftpd.pem

we need to generate the Diffie-Hellman parameter with:

sudo openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 4096

If your mail server has a single CPU core, then this is going to take a long time (about 10 minutes).

Restart Pure-FTPd.

sudo systemctl restart pure-ftpd

Check the status to see if it’s running.

systemctl status pure-ftpd

Now you can connect to your FTP server over TLS.

If you use Nautilus file manager to connect to FTP server via plain text ftp:// protocol

nautilus connect to ftp server

The connection will be refused.

cleartext sessions are not accepted on this server

Instead of ftp://, you must use ftps://.

Please note that Filezilla doesn’t trust any certificate (self-signed or CA-signed) by default. Users must choose to trust certificate for themselves.

filezilla unknown certificate

FileZilla Unknown Certificate Warning

Wrapping Up

I hope this tutorial helped you set up a secure FTP server with Pure-FTPd on Ubuntu. As always, if you found this post useful, then subscribe to our free newsletter. You can also follow us on Twitter or like our Facebook page.

Rate this tutorial
[Total: 4 Average: 5]

5 Responses to “How to Set Up a Secure FTP Server with Pure-FTPd on Ubuntu

  • LinuxGuy
    2 years ago

    What port should I open in firewall?

    • You should open port 20 and 21. For example, use UFW.

      sudo ufw allow 20/tcp
      sudo ufw allow 21/tcp
    • ports 20 and 21 are used for when FTP is in the active mode. some clients behind firewalls out of their own reach however will find they need passive mode, and then you need to open just port 21/tcp and a range of ports on the high end, to get ftp working. but you would need to tell pure-ftpd about it like so:

       # echo "55521 55522" > /etc/pure-ftpd/conf/PassivePortRange

      This writes a port range 55521-55522 into the file PassivePortRange, in our example pure-ftpd would have two ports to connect two times to (a) client(s) at max. If you want to have more connections, just add some more ports to the range. like write “55521 55530” if you want to have 10 ports, which pure-ftpd will then be able to choose randomly for sessions.

      Hope that helps someone.
      h08

      then restart the service

      # servicepure-ftpd-mysql restart

      make sure you open the ports you gave pure-ftpd for passive connections in your firewall, like Xiao Guo An explained above.

  • Wesley Santos
    12 months ago

    Hi Xiao, do you have a tutorial for setting up FTP server on Ubuntu 18.04 or Debian 10?

    best regards,
    Wesley Santos

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.


The maximum upload file size: 2 MB.
You can upload: image.