Installing, configuring and accessing FTP server via Filezilla in Centos 7

Swwapnil Pawar
5 min readJan 9, 2020

--

CentOS

vsftpd (Very Secure File Transport Protocol Daemon) is a secure, fast FTP server. The procedures to install, configure FTP and access the FTP server via Filezilla on CentOS 7 is explained in this article.

login to your server & enter the below command to install vsftpd:

sudo yum install ftp vsftpdLoaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
--> Running transaction check
---> Package ftp.x86_64 0:0.17-66.el7 will be installed
---> Package vsftpd.x86_64 0:3.0.2-11.el7_2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
.
.
Installed:
ftp.x86_64 0:0.17-66.el7 vsftpd.x86_64 0:3.0.2-11.el7_2

Complete!

Once the installation is done, open the vsftpd.conf file located at

sudo nano /etc/vsftpd/vsftpd.conf

And edit it as follows:

## Disable anonymous login ##
anonymous_enable=NO
## Uncomment ##
ascii_upload_enable=YES
ascii_download_enable=YES
## Uncomment - Enter your Welcome message - This is optional ##
ftpd_banner=Welcome to UNIXMEN FTP service.
## Add at the end of this file ##
use_localtime=YES
## Uncomment ##
anon_upload_enable=YES
## Uncomment ##
anon_mkdir_write_enable=YES
## Add new line at the end ##
file_open_mode=0777

Save and exit the file.
Then enable and start the vsftpd service.

sudo systemctl enable vsftpdsudo systemctl start vsftpd

The next step is to allow the FTP service and port 21 via the firewall.

sudo firewall-cmd --permanent --add-port=21/tcpoutput > successsudo firewall-cmd --permanent --add-service=ftpoutput > successRestart firewall:
[hgsuser@hgsuser ~]# sudo firewall-cmd --reload

If you receive an error while adding firewall rules as shown below

sudo: firewall-cmd: command not found

Follow the below steps to recover from firewall-cmd error:

firewall-cmd is a command-line front-end for firewalld (firewalld daemon), a dynamic firewall management tool with D-Bus interface.

It supports both IPv4 and IPv6. it also supports network firewall zones, bridges and ipsets. It allows for timed firewall rules in zones, logs denied packets, automatically loads kernel modules and so many other features.

Firewalld uses runtime and permanent configuration options, which you can manage using firewall-cmd.

To fix this error, you need to install firewalld on RHEL/CentOS 7 using yum package manager as follows.

$ sudo yum install firewalld
firewalld output

Next, start firewalld and enable it to auto-start at system boot, then check its status.

$ sudo systemctl start firewalld
$ sudo systemctl enable firewalld
$ sudo systemctl status firewalld

Then, update the SELinux boolean values for the FTP service as shown below.

[hgsuser@hgsuser ~]# sudo setsebool -P ftp_home_dir on
[hgsuser@hgsuser ~]#

If you get the output saying “SELinux is Disabled” then you need to enforce it to update SELinux boolean value.

$ sudo nano /etc/selinux/configChange SELINUX to enforcing.# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing — SELinux security policy is enforced.
# permissive — SELinux prints warnings instead of enforcing.
# disabled — No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted — Targeted processes are protected,
# minimum — Modification of targeted policy. Only selected processes are protected.
# mls — Multi Level Security protection.
SELINUXTYPE=targeted

Try updating SELinux boolean values again & you will have to reboot the system before SELINUX value gets updated.

To Create FTP users

The root user is not allowed to login to the FTP server for security purposes. So, create a normal testing user.

[hgsuser@hgsuser ~]# useradd helpdesk
[hgsuser@hgsuser ~]# passwd helpdesk
Changing password for user abc.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

Connect to FTP server

Connect to the FTP server with the user “ helpdesk” .

[hgsuser@hgsuser ~]# ftp 192.168.7.224
Connected to 192.168.7.224 (192.168.7.224).
220 Welcome to linuxhelp FTP service.
Name (192.168.7.224:root): helpdesk
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp> exit
221 Goodbye

Access FTP Server Via FileZilla

Install a graphical FTP client called Filezilla to access FTP server.

First, enter the following commands to disable firewalld, and to enable iptables for easy access of filezilla.
Make sure that you execute these commands on your FTP server and not in ftp clients.

[hgsuser@hgsuser ~]# yum install iptables-services
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
--> Running transaction check
---> Package iptables-services.x86_64 0:1.4.21-13.el7 will be updated
---> Package iptables-services.x86_64 0:1.4.21-16.el7 will be an update
--> Processing Dependency: iptables = 1.4.21-16.el7 for package: iptables-services-1.4.21-16.el7.x86_64
--> Running transaction check
---> Package iptables.x86_64 0:1.4.21-13.el7 will be updated
---> Package iptables.x86_64 0:1.4.21-16.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved.Updated:
iptables-services.x86_64 0:1.4.21-16.el7
Dependency Updated:
iptables.x86_64 0:1.4.21-16.el7
Complete![hgsuser@hgsuser ~]# sudo systemctl mask firewalld[hgsuser@hgsuser ~]# sudo systemctl enable iptables
ln -s ' /usr/lib/systemd/system/iptables.service' ' /etc/systemd/system/basic.target.wants/iptables.service'
[hgsuser@hgsuser ~]# sudo systemctl enable ip6tables
ln -s ' /usr/lib/systemd/system/ip6tables.service' ' /etc/systemd/system/basic.target.wants/ip6tables.service'

[hgsuser@hgsuser ~]# sudo systemctl stop firewalld
[hgsuser@hgsuser ~]#
[hgsuser@hgsuser ~]# sudo systemctl start iptables
[hgsuser@hgsuser ~]#
[hgsuser@hgsuser ~]# sudo systemctl start ip6tables
[hgsuser@hgsuser ~]#

Allow the default ftp port “ 21” in the firewall or router.
Open and add the following line in the “ iptables” file in /etc/sysconfig/

[hgsuser@hgsuser ~]# sudo vim /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

Save and exit the file. Restart iptables.

[hgsuser@hgsuser ~]# sudo vim /etc/sysconfig/iptables
[hgsuser@hgsuser ~]# sudo systemctl restart iptables
[hgsuser@hgsuser ~]# sudo systemctl restart ip6tables
[hgsuser@hgsuser ~]#

Once you done will all the above steps, now you will create FTP User to give access to server using FileZilla Client.

Create a local user that will be used for ftp (in our case we will call him helpdesk) and set the home directory to /var/www

sudo adduser helpdesk
sudo usermod -d /var/www -m helpdesk

5. Add the ftpuser to the www-data group

sudo usermod -a -G hgsuser helpdesk

6. Set the correct permissions on /var/www

sudo chgrp -R hgsuser /var/www
sudo chmod -R g+w /var/www

7. Make the directory and all directories below it “set GID”, so that all new files and directories created under /var/www are owned by the hgsuser group

sudo find /var/www -type d -exec chmod 2775 {} \;

8. Find all files in /var/www and add read and write permission for owner and group

sudo find /var/www -type f -exec chmod ug+rw {} \;

NOTE: Make sure you select “ACTIVE” mode as a default mode in filezilla transfer settings.

Now, you’re successfully connect to the server using FTP.

--

--

Swwapnil Pawar

Entrepreneur, Cloud Evangelist, AWS/Google Certified Architect, Building Cool Things With Serverless. Avid Reader