How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (2023)


FTP, short for File Transfer Protocol, is a network protocol that was once widely used for moving files between a client and server. It has since been replaced by faster, more secure, and more convenient ways of delivering files. Many casual Internet users expect to download directly from their web browser with https, and command-line users are more likely to use secure protocols such as the scp or sFTP.

FTP is still used to support legacy applications and workflows with very specific needs. If you have a choice of what protocol to use, consider exploring the more modern options. When you do need FTP, however, vsftpd is an excellent choice. Optimized for security, performance, and stability, vsftpd offers strong protection against many security problems found in other FTP servers and is the default for many Linux distributions.

In this tutorial, we’ll show you how to configure vsftpd to allow a user to upload files to his or her home directory using FTP with login credentials secured by SSL/TLS.


To follow along with this tutorial you will need:

  • An Ubuntu 16.04 server with a non-root user with sudo privileges: You can learn more about how to set up a user with these privileges in our Initial Server Setup with Ubuntu 16.04 guide.

Once you have an Ubuntu server in place, you’re ready to begin.

Step 1 — Installing vsftpd

We’ll start by updating our package list and installing the vsftpd daemon:

  1. sudo apt-get update
  2. sudo apt-get install vsftpd

When the installation is complete, we’ll copy the configuration file so we can start with a blank configuration, saving the original as a backup.

  1. sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig

With a backup of the configuration in place, we’re ready to configure the firewall.

Step 2 — Opening the Firewall

We’ll check the firewall status to see if it’s enabled. If so, we’ll ensure that FTP traffic is permitted so you won’t run into firewall rules blocking you when it comes time to test.

  1. sudo ufw status

In this case, only SSH is allowed through:


Status: activeTo Action From-- ------ ----OpenSSH ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)

You may have other rules in place or no firewall rules at all. Since only ssh traffic is permitted in this case, we’ll need to add rules for FTP traffic.

We’ll need to open ports 20 and 21 for FTP, port 990 for later when we enable TLS, and ports 40000-50000 for the range of passive ports we plan to set in the configuration file:

  1. sudo ufw allow 20/tcp
  2. sudo ufw allow 21/tcp
  3. sudo ufw allow 990/tcp
  4. sudo ufw allow 40000:50000/tcp
  5. sudo ufw status

Now our firewall rules looks like:


Status: activeTo Action From-- ------ ----OpenSSH ALLOW Anywhere990/tcp ALLOW Anywhere20/tcp ALLOW Anywhere21/tcp ALLOW Anywhere40000:50000/tcp ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)20/tcp (v6) ALLOW Anywhere (v6)21/tcp (v6) ALLOW Anywhere (v6)990/tcp (v6) ALLOW Anywhere (v6)40000:50000/tcp (v6) ALLOW Anywhere (v6)

With vsftpd installed and the necessary ports open, we’re ready to proceed to the next step.

Step 3 — Preparing the User Directory

For this tutorial, we’re going to create a user, but you may already have a user in need of FTP access. We’ll take care to preserve an existing user’s access to their data in the instructions that follow. Even so, we recommend you start with a new user until you’ve configured and tested your setup.

First, we’ll add a test user:

  1. sudo adduser sammy

Assign a password when prompted and feel free to press “ENTER” through the other prompts.

FTP is generally more secure when users are restricted to a specific directory.vsftpd accomplishes this with chroot jails. When chroot is enabled for local users, they are restricted to their home directory by default. However, because of the way vsftpd secures the directory, it must not be writable by the user. This is fine for a new user who should only connect via FTP, but an existing user may need to write to their home folder if they also shell access.

In this example, rather than removing write privileges from the home directory, we’re will create an ftp directory to serve as the chroot and a writable files directory to hold the actual files.

Create the ftp folder, set its ownership, and be sure to remove write permissions with the following commands:

  1. sudo mkdir /home/sammy/ftp
  2. sudo chown nobody:nogroup /home/sammy/ftp
  3. sudo chmod a-w /home/sammy/ftp

Let’s verify the permissions:

  1. sudo ls -la /home/sammy/ftp


total 84 dr-xr-xr-x 2 nobody nogroup 4096 Aug 24 21:29 .4 drwxr-xr-x 3 sammy sammy 4096 Aug 24 21:29 ..

Next, we’ll create the directory where files can be uploaded and assign ownership to the user:

  1. sudo mkdir /home/sammy/ftp/files
  2. sudo chown sammy:sammy /home/sammy/ftp/files

A permissions check on the files directory should return the following:

  1. sudo ls -la /home/sammy/ftp


