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 vsftpdConfiguration
Open the main configuration file:
sudo nano /etc/vsftpd/vsftpd.confMake 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=40100Creating an FTP user
Create a dedicated user for FTP access:
sudo useradd -m ftpuser
sudo passwd ftpuserIf you want to restrict the user from SSH login while allowing FTP:
sudo usermod -s /sbin/nologin ftpuserAdd /sbin/nologin to /etc/shells so vsftpd accepts it:
echo "/sbin/nologin" | sudo tee -a /etc/shellsFirewall 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 saveStarting vsftpd
sudo service vsftpd start
sudo chkconfig vsftpd onTesting the connection
Connect from a client machine:
ftp your-server-ipLog in with the FTP user credentials. You should land in the user's home directory and be able to upload files.