Configure FTP Service In Linux Using vsftpd – RHEL 7&8

Learn the step by step process of how to setup or configure FTP service in Linux. Also learn the vsftpd configuration file and the important parameters in the file.


What Is FTP and vsftpd

FTP, which is the acronym for (File transfer protocol) is a protocol used to transfer or share files between two systems.

FTP services is a server-client based services used in sharing files between a server and a client using the File transfer protocol (FTP).

For files to be shared, an FTP server will have to be in place (installed and configured) where files can be downloaded from or uploaded to by the client.

Just as we have many FTP server software (FTP applications) that can be installed on windows such as FileZilla, WinSCP, etc to share files between systems, also In Linux, there are many FTP server software (FTP applications) that can be used to set up FTP services.

Examples of such applications that can be used in Linux are ProFTPD, CrossFTP, PureFTPD, uFT, Apache FTP Server, etc, but the default application/daemon used in Linux is the vsftpd daemon. vsftpd is even shipped with some Linux distributions

Therefore, in this article, we will look at how to set up FTP services using the vsftpd application.

Understanding Basic vfstpd Service

There are two kinds of users for FTP services. They are

1. Anonymous users: From the word anonymous, any user can access the FTP server if the anonymous way of accessing the FTP server is configured and allowed.

The anonymous user in real sense accesses files in the home directory of the default FTP user on the system.

To see the home directory of the default FTP user, use the command,

[root@HQDEV1 ~]# cat /etc/passwd |grep ftp

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

You can see the home directory of the ftp user is “/var/ftp” which is also the document root for FTP. Hence why an anonymous user can be able to access a file that is actually accessed from the FTP user’s home directory.

More so, the anonymous user has restrictions. Anonymous users can’t write to files by default but only download files because the directory, “/var/ftp” where files can be accessed by anonymous users is owned by root and doesn’t have write permission as well.

This can be verified by using the command,

[root@HQDEV1 ~]# ls -ld /var/ftp

drwxr-xr-x. 3 root root 17 Jul  2 20:48 /var/ftp

2. Verified users: only the users in the /etc/passwd file can access the FTP server if the verified or authenticated way of accessing the FTP server is configured and allowed.

Going forward, this tutorial will focus on only the anonymous way of accessing the FTP server. In other article, we will look at the other way of accessing the FTP server.

vsftpd Configuration File

The vsftpd configuration file is in the path, (/etc/vsftpd/vsftpd.conf).

Let’s concatenate the file to see the content.

[root@HQDEV1 ~]# cat /etc/vsftpd/vsftpd.conf

Let’s understand the important parameters in this file.

1. anonymous_enable =NO

This parameter implies that anonymous users will not be able to access or download files from the FTP server. If the value is set to “YES”, then anonymous users will be able to access or download from the FTP server.

2. local_enable=YES

This parameter implies that users will be able to access or download files from their home directory. However, if SELinux is enabled and in enforcing mode, if the boolean for this feature is not turned on, the download will not happen until the boolean is turned on.

To allow otherwise, set the value to be “NO”

3. write_enable=YES

This implies that the verified users in “/etc/passwd” will be able to write to their directories. If the value is set otherwise, they won’t be able to write in their directories.

4. anon_upload_enable=YES

This implies that anonymous users will be able to upload files. The parameter is commented which negates the settings. If this parameter is commented out or the value is set to “NO”, anonymous users will not be able to upload files.

Having understood the basic parameters in the vsftpd configuration file, let’s get to the action


How To Configure / Setup FTP Server In Linux (Step By step)

1. Install the FTP server (vsftpd)

[root@HQDEV1 ~]# yum install vsftpd -y

Updating Subscription Management repositories.
Last metadata expiration check: 0:00:37 ago on Thu 02 Jul 2020 08:47:57 PM WAT.

[root@HQDEV1 ~]#

2. Backup the vsftpd configuration file(vsftpd.conf)

[root@HQDEV1 ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_original

3. Edit the vsftpd.conf file for anonymous users to be able to access files on the server

[root@HQDEV1 ~]# vi /etc/vsftpd/vsftpd.conf

look for the line “anonymous_enable”, comment out the line and make the value YES

NB: If you comment out the line, anonymous users will be allowed by default

configure FTP service in Linux

4. Start the vsftpd service

[root@HQDEV1 ~]# systemctl start vsftpd

If you wish, you can enable the service by using the command

[root@HQDEV1 ~]# systemctl enable vsftpd

5. Verify the status of the vsftpd service

[root@HQDEV1 ~]# systemctl status vsftpd

● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-07-02 23:27:21 WAT; 1min 15s ago
  Process: 36656 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)

Now we have the FTP service configured for anonymous users. Let’s do a test.

6. Copy a file to the location “/var/ftp”

[root@HQDEV1 ~]# cp /etc/fstab /var/ftp

7. Use any FTP client utility to connect to the FTP server

In this tutorial, we will use the lftp client to connect.

Download the lftp package

[root@HQDEV1 ~]# yum install lftp

Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                       


8. Connect with the lftp client and do a list of the files

[root@HQDEV1 ~]# lftp localhost
lftp localhost:~> ls
-rw-r--r--    1 0        0             776 Jul 04 17:49 fstab
drwxr-xr-x    2 0        0               6 Feb 17 09:35 pub
lftp localhost:/>

Now you can see the fstab file.

concatenate the file.

lftp localhost:/> cat fstab

# /etc/fstab
# Created by anaconda on Sat Apr 11 12:48:10 2020
#/dev/mapper/tekneed                      /victor                 ext4    defaults        1 2
776 bytes transferred
lftp localhost:/>

you can also use the wget utility to download files remotely or use any browser

Configuring FTP Server As a Remote Server For yum local Repository In RHEL / CentOS 8

Your feedback is welcomed. If you love others, you will share with others

Be the first to comment

Leave a Reply

Your email address will not be published.