DEV Community

Ashwin Telmore
Ashwin Telmore

Posted on • Originally published at ashwintelmore.hashnode.dev on

How to use FTP servers in Ubuntu

In This blog we will see how to install and configure an FTP server on Ubuntu 20.04 that you use to share files between your devices.

FTP stand for File Transfer Protocol which is a standard network protocol used to transfer files to and from a remote system. We will be installing vsftpd which stand for Very Secure Ftp Daemon, a stable, secure, and fast FTP server.

FTP is a very popular protocol, for more secure and faster data transfers

Installing vsftpd on Ubuntu 20.04

The vsftpd package is available in the Ubuntu repositories. To install it, run the following commands:

sudo apt update


sudo apt install vsftpd

Enter fullscreen mode Exit fullscreen mode

The ftp service will automatically start once the installation process is complete. To verify it, print the service status:

sudo systemctl status vsftpd

Enter fullscreen mode Exit fullscreen mode

The output should show that the vsftpd service is active and running:

 vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-03-02 15:17:22 UTC; 3s ago
      .
      .
      .

Enter fullscreen mode Exit fullscreen mode

Configuring vsftpd The vsftpd server configuration is stored in the /etc/vsftpd.conf file.

For more visit the vsftpd documentation page.

In the following sections, we will go over some important settings needed to configure a secure vsftpd installation.

Start by opening the vsftpd configuration file:

sudo vi /etc/vsftpd.conf

Enter fullscreen mode Exit fullscreen mode

Paste these properties at last

listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
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
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=30000
pasv_max_port=31000
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO

Enter fullscreen mode Exit fullscreen mode

Save the file and restart the vsftpd service for changes to take effect:

sudo systemctl restart vsftpd

Enter fullscreen mode Exit fullscreen mode

Opening the Firewall If you are running a UFW firewall , youll need to allow FTP traffic.

To open port 21 (FTP command port), port 20 (FTP data port), and 30000-31000 (Passive ports range), run the following commands:

sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp

Enter fullscreen mode Exit fullscreen mode

To avoid being locked out, make sure port 22 is open:

sudo ufw allow OpenSSH

Enter fullscreen mode Exit fullscreen mode

Reload the UFW rules by disabling and re-enabling UFW:

sudo ufw disable
sudo ufw enable

Enter fullscreen mode Exit fullscreen mode

To verify the changes run:

sudo ufw status

Enter fullscreen mode Exit fullscreen mode

Output look like

Status: active
To Action From
-- ------ ----
20:21/tcp ALLOW Anywhere
30000:31000/tcp ALLOW Anywhere
OpenSSH ALLOW Anywhere
20:21/tcp (v6) ALLOW Anywhere (v6)
30000:31000/tcp (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

Enter fullscreen mode Exit fullscreen mode

Creating FTP User

To test the FTP server, we will create a new user. Create a new user named newuser:

sudo adduser newuser

Enter fullscreen mode Exit fullscreen mode

Add the user to the allowed FTP users list:

echo "newuser" | sudo tee -a /etc/vsftpd.user_list

Enter fullscreen mode Exit fullscreen mode

Create the FTP directory tree and set the correct permissions:

sudo mkdir -p /home/newuser/ftp

Enter fullscreen mode Exit fullscreen mode

Give the require permission to the newuser.

sudo chmod 777 /home/newuser/ftp


sudo chown -R newuser: /home/newuser/ftp

Enter fullscreen mode Exit fullscreen mode

Test your configuration Perform the following step in another windows/Linux system to test out

step 1: open Command line interface of your respective system and run this following command with replacing the ip_address of remote system

ftp ip_address

Enter fullscreen mode Exit fullscreen mode

Enter the user name which you newly created with password and you will see the following output

C:\Users\window>ftp 192.168.29.128 
Connected to 192.168.29.128. 
220 (vsFTPd 3.0.3) 
200 Always in UTF8 mode. User (192.168.29.128:(none)): newuser
331 Please specify the password.
Password: 
230 Login successful.
ftp>

Enter fullscreen mode Exit fullscreen mode

Done!😎

Read the next blog to upload and download the file through the ftp

Top comments (0)