How to Install and Configure vsftpd on Ubuntu 18.04

install-ftp-server-ubuntu-vsftpd

How to Install and Configure vsftpd on Ubuntu 18.04

Posted on |

It is simple to install a basic FTP server in Ubuntu 18.04 Bionic Beaver using vsftpd. In this post, we will install the necessary programmes, create a user, configure encryption, and then test connecting to it.

Install vsftpd

  1. Enter the Following Command to Install vsftpd
sudo apt-get install vsftpd -y
  • Start the vsftpd Service and Set It to Start on Boot
sudo systemctl start vsftpd
sudo systemctl enable vsftpd

Setup Directory Structure For FTP

  1. Create a User
sudo adduser testuser1
  • Create a Directory and Set Ownership
sudo mkdir /home/testuser1/ftp
sudo chown nobody:nogroup /home/testuser1/ftp
sudo chmod a-w /home/testuser1/ftp
  • Create a Directory Where Files Can Be Uploaded and Give Ownership to the Test User
sudo mkdir /home/testuser1/ftp/test
sudo chown testuser1:testuser1 /home/testuser1/ftp/test

Configure vsftpd

  1. Backup vsftpd’s Original Config File
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
  • Open and Edit the vsftpd.conf File
sudo nano /etc/vsftpd.conf
  • Add the Following to the File:
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=11000
user_sub_token=$USER
local_root=/home/$USER/ftp
userlist_enable=YES
userlist_file=/etc/vsftpduserlist.conf
userlist_deny=NO
  • Save and Close the Config File
    vsftpd configuration has many options so you may need to make further adjustments based on your local server setup in Dataservermarket.
  • Add The testuser1 User We Created to vsftpd’s User List File
sudo nano /etc/vsftpduserlist.conf
  • Restart the vsftpd Service to Apply These Changes
sudo systemctl restart vsftpd

Setup Security with SSL/TLS

  1. Create a Security Certificate
sudo mkdir /etc/certs
 
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/certs/vsftpd.pem -out /etc/certs/vsftpd.pem
  • Open the vsftpd.conf File
sudo nano /etc/vsftpd.conf
  • Add the Following Lines to the File
rsa_cert_file=/etc/certs/vsftpd.pem
rsa_private_key_file=/etc/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
  • Save the File and Restart vsftpd.
sudo systemctl restart vsftpd

To test, configure your favorite FTP client to connect to your server and make sure to set the encryption settings in Dataservermarket when you login.

Install and Configure vsftpd on Ubuntu 18.04

You should see the FTP server contents upon login.

Install and Configure vsftpd on Ubuntu 18.04

How to Install FTP Linux  and FTP Configuration in Linux

vsftpd is a lightweight, extremely reliable, secure, and fast Linux FTP server. Many popular FTP services Dataservermarket on the internet are powered by vsftpd (including ftp.redhat.com).

vsftpd additionally supports virtual IP addresses, virtual users, bandwidth limiting, IPv6 encryption, and other features.

This guide will walk you through the process of installing vsftpd from source on your server.

  1. Download vsftpd Source

Go to vsftpd download site and scroll down to download the latest version of the vsftpd. Or use wget to download it directly on your server from Dataservermarket.

# wget ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.2.tar.gz
  • Compile vsftpd source

Compile the vsftpd source as shown below.

# tar xvfz vsftpd-2.3.2.tar.gz
 
# cd vsftpd-2.3.2
 
# make

After the make command executes successfully, you’ll see vsftpd file getting created in the current directory.

# ls -l vsftpd

You can either move the vsftpd file Dataservermarket manually to /usr/local/sbin directory and set appropriate permissions, or execute the make install as shown below.

# make install
if [ -x /usr/local/sbin ]; then \
                install -m 755 vsftpd /usr/local/sbin/vsftpd; \
        else \
                install -m 755 vsftpd /usr/sbin/vsftpd; fi
if [ -x /usr/local/man ]; then \
                install -m 644 vsftpd.8 /usr/local/man/man8/vsftpd.8; \
                install -m 644 vsftpd.conf.5 /usr/local/man/man5/vsftpd.conf.5; \
        elif [ -x /usr/share/man ]; then \
                install -m 644 vsftpd.8 /usr/share/man/man8/vsftpd.8; \
                install -m 644 vsftpd.conf.5 /usr/share/man/man5/vsftpd.conf.5; \
        else \
                install -m 644 vsftpd.8 /usr/man/man8/vsftpd.8; \
                install -m 644 vsftpd.conf.5 /usr/man/man5/vsftpd.conf.5; fi

After make install, make sure the vsftpd file is copied to /usr/local/sbin directory.

# ls -l /usr/local/sbin/vsftpd
-rwxr-xr-x 1 root root 107652 Oct 30 20:23 /usr/local/sbin/vsftpd
  • Copy vsftpd man pages to /usr/share/man/man8, man5

You might get the following make install error messages because /usr/local/man/man8 and man5 directory does not exist over Dataserevermarket.

install: cannot create regular file `/usr/local/man/man8/vsftpd.8': No such file or directory
install: cannot create regular file `/usr/local/man/man5/vsftpd.conf.5': No such file or directory
make: *** [install] Error 1

