CentOS

How to Setup an FTP Server with vsftpd on CentOS 7

vsftpd is an open source and lightweight FTP server solution. It is very fast, secure and stable. The configuration of vsftpd is very simple and straightforward.

In this article, I am going to show you how to install and access the vsftpd FTP server on CentOS 7. So, let’s get started.

Installing vsftpd:

vsftpd is available in the official package repository of CentOS 7. So, you can easily install it with the YUM package manager.

First, update the YUM package repository cache with the following command:

$ sudo yum makecache

The YUM package repository cache should be updated.

Now, install vsftpd with the following command:

$ sudo yum install vsftpd

Now, press y and then press <Enter> to continue.

vsftpd should be installed.

Now, check whether the vsftpd service is running with the following command:

$ sudo systemctl status vsftpd

As you can see, the vsftpd service is not running or inactive.

To start the vsftpd service, run the following command:

$ sudo systemctl start vsftpd

Now, check the status of the vsftpd service again.

$ sudo systemctl status vsftpd

As you can see, vsftpd service is running.

Now, you should add vsftpd service to the system startup so that it will start automatically on system boot.

To add the vsftpd service to the system startup, run the following command:

$ sudo systemctl enable vsftpd

vsftpd service should be added to the system startup.

Configuration Files of vsftpd:

On CentOS 7, all the vsftpd configuration files are in the /etc/vsftpd directory as you can see in the screenshot below.

The main configuration file is /etc/vsftpd/vsftpd.conf. If you want to configure vsftpd, most of the time you will be spending on modifying this file.

The main configuration file /etc/vsftpd/vsftpd.conf contains a lot of comments which is helpful when you configure vsftpd, but it makes it hard to see what configuration options are enabled. So, I recommend you keep a backup copy of the original configuration file and remove all comments from the /etc/vsftpd/vsftpd.conf file. This way, you will be able to take a look at the comments whenever you need any help configuring vsftpd and still have a clean configuration file which is easy to work with.

To make a backup copy (I will call it /etc/vsftpd/vsftpd.conf.backup) of the original /etc/vsftpd/vsftpd.conf file, run the following command:

$ sudo cp -v /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.backup

Now, remove all the comments from the original /etc/vsftpd/vsftpd.conf configuration file with the following command:

$ sudo egrep -v '^.*#' /etc/vsftpd/vsftpd.conf.backup | sudo tee /etc/vsftpd/vsftpd.conf

As you can see, the original configuration file now looks very clean.

Accessing the FTP Server:

The default configuration of vsftpd on CentOS is good enough. By default, vsftpd is configured in a way that lets only the login users on CentOS 7 to access their home directories via FTP.

To access your FTP server, you can use the command line lftp client program or any graphical FTP client programs such as FileZilla. I am going to use lftp command line FTP client in this article. I will use the same CentOS 7 machine for testing.

lftp is available in the official package repository of CentOS 7.

To install lftp, run the following command:

$ sudo yum install lftp

Now, press y and then press <Enter> to continue.

lftp should be installed.

Now, find the IP address of your FTP server as follows:

$ ip a

As you can see, the IP address of my FTP server is 192.168.21.133. Your IP address will be different. So, make sure to replace it with yours from now on.

Now, to try to access the FTP server as your login user as follows:

$ lftp -u USERNAME IP_ADDR

Here, USERNAME is the username of your login user that you want to log in to the FTP server as and IP_ADDR is the IP address of your FTP server.

Now, type in the password of your login user and press <Enter>.

You should be connected.

As you can see, all the directories and files of my HOME directory is listed. So, it works.

Adding New FTP Users:

As the default configuration of vsftpd lets only the login users access their home directories via FTP, to add a new FTP user, all you have to do is to add a new login user on your CentOS 7 machine.

To add a new user linda, run the following command:

$ sudo adduser -m linda

Now, set a password for the user linda with the following command. Note that, this is also the FTP password for the user linda.

$ sudo passwd linda

Now, type in a password for the user linda and press <Enter>.

Now, re-type the password and press <Enter>.

The password should be set.

As you can see, I can access the HOME directory of the user linda that I’ve just created.

Opening FTP Ports:

Now that everything is working, you can open the FTP ports so that other people can access it.

To do that using the default firewall program (firewalld) of CentOS 7, run the following command:

$ sudo firewall-cmd --zone=public --add-service=ftp --permanent

Now, reload the firewall for the changes to take effect with the following command:

$ sudo firewall-cmd --reload

So, that’s how you install and access the vsftpd FTP server on CentOS 7. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.