This case focuses on deploying a secure FTP server for local users, disabling anonymous access, and restricting users to their home directories.
yum to install the vsftpd package (the default secure FTP daemon for CentOS).sudo yum install vsftpd -y
/etc/vsftpd/vsftpd.conf to disable anonymous login (anonymous_enable=NO), allow local user login (local_enable=YES), enable file uploads (write_enable=YES), and restrict users to their home directories (chroot_local_user=YES). To allow writes in the chroot directory, add allow_writeable_chroot=YES.sudo systemctl start vsftpd
sudo systemctl enable vsftpd
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=30000-31000/tcp
sudo firewall-cmd --reload
sudo setsebool -P ftpd_full_access on
ftpuser) with a home directory and set a password. Restrict shell access to prevent shell logins:sudo useradd -m -s /sbin/nologin ftpuser
sudo passwd ftpuser
This setup ensures only authenticated local users can access the server, with each user confined to their home directory—preventing unauthorized access to system files. Passive mode configuration resolves common NAT/firewall connectivity issues.
For scenarios requiring isolated FTP accounts (e.g., client-specific access), virtual users (non-system accounts mapped to system users) are ideal. This case covers creating virtual users with custom home directories and permissions.
db4-utils to manage virtual user credentials (stored in a hashed database).sudo yum install db4 db4-utils -y
/etc/vsftpd/vuser_passwd.txt) with one username/password pair per line (e.g., ftpuser1/pass1). Generate a hashed database:db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
/etc/pam.d/vsftpd to use the virtual user database. Comment out existing lines and add:auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd
account required pam_userdb.so db=/etc/vsftpd/vuser_passwd
/var/ftp/virtual_users) and individual subdirectories (e.g., /var/ftp/virtual_users/ftpuser1). Set ownership to the virtual user and configure permissions:sudo mkdir -p /var/ftp/virtual_users/ftpuser1
sudo useradd -d /var/ftp/virtual_users/ftpuser1 -s /sbin/nologin ftpvirtuser
sudo chown ftpvirtuser:ftpvirtuser /var/ftp/virtual_users/ftpuser1
/etc/vsftpd/vuser_conf/ftpuser1) with custom options (e.g., local_root=/var/ftp/virtual_users/ftpuser1, write_enable=YES)./etc/vsftpd/vsftpd.conf to enable virtual users (guest_enable=YES), map virtual users to the system user (guest_username=ftpvirtuser), and specify the config directory (user_config_dir=/etc/vsftpd/vuser_conf).sudo systemctl restart vsftpd
Virtual users provide enhanced security by separating FTP access from system accounts. Each virtual user has a dedicated directory with customizable permissions, ideal for multi-client environments where isolation is critical.
FTP deployments often face connectivity or permission problems. This case outlines solutions for three frequent issues.
Symptoms: Clients cannot connect to the FTP server (error: “Connection refused”).
Root Cause: The vsftpd service is not running, or the firewall blocks port 21.
Solution:
sudo systemctl start vsftpd
sudo systemctl enable vsftpd
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --reload
Symptoms: Users can log in but cannot access their home directory (error: “500 OOPS: cannot change directory:/home/username”).
Root Cause: SELinux prevents FTP access to user home directories (default ftp_home_dir setting is off).
Solution: Enable SELinux support for FTP home directories:
sudo setsebool -P ftp_home_dir on
Symptoms: Users can upload files but receive “553 Could not create file” errors.
Root Cause: The target directory lacks write permissions for the FTP user, or SELinux blocks file creation.
Solution:
/var/ftp/pub):sudo chmod 777 /var/ftp/pub
sudo chcon -t public_content_rw_t /var/ftp/pub
These troubleshooting steps address the most common FTP issues, ensuring reliable connectivity and file transfer capabilities. SELinux and firewall configurations are critical to resolving permission-related problems.