Copy the man pages manually to the /usr/share/man/man8 and man5 directory as shown below.

# cp vsftpd.8 /usr/share/man/man8/
 
# cp vsftpd.conf.5 /usr/share/man/man5/
  • Copy vsftpd.conf configuration file

vsftpd comes with a default configuration file in Dataserevermarket. Copy this vsftpd.conf to /etc directory.

# cp vsftpd.conf /etc
  • Setup Anonymouse FTP access for vsftpd

Make sure ftp user already exists.

# grep ftp /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

Create /var/ftp directory and set appropriate privileges.

#  mkdir /var/ftp/
 
# chown root.root /var/ftp
 
# chmod og-w /var/ftp

Login using anonymous (or ftp user) to make sure it works as shown below.

# ftp localhost
Connected to dotcom.
220 (vsFTPd 2.3.2)
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

At this stage over Dataserevermarket, if you try to login with any other account (except anonymous, and ftp), it will fail as shown below.

# ftp localhost
Connected to dotcom.
220 (vsFTPd 2.3.2)
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): ramesh
530 This FTP server is anonymous only.
Login failed.
ftp> 
  • Allow UNIX logins to use vsftp

You might want to setup ftp users other than anonymous or ftp. You can allow Linux login account to be used to access the vsftpd server.

First, copy the vsftpd.pam template provided in Dataserevermarket along with the source code to the /etc/pam.d/ftp directory

# cp RedHat/vsftpd.pam /etc/pam.d/ftp

Remove the comment from the local_enable parameter in the /etc/vsftpd.conf file. i.e local_enable should be set to YES to allow local Unix accounts to be used to login from the ftp.

#local_enable=YES

Kill the running vsftpd, and restart it again. Now, try to login again with a Linux user account using the ftp and it should work.

# ps -ef | grep vsftpd
 
# kill -9 {vsftpd-pid}
 
# /usr/local/sbin/vsftpd &
 
# ftp localhost
Connected to dotcom.
220 (vsFTPd 2.3.2)
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): ramesh
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

How To Install FTP Server in Ubuntu with vsftpd

If you want to Install FTP Server Ubuntu , you can’t go wrong with vsftpd.

FTP is an abbreviation for File Transfer Protocol. It is similar to HTTP (HyperText Transport Protocol) in that it provides a language for data transfer across a network in Dataservermarket. Because FTP is unencrypted by default, it is not a good solution for secure data transmission.

This instruction will walk you through the process of installing and configuring an FTP server with vsftpd on Ubuntu.

Step 1: Update System Packages

Start by updating your repositories – enter the following in a terminal window:

sudo apt update

Install and Configure vsftpd on Ubuntu 18.04

Step 2: Install vsftpd Server on Ubuntu

A common open-source FTP utility used in Ubuntu FTP Setup is vsftpd OR FTP Server Ubuntu. It is recommended for its ease of use.

  1. To install vsftpd, enter the command:

sudo apt install vsftpd

This is an example of the output in Ubuntu.

Install and Configure vsftpd on Ubuntu 18.04

2. To launch the service and enable it at startup, run the commands:

sudo systemctl start vsftpd

sudo systemctl enable vsftpd

Step 3: Backup Configuration Files

Before making any changes, make sure to back up your configuration files.

1. Create a backup copy of the default configuration file by entering the following:

 

sudo cp /etc/vsftpd.conf  /etc/vsftpd.conf_default

Step 4: Create FTP User

Create a new FTP user with the following commands:

sudo useradd -m testuser

sudo passwd testuser

The system should ask you to create a password for the new testuser account.

Step 5: Configure Firewall to Allow FTP Traffic

If you are using UFW that comes standard with Ubuntu, it will block FTP traffic by default. Enter the following commands to open Ports 20 and 21 for FTP traffic:

sudo ufw allow 20/tcp

sudo ufw allow 21/tcp

Install and Configure vsftpd on Ubuntu 18.04

Step 6: Connect to Ubuntu FTP Server

Connect to the FTP server with the following command:

sudo ftp ubuntu-ftp

Replace ubuntu-ftp with the name of your system (taken from the command line).

Log in using the testuser account and password you just set. You should now be successfully logged in to your FTP server.

Configuring and Securing Ubuntu vsftpd Server

Change Default Directory

The FTP server uses the /srv/ftp directory as the default directory by default. This may be changed by making a new directory and modifying the FTP user’s home directory.

To change the FTP home directory, enter the following:

sudo mkdir /srv/ftp/new_location

sudo usermod -d /srv/ftp/new_location ftp

Restart the vsftpd service to apply the changes:

sudo systemctl restart vsftpd.service

You may now put any files you want to share over FTP into the /srv/ftp folder (if it was left as the default) or the /srv/ftp/new location/ directory (if you changed it).

Authenticate FTP Users

If you want authorised users to be able to upload files, change the vsftpd.conf file to include the following:

sudo nano /etc/vsftpd.conf

Find the entry labeled write_enable=NO, and change the value to “YES.”

Install and Configure vsftpd on Ubuntu 18.04

Save the file, exit, then restart the FTP service with the following:

sudo systemctl restart vsftpd.service

This allows the user to make changes inside their home directory.

Leave a Reply

Your email address will not be published. Required fields are marked *