
This guide explains how to set up vsftpd (Very Secure File Transfer Protocol Daemon), which allows users to upload files via FTPS (also known as FTP-SSL and FTP Secure). This guide is written for the Vultr One-Click LAMP server on Ubuntu 18.04 using a free Let's Encrypt SSL/TLS certificate. With minor modifications, you can adapt this guide to any server distribution with vsftpd in their repository, and use Apache or Nginx.
Update the local package index.
Install the vsftpd daemon.
UFW, or Uncomplicated Firewall, is installed by default on Ubuntu systems. If it is enabled, open the necessary ports: 20 and 21 for FTP, 40000-50000 for passive FTP, and 990 for TLS.
If the firewall is enabled, the rules should look like this:
Create a dedicated user to log in to FTP, and use a strong password.
For increased security, block this user from logging in via SSH.
Add the following line to the bottom of the file.
Save and exit the file.
Restart SSH to enforce the changes.
Set the home directory to the folder above the default webroot. vsftpd restricts the user's access to their specific home directory using chroot jails and requires that the directory be not writable by the user. For Apache, the default webroot is /var/www/html.
Set the ownership of the webroot to the FTP user.
Verify the permissions of the directory.
Open the configuration file for vsftpd.
Ensure anonymous FTP access is disabled and local users can log in.
Uncomment these lines to allow the FTP user to upload files, and prevent them from accessing any files outside of their home directory.
Add force_dot_files=YES in the file to show hidden files such as .htaccess.
Set the range of ports available for passive FTP. Make sure these values match the firewall settings added in Step 2.
Restrict FTP access to users specified in /etc/vsftpd.userlist.
Save and exit the file.
Edit /etc/vsftpd.userlist.
Add the ftpaccess user to the file.
Save and exit the file.
Restart vsftpd to load the changes.
You should be able to log in with any FTP client as the ftpaccess user, but the server is un-encrypted. Continue with Step 5 to set up encryption.
By default, FTP does not encrypt credentials or data in transit. Follow these steps to use the server's Let's Encrypt certificate to secure the connection. You can follow our guide to obtain a Let's Encrypt certificate for a LAMP server if you need to install one first.
Edit the vsftpd configuration file.
Find the two lines beginning with rsa_ and comment them out by adding # at the beginning.
Add the following lines. Adjust the pathname to match the location of the server's certificate files.
Add this line to allow clients that can't connect over TLS to use SSL.
Deny anonymous connections and force a secure connection by adding the following lines.
Specify which protocols to use. For security, allow TLS and block older versions of SSL.
Add the following to use strong encryption methods.
Do not require the reuse of SSL sessions. Setting this to yes may interfere with many FTP clients.
Add the ports used for passive FTP.
Save and exit the file.
Restart the server.
A good verification test is to attempt a connection with the default command-line ftp client, which will fail because it doesn't support encryption.
Connect using command-line ftp from a different machine.
Enter the username when prompted and ensure access is denied.
With a client that supports FTPS, such as FileZilla or Cyberduck, connect to the server and check the connection log. You should find entries similar to this:
You can now securely connect to your server via FTPS and upload files to your website directory.
0 Comments
Be the first to comment and share your perspective with the community.