Check this Out!Visit our social network pages for recent updates!

Install VSFTPD with SSL/TLS on Ubuntu 17. 04 / 17.10

This post shows students and new users how to install VSFTPD with SSL/TLS support on Ubuntu 17.04 / 17.10. VSFTPD is an opensource program that uses File Transfer Protocol (FTP) to enable file uploads and downloads.

There are other opensource programs that use FTP protocol to transfer files on Linux systems, but VSFTPD is probably the most popular and easier to configure.  VSFTPD daemon listens continuously for FTP requests from FTP clients. If the request is valid and the user is authorized, access will be granted.

Access can be managed two ways… anonymous and authenticated.

 In anonymous mode, remote users / clients can access the server anonymously. Only valid users are allow to authenticate and access restricted areas. To install VSFTPD follow the steps below:

Step 1: Install VSFTPD

To install VSFTPD on Ubuntu run the commands below

sudo apt-get install vsftpd

After installing, the commands below can be used to stop, start and enable VSFTPD service to always startup when the server boots

sudo systemctl stop vsftpd.service
sudo systemctl start vsftpd.service
sudo systemctl enable vsftpd.service

To configure VSFTPD, run the command below to open vsftpd.conf file. This is the main configuration file for the program

sudo nano /etc/vsftpd.conf

Then, make the following highlighted changes below and save the file.

Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone? vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
listen_ipv6=YES
#
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
# If enabled, vsftpd will display directory listings with the time
# in your local time zone. The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
## By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.

After editing the file, save it.

After making the changes above, restart VSFTPD service by running the commands below

sudo systemctl restart vsftpd.service

Step 2: Configuring VSFTPD

If you want to block users, open the file below and add the user account and save the file.

sudo nano /etc/ftpusers

All the accounts in the file above will be denied FTP access.

To enable SSL/TLS encryption, follow the steps below.

First, run the commands below to create a folder to store the certificates

sudo mkdir -p /etc/ssl/certs

Then run the commands below to create a new one year self-signed SSL/TLS certificate and store in the folder above.

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

Then you run the commands above, you’ll be asked series of questions to incorporate into the certificate. Use the guide below to answer

You are about to be asked to enter information that will be incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:MN
Locality Name (eg, city) []:BP
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:none
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:

After generating the certificate, open /etc/vsftpd.conf file and add the lines below and save.

rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/certs/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH

Restart the server and you’re done.

To test, open an FTP client and connect, you should be prompted allow to confirm the certificate presented to the client.

Enjoy!

You may also like the post below:

Installing Webmin on Ubuntu 17.04 / 17.10

Leave a Reply