First, the installation of the necessary procedures
1. Install MySQL and pam_mysql
# yum-y Install vsftpd mysql-server mysql-devel pam_mysql
Note: Pam_mysql is provided by the Epel source.
Second, create a virtual user account
1. Prepare the database and related tables
First, make sure that the MySQL service is up and running. Then, create the database that stores the virtual users as needed, which is created as a VSFTPD database.
mysql> CREATE DATABASE vsftpd;
Mysql> Grant Select on vsftpd.* to [e-mail protected] identified by ' www.test.com ';
Mysql> Grant Select on vsftpd.* to [e-mail protected] identified by ' www.test.com ';
mysql> flush Privileges;
mysql> use VSFTPD;
Mysql> CREATE TABLE Users (
-ID int auto_increment not NULL,
, name char (a) binary not NULL,
Password char () binary not NULL,
-primary key (ID)
);
2. Adding a Test virtual user
To add the required users as needed, it is necessary to note that their passwords should be stored with the password function encrypted for security purposes.
mysql> INSERT into users (Name,password) VALUES (' Tom ', password (' test '));
mysql> INSERT into users (Name,password) VALUES (' Jerry ', password (' test '));
Third, configuration vsftpd
1. Establish the required files for PAM Certification
#vi/etc/pam.d/vsftpd.mysql
Add the following two lines
Auth required/lib/security/pam_mysql.so user=vsftpd passwd=www.test.com host=localhost db=vsftpd table=users Usercolumn=name Passwdcolumn=password crypt=0
Account required/lib/security/pam_mysql.so user=vsftpd passwd=www.test.com host=localhost db=vsftpd table=users Usercolumn=name Passwdcolumn=password crypt=0
Note: Due to the way MySQL is installed, pam_mysql.so Unix-based sock may have problems connecting to the MySQL server, and it is recommended that you authorize a remotely connected MySQL user to access the VSFTPD database.
2. Modify the VSFTPD configuration file to adapt it to MySQL authentication
Establish a virtual user mapping of the system users and corresponding directories
# useradd-s/sbin/nologin-d/var/ftproot VUser
# chmod Go+rx/var/ftproot
Make sure that the following options are enabled in/etc/vsftpd.conf
Anonymous_enable=yes
Local_enable=yes
Write_enable=yes
Anon_upload_enable=no
Anon_mkdir_write_enable=no
Chroot_local_user=yes
Then add the following options
Guest_enable=yes
Guest_username=vuser
And make sure that the value of the Pam_service_name option is as follows
Pam_service_name=vsftpd.mysql
Iv. Start VSFTPD Service
# service VSFTPD Start
# Chkconfig VSFTPD on
Viewing port opening conditions
# NETSTAT-TNLP |grep:21
TCP 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 23286/vsftpd
Using the virtual user login, positive configuration results, the following is the local command mode test, you can also use the other win box with IE or FTP client tool login
# FTP localhost
V. Configure virtual users to have different access rights
VSFTPD can provide each user with a separate profile in the profile directory to define their FTP service access rights, with each virtual user's profile name and the virtual user's user name. The configuration file directory can be any unused directory, just specify its path and name in vsftpd.conf.
1. Configure VSFTPD to use the profile directory for virtual users
# Vim Vsftpd.conf
Add the following options
User_config_dir=/etc/vsftpd/vusers_config
2. Create the required directory and provide the configuration file for the virtual user
# mkdir/etc/vsftpd/vusers_config/
# cd/etc/vsftpd/vusers_config/
# Touch Tom Jerry
3. Configure access rights for virtual users
The virtual user's access to the VSFTPD service is done through the instructions of the anonymous user. For example, if you need to let Tom users have permission to upload files, you can modify the/etc/vsftpd/vusers_config/tom file, add the following options.
Anon_upload_enable={yes|no}
Anon_mkdir_write_enable={yes|no}
Anon_other_write_enable={yes|no}
Vsftpd+pam+mysql