Setting Up an FTP Server on CentOS 7

Setting Up an FTP Server on CentOS 7

To set up an FTP server on CentOS 7, follow these steps:

Step 1: Verify vsftpd Installation

Before proceeding, ensure that vsftpd is installed on your system. Run the following command to check:

rpm -qa | grep vsftpd

This command will search for vsftpd packages in the RPM database.

Step 2: Install vsftpd

If vsftpd is not installed, install it using the following command:

yum install vsftpd -y

This command will install vsftpd and its dependencies.

Step 3: Configure vsftpd

Open the vsftpd configuration file in a text editor using the following command:

vim /etc/vsftpd/vsftpd.conf

In this file, modify the following configuration settings:

  • Change Chroot_local_user = YES to Chroot_local_user = YES (no change)
  • Change Chroot_list_enable = YES to Chroot_list_enable = NO
  • Remove the Chroot_list_file = /etc/vsftpd/chroot_list line
  • Add the following line to set the root directory (optional):
    Local_root = /home/ftp_dir

Save the changes by pressing Esc, then enter :wq and press Enter.

Step 4: Start and Enable the FTP Server

Start the vsftpd service using the following command:

service vsftpd start

Enable the vsftpd service to start automatically at boot time using the following command:

chkconfig vsftpd on

Step 5: Create a User and Group

Create a new user group for the FTP users:

groupadd ftp_group

Add a new user, ftpadmin, to the ftp_group group:

useradd -d /home/ftp_dir -g ftp_group ftpadmin

Set the shell for the ftpadmin user to /sbin/nologin:

usermod -s /sbin/nologin ftpadmin

Change the home directory of the ftpadmin user to /home/ftp_dir:

usermod -d /home/ftp_dir ftpadmin

Set the password for the ftpadmin user:

passwd ftpadmin

Set the permissions for the /home/ftp_dir directory:

chmod -R 777 /home/ftp_dir

Step 6: Disable SELinux

Disable SELinux to prevent it from interfering with the FTP server:

setenforce 0

Open the SELinux configuration file in a text editor using the following command:

vim /etc/selinux/config

Change the SELINUX setting from enforcing to disabled:

SELINUX=disabled

Save the changes by pressing Esc, then enter :wq and press Enter.

Step 7: Restart the vsftpd Service

Restart the vsftpd service to apply the changes:

service vsftpd restart

Step 8: Test the FTP Server

You have now set up an FTP server on CentOS 7. Test it by connecting to the server using an FTP client, such as FileZilla.