total 12dr-xr-xr-x 3 nobody nogroup 4096 Aug 26 14:01 .drwxr-xr-x 3 sammy sammy 4096 Aug 26 13:59 ..drwxr-xr-x 2 sammy sammy 4096 Aug 26 14:01 files

Finally, we’ll add a test.txt file to use when we test later on:

  1. echo "vsftpd test file" | sudo tee /home/sammy/ftp/files/test.txt

Now that we’ve secured the ftp directory and allowed the user access to the files directory, we’ll turn our attention to configuration.

Step 4 — Configuring FTP Access

We’re planning to allow a single user with a local shell account to connect with FTP. The two key settings for this are already set in vsftpd.conf. Start by opening the config file to verify that the settings in your configuration match those below:

  1. sudo nano /etc/vsftpd.conf


. . .# Allow anonymous FTP? (Disabled by default).anonymous_enable=NO## Uncomment this to allow local users to log in.local_enable=YES. . .

Next we’ll need to change some values in the file. In order to allow the user to upload files, we’ll uncomment the write_enable setting so that we have:


. . .write_enable=YES. . .

We’ll also uncomment the chroot to prevent the FTP-connected user from accessing any files or commands outside the directory tree.


. . .chroot_local_user=YES. . .

We’ll add a user_sub_token in order to insert the username in our local_root directory path so our configuration will work for this user and any future users that might be added.



We’ll limit the range of ports that can be used for passive FTP to make sure enough connections are available:



Note: We pre-opened the ports that we set here for the passive port range. If you change the values, be sure to update your firewall settings.

Since we’re only planning to allow FTP access on a case-by-case basis, we’ll set up the configuration so that access is given to a user only when they are explicitly added to a list rather than by default:



userlist_deny toggles the logic. When it is set to “YES”, users on the list are denied FTP access. When it is set to “NO”, only users on the list are allowed access. When you’re done making the change, save and exit the file.

Finally, we’ll create and add our user to the file. We’ll use the -a flag to append to file:

  1. echo "sammy" | sudo tee -a /etc/vsftpd.userlist

Double-check that it was added as you expected:

cat /etc/vsftpd.userlist



Restart the daemon to load the configuration changes:

  1. sudo systemctl restart vsftpd

Now we’re ready for testing.

Step 5 — Testing FTP Access

We’ve configured the server to allow only the user sammy to connect via FTP. Let’s make sure that’s the case.

Anonymous users should fail to connect: We disabled anonymous access. Here we’ll test that by trying to connect anonymously. If we’ve done it properly, anonymous users should be denied permission:

  1. ftp -p


Connected to (vsFTPd 3.0.3)Name ( anonymous530 Permission denied.ftp: Login failed.ftp>

Close the connection:

  1. bye

Users other than sammy should fail to connect: Next, we’ll try connecting as our sudo user. They, too, should be denied access, and it should happen before they’re allowed to enter their password.

  1. ftp -p


Connected to (vsFTPd 3.0.3)Name ( sudo_user530 Permission denied.ftp: Login failed.ftp>

Close the connection:

  1. bye

sammy should be able to connect, as well as read and write files: Here, we’ll make sure that our designated user _can_connect:

  1. ftp -p


Connected to (vsFTPd 3.0.3)Name ( sammy331 Please specify the password.Password: your_user's_password230 Login successful.Remote system type is UNIX.Using binary mode to transfer files.ftp>

We’ll change into the files directory, then use the get command to transfer the test file we created earlier to our local machine:

  1. cd files
  2. get test.txt


227 Entering Passive Mode (203,0,113,0,169,12).150 Opening BINARY mode data connection for test.txt (16 bytes).226 Transfer complete.16 bytes received in 0.0101 seconds (1588 bytes/s)ftp>

We’ll turn right back around and try to upload the file with a new name to test write permissions:

  1. put test.txt upload.txt


227 Entering Passive Mode (203,0,113,0,164,71).150 Ok to send data.226 Transfer complete.16 bytes sent in 0.000894 seconds (17897 bytes/s)

Close the connection:

  1. bye

Now that we’ve tested our configuration, we’ll take steps to further secure our server.

Step 6 — Securing Transactions

Since FTP does not encrypt any data in transit, including user credentials, we’ll enable TTL/SSL to provide that encryption. The first step is to create the SSL certificates for use with vsftpd.

We’ll use openssl to create a new certificate and use the -days flag to make it valid for one year. In the same command, we’ll add a private 2048-bit RSA key. Then by setting both the -keyout and -out flags to the same value, the private key and the certificate will be located in the same file.

We’ll do this with the following command:

  1. sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem

You’ll be prompted to provide address information for your certificate. Substitute your own information for the questions below:


Generating a 2048 bit RSA private key............................................................................+++...........+++writing new private key to '/etc/ssl/private/vsftpd.pem'-----You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:USState or Province Name (full name) [Some-State]:NYLocality Name (eg, city) []:New York CityOrganization Name (eg, company) [Internet Widgits Pty Ltd]:DigitalOceanOrganizational Unit Name (eg, section) []:Common Name (e.g. server FQDN or YOUR name) []: your_IP_addressEmail Address []:

For more detailed information about the certificate flags, see OpenSSL Essentials: Working with SSL Certificates, Private Keys and CSRs

Once you’ve created the certificates, open the vsftpd configuration file again:

  1. sudo nano /etc/vsftpd.conf

Toward the bottom of the file, you should two lines that begin with rsa_. Comment them out so they look like:


# rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem# rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

Below them, add the following lines which point to the certificate and private key we just created:



After that, we will force the use of SSL, which will prevent clients that can’t deal with TLS from connecting. This is necessary in order to ensure all traffic is encrypted but may force your FTP user to change clients. Change ssl_enable to YES:



After that, add the following lines to explicitly deny anonymous connections over SSL and to require SSL for both data transfer and logins:



After this we’ll configure the server to use TLS, the preferred successor to SSL by adding the following lines:



Finally, we will add two more options. First, we will not require SSL reuse because it can break many FTP clients. We will require “high” encryption cipher suites, which currently means key lengths equal to or greater than 128 bits:



When you’re done, save and close the file.

Now, we need to restart the server for the changes to take effect:

  1. sudo systemctl restart vsftpd

At this point, we will no longer be able to connect with an insecure command-line client. If we tried, we’d see something like:

  1. ftp -p
  2. Connected to
  3. 220 (vsFTPd 3.0.3)
  4. Name ( sammy
  5. 530 Non-anonymous sessions must use encryption.
  6. ftp: Login failed.
  7. 421 Service not available, remote server has closed connection
  8. ftp>

Next, we’ll verify that we can connect using a client that supports TLS.

Step 7 — Testing TLS with FileZilla

Most modern FTP clients can be configured to use TLS encryption. We will demonstrate how to connect using FileZilla because of its cross platform support. Consult the documentation for other clients.

When you first open FileZilla, find the Site Manager icon just below the word File, the left-most icon on the top row. Click it:

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (1)

A new window will open. Click the “New Site” button in the bottom right corner:

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (2)Under “My Sites” a new icon with the words “New site” will appear. You can name it now or return later and use the Rename button.

You must fill out the “Host” field with the name or IP address. Under the “Encryption” drop down menu, select “Require explicit FTP over TLS”.

For “Logon Type”, select “Ask for password”. Fill in the FTP user you created in the “User” field:

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (3)Click “Connect” at the bottom of the interface. You will be asked for the user’s password:

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (4)Click “OK” to connect. You should now be connected with your server with TLS/SSL encryption.

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (5)When you’ve accepted the certificate, double-click the files folder and drag upload.txt to the left to confirm that you’re able to download files.
How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (6)When you’ve done that, right-click on the local copy, rename it to upload-tls.txt` and drag it back to the server to confirm that you can upload files.

How To Set Up vsftpd for a User's Directory on Ubuntu 16.04 | DigitalOcean (7)You’ve now confirmed that you can securely and successfully transfer files with SSL/TLS enabled.

Step 8 — Disabling Shell Access (Optional)

If you’re unable to use TLS because of client requirements, you can gain some security by disabling the FTP user’s ability to log in any other way. One relatively straightforward way to prevent it is by creating a custom shell. This will not provide any encryption, but it will limit the access of a compromised account to files accessible by FTP.

First, open a file called ftponly in the bin directory:

  1. sudo nano /bin/ftponly

We’ll add a message telling the user why they are unable to log in. Paste in the following:

#!/bin/shecho "This account is limited to FTP access only."

Change the permissions to make the file executable:

  1. sudo chmod a+x /bin/ftponly

Open the list of valid shells:

  1. sudo nano /etc/shells

At the bottom, add:


. . ./bin/ftponly

Update the user’s shell with the following command:

  1. sudo usermod sammy -s /bin/ftponly

Now try logging in as sammy:

  1. ssh sammy@

You should see something like:


This account is limited to FTP access only.Connection to closed.

This confirms that the user can no longer ssh to the server and is limited to FTP access only.


In this tutorial we covered setting up FTP for users with a local account. If you need to use an external authentication source, you might want to look into vsftpd’s support of virtual users. This offers a rich set of options through the use of PAM, the Pluggable Authentication Modules, and is a good choice if you manage users in another system such as LDAP or Kerberos.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated: 26/10/2023

Views: 5909

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.