Build A Linux FTP Server on Ubuntu 17.04

linux ftp server

FTP is an old service which almost anyone known already what it is. If you are regular internet users, you should be familiar with FTP. This Linux Guide will show you how to install or setup a Linux FTP Server on Ubuntu Linux in few simple steps. On this tutorial, we use Ubuntu 17.04 but it also works with Ubuntu 16.04 and other Ubuntu version as well. We are going to show you how to setup Linux FTP Server in both normal and stand-alone mode. To build a secure FTP Server, we use a lightweight and secure FTP Server vsFTPD which is great for servers with high load. 

What is FTP ?

If you are not familiar with FTP, here are a short introduction to FTP and the service offers. FTP stands for File Transfer Protocol. This protocol has been used widely in last couple of years. This network protocol allows us to transfer files or folders from one host to another host (usually remote host). FTP supports both LAN and also Internet. Imagine if you are at home and want to send some files to your remote server at the other continent, FTP is for you. 

On this tutorial, we are going to use vsFTPD. vsFTP has many great features such as:

  • Virtual IP configuration
  • Virtual users
  • Standalone or inetd service support
  • Bandwidth throttling
  • SSL integration
  • Many more

How to Setup Linux FTP Server on Ubuntu

Ubuntu is a great Linux distribution for both desktop and server. We can install Linux FTP Server on Ubuntu with a single command on Terminal.

sudo apt update
sudo apt install vsftpd

The command will update your system repository and then install FTP Server and start the ftp server as well. You can check if the vsftpd service is running using this command

sudo systemctl status vsftpd

Output:

ubuntu@ubuntu-server:~$ sudo systemctl status vsftpd
● vsftpd.service - vsftpd FTP server
Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2017-10-09 16:42:26 WIB; 32s ago
Main PID: 22963 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─22963 /usr/sbin/vsftpd /etc/vsftpd.conf

Oct 09 16:42:26 ubuntu-server systemd[1]: Starting vsftpd FTP server...
Oct 09 16:42:26 ubuntu-server systemd[1]: Started vsftpd FTP server.

At this point our FTP Server is up and running. Now we will learn how to setup FTP Server using Stand-alone vs Normal mode. 

Stand-alone vs Normal FTP Mode

Stand-alone mode

After install, by default vsftpd start in stand-alone mode. Without any changes to its configuration file, vsftp already run in stand-alone mode. But what is stand-alone mode? In stand-alone mode, the service has its own daemon (startup script). The vsftpd daemon provide us couple of command to manage the FTP Server, such as:

  • start or stop – is used to start or stop the ftp server
  • status – get information about the ftp server status
  • restart – command to restart the ftp server
  • reload – this will tells ftp server to reload and apply all new configuration. For example if we edit the config file, we need to reload it. This won’t shut down the ftp but only reloading the new configuration.

For example, the following command is used to restart the ftp server 

sudo systemctl restart vsftpd

Normal Mode

In Nomal mode, the vsftpd FTP service is managed by xinetd superserver. This xinetd will responsible to keep the FTP service alive. In order to run vsftpd FTP server in normal mode, we need to install xinetd superserver first.

sudo apt install xinetd

Now, we need to create a vsftpd config file under /etc/xinetd.d/ directory. Copy and paste the following lines to it.

service ftp
{
        disable                 = no
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /usr/sbin/vsftpd
        per_source              = 5
        instances               = 200
        no_access               = 10.1.1.10
        banner_fail             = /etc/vsftpd.busy
        log_on_success          += PID HOST DURATION
        log_on_failure          += HOST
}

Next, we need to edit the vsftpd configuration file in /etc/vsftp.conf and change the following line

listen=yes

Change it to

listen=no

This will force FTP Server not to open any ports and let the xinetd service to do this. We need to stop the vsftpd service first prior to start it in normal mode.

sudo systemctl stop vsftpd

and then

sudo service xinetd restart

Now check the FTP Server if it runs normally using this command

netstat -ant | grep 21

Output:

ubuntu@ubuntu-server:/etc/xinetd.d$ netstat -ant | grep 21
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN

Configure FTP Server

In the following steps we are going to configure several things such as Configure user access and anonymous access and some others. We need to edit /etc/vsftpd.conf file. Please restart the ftp server after you made edit. 

sudo service xinetd restart

Anonymous FTP Access Configuration

We are going to disable or enable anonymous access to FTP Server. It’s depends on your needs whether you need to leave it disable or you want to give limited access to anonymous user. Find the following lines and make change as you need. These are the default settings which does not allow anonymous access. It’s not wise to enable anonymous access. 

anonymous_enable=NO
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES

But, in case you need it to, simply change those lines into 

anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES

Warning: Those settings will lets anonymous access your FTP Server, upload files and also create directory as well. Please do it at your own risk. We recommended to leave the default value as it’s secured already.

Enable local user FTP access

Now, if you want, you can enable local user to log in to FTP server using their account. To do this, we need to enable the following settings on /etc/vsftpd.conf

local_enable=YES

With this option, user can login to the server. To test, simply execute the following command

ftp localhost

Example:

root@ubuntu-server:/etc# ftp localhost
Trying 127.0.0.1...
Connected to localhost.
220 Welcome to blah FTP service.
Name (localhost:ubuntu): ubuntu
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221 Goodbye.
root@ubuntu-server:/etc#

 

OK now we have a working Linux FTP Server. Now you can use it for your needs for example to store your backup files and other stuffs. 

Thanks for reading this how to setup Linux FTP Server using Ubuntu. Please share if you think this is useful. Leave us comments if you need help. I will try to moderate each comments.

Be the first to comment

Leave a Reply