How To Setup FTP Server In Linux/Unix?

How To Setup FTP Server In Linux/Unix?

What is FTP?

FTP is the short form of File Transfer Protocol. It is a standard networking protocol used to transfer files between client and server. An FTP user may authenticate themselves by using username and a password. For secure transmission of username or password or other encrypted content that is to be transferred, FTP is often secured with the SSL/TLS(FTPS) or replaced with SSH File Transfer Protocol(SFTP). FTPD, VSFTPD, PROFTPD, and PUREPTPD are some examples of FTP servers used in Unix or Unix based systems.

What is vsftpd?

VSFTPD stands for “Very Secure File Transfer Protocol Daemon”. Using FTP without including any type of security layers likes SSL/TLS is insecure, and anyone should avoid this because it transmits data without encryption. So It is recommended to use a secure version of FTP such as SFTP. In this article, we are going to discuss about installing and configuring vsftpd which is a type of secure FTP server.

Installing vsftpd

To install vsftpd in your system use the following commands(In debian based systems) –

sudo apt-get update
sudo apt-get install vsftpd

Enable vsftpd services

Start the vsftpd services by using the given command-
systemctl start vsftpd
systemctl enable vsftpd

Create an FTP directory and grant required permissions –

So before starting, we need to create a user for FTP access-
sudo adduser testuser

Next, create an FTP directory and set ownership by using the given command-

sudo mkdir /home/testuser/ftp
sudo chown nobody:nogroup /home/testuser/ftp
sudo chmod a-w /home/testuser/ftp

Now create a directory where files can be uploaded by testuser –
sudo mkdir /home/testuser/ftp/test
sudo chown testuser:testuser /home/testuser/ftp/test

Configure vsftpd server

The configuration of vsftpd is saved in a file called vsftpd.conf which resides inside /etc/ directory of the system. For the secure implementation of the vsftpd server, we have to add/modify some options inside the vsftpd configuration file. But before making any changes to the configuration file, It is good to take the backup of the original file. The same can be done by using the given command-
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig

Now open the configuration file by using a text editor-
sudo nano /etc/vsftpd.conf

And add or uncomment the following options that are given inside the vsftpd.conf file –

 listen=YES
 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/vsftpd.userlist
 userlist_deny=NO

Save the edited file by pressing ctrl+o followed by the return key. The options in the configuration file can be added or modified according to your needs.

Now we need to add testuser into /etc/vsftpd.userlist file to allow FTP access. Use the following command to open the file using a text editor –
sudo nano /etc/vsftpd.userlist
Now add the testuser in this file and press ctrl+s to save and ctrl+x to exit from the editor.
Restart the vsftpd services –
sudo systemctl restart vsftpd

To check the status of FTP server use the following command –
sudo systemctl status vsftpd

As you can see in the image server is active(running). Now it is ready for use.

Accessing FTP server

The FTP server can be accessed by using a web browser or an FTP client application like Filezilla. To access from web browser use the URL of the site like ftp://example.com or use the localhost IP address if your FTP server is running locally. For example – Enter ftp://127.0.0.1 in your browser and press enter it will ask you to enter username and password. Enter the username that you have created before, and password and press enter to proceed. It will display the files and directories of the system. You can enable the SSL/TLS to encrypt the data transferred via FTP.

I hope this will gives you a basic understanding of implementing the FTP server in your system. At any step, if you find yourself stuck feel free to write us in the comments below.

Previous How To Connect A Remote Linux Server Using SSH?
Next How Systemd Is Different From SysVinit?

About author

You might also like

Linux Topics 0 Comments

Some Online Linux Terminal to Learn Linux

Are you looking for some online linux terminals to work with?? Yes, there are some Linux terminals available online which will be helpful for you to learn Linux on the

Linux Topics 0 Comments

How to Configure vncserver in Fedora Linux

Vnc server and vnc viewer is used to Remote Access in most of the Linux machines like Fedora, RHEL, Ubuntu or any other Linux distro. Sometimes it is necessary for

Linux Topics 0 Comments

How to Learn Linux Without Having a Linux Machine?

Wondering how to learn Linux without having a Linux PC with you?? Is it really possible or you’re just kidding me?? Trust me it’s all possible and you just need

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply