How to set up vsftpd FTP server on CentOS 6

This article guides you through the process of setting up vsftpd to allow a user to upload files to their home directory using FTP on CentOS 6.

Installation

sudo yum install vsftpd

Configuration

Open the main configuration file:

sudo nano /etc/vsftpd/vsftpd.conf

Make the following changes to enable local user logins and restrict them to their home directories:

# Disable anonymous access
anonymous_enable=NO

# Allow local system users to log in
local_enable=YES

# Allow file uploads
write_enable=YES

# Restrict users to their home directories
chroot_local_user=YES

# Required when chroot is enabled to avoid the "500 OOPS" error
allow_writeable_chroot=YES

# Use passive mode (recommended for firewalls/NAT)
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40100

Creating an FTP user

Create a dedicated user for FTP access:

sudo useradd -m ftpuser
sudo passwd ftpuser

If you want to restrict the user from SSH login while allowing FTP:

sudo usermod -s /sbin/nologin ftpuser

Add /sbin/nologin to /etc/shells so vsftpd accepts it:

echo "/sbin/nologin" | sudo tee -a /etc/shells

Firewall rules

Open the FTP control port and passive data ports:

sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 40000:40100 -j ACCEPT
sudo service iptables save

Starting vsftpd

sudo service vsftpd start
sudo chkconfig vsftpd on

Testing the connection

Connect from a client machine:

ftp your-server-ip

Log in with the FTP user credentials. You should land in the user's home directory and be able to upload files.

On this page