September 16, 2021

TECH HYME

A Blog For Tech Enthusiasts

How to Setup FTP Server in Ubuntu

3 min read

FTP used to be the most used protocol on the Internet by sheer data traffic until it was surpassed by HTTP a few years ago. FTP does one thing, and it does it well, transferring of files between systems. The protocol itself is insecure, passwords, data, etc is transferred in clear text and can easily be sniffed, however most ftp usage is ‘anonymous’, so this isn’t a huge problem.

You may also read:

One of the main problems typically encountered with ftp sites is improper permissions on directories that allow people to use the site to distribute their own data.

The main objectives of FTP are:

  • To promote sharing of files
  • To encourage indirect or implicit (via programs) use of remote computers,
  • To shield a user from variations in file storage systems among hosts, and
  • To transfer data reliably and efficiently.

There are numerous ftp server software packages available for Linux but the best and most reliable is VSFTPD.

The first step is to install the vsftpd package in your Ubuntu machine by typing the following command:

apt-get install vsftpd

FTP Server Ubuntu Tech Hyme

Before proceeding further, make sure that you must take the backup of your original vsftpd.conf file:

mv /etc/vsftpd.conf /etc/vsftpd.conf.backup

FTP Server Ubuntu Tech Hyme

Now create new vsftpd.conf and paste the following configuration into it:

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
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES

This configuration is enough for a basic FTP server, and can later be tweaked for the specific needs of your environment once you’ve verified this is working properly:

FTP Server Ubuntu Tech Hyme

Next, you also need to create an exception in your Ubuntu built-in firewall (UFW) which will allow your FTP traffic:

ufw allow from any to any port 20,21,10000:10100 proto tcp

FTP Server Ubuntu Tech Hyme

With all this, restart your FTP Service by typing “systemctl restart vsftpd“.

FTP Server Ubuntu Tech Hyme

Congratulations! Your FTP server is ready and now you just need to add a new user into it with useradd and passwd command:

useradd -m <Username>
passwd <Username>

FTP Server Ubuntu Tech Hyme

In order to test and verify, you can create a test file in FTP User’s Home directory.

In this case, our home directory is /home/hymeuser/

FTP Server Ubuntu Tech Hyme

You should now be able to connect to your FTP server either by IP address or hostname.

Ensure that the default FTP client utility is installed on your system by running the following command. To connect from command line and verify that everything is working, open a terminal and use Ubuntu’s ftp command to connect to your loopback address (127.0.0.1).

ftp 127.0.0.1

FTP Server Ubuntu Tech Hyme

If you are using Windows Operating System, then you can use ftp://<IP address> in the address bar.

Enter the credentials of registered user and click on Log on button.

FTP Server Ubuntu Tech Hyme

Upon a successful connection, you’ll see the test file you created earlier. You’ll now be able to download and view this file, or upload your own contents to the directory.

FTP Server Ubuntu Tech Hyme

You can do a lot of things with your FTP server by editing the vsftpd.conf file like Changing Default Port, Allow Anonymous Access etc

Here for demonstration, we added the (listen_port 2020) code at the end of the file which will change your FTP default Port from 21 to 2020.

FTP Server Ubuntu Tech Hyme

Let us know if you have any problem while configuring and setup the FTP Server, or you can also mail us your query at hymeblogs@gmail.com.

Leave a Reply