Platform: Red Hat RHEL5 + VSFTPD + MySQL
1. Install MySQL
Mysql-5.1.7-beta-linux-i686-glibc23.tar.gz
# Tar zxvf mysql-5.1.7-beta-linux-i686-glibc23.tar.gz
# Ln-s mysql-5.1.7-beta-linux-i686-glibc23/usr/local/mysql
# Cd/usr/local/mysql
# Scripts/mysql_install_db -- user = mysql
# Chown-R root.
# Chown-R mysql data
# Chgrp-R mysql.
# Bin/mysqld_safe &
# Bin/mysql
Mysql>
Ii. Install pam_mysql.so
Pam_mysql-0.7RC1.tar.gz //: chinaunix
# Tar zxvf pam_mysql-0.7RC1.tar.gz
# Cd pam_mysql-0.7RC1
#./Configure -- with-mysql =/usr/local/mysql
# Make clean install
# Cp/usr/lib/security/pam_mysql.so/lib/security/
3. Install vsftpd
Use rpm to install the vsftpd rpm package that comes with EL5.
4. Create a virtual user
# Useradd-d/home/vftp-s/bin/nologin vftp-m
5. Establish Authentication
Create a user using mysql
Put the user name and password in the mysql library, and the implementation is quite simple.
(1) Create a database and set the corresponding Permissions
# Mysql-p
Mysql> create database ftpd;
Mysql> use ftpd;
Mysql> create table user (name char (20) binary, passwd char (20) binary );
Mysql> insert into user (name, passwd) values ('Mike ', '123 ');
Mysql> insert into user (name, passwd) values ('Tom ', '123 ');
Mysql> grant select, insert on ftpd. user to vftp @ localhost identified by '123 ';
Mysql> flush privileges; refresh permission settings
Mysql> quit
(2) create PAM Authentication Information
# Vi/etc/pam. d/vftp. The content is as follows:
Auth required/lib/security/pam_mysql.so user = vftp passwd = 123 host = localhost db = ftpd table = user usercolumn = name passwdcolumn = passwd crypt = 0
Account required/lib/security/pam_mysql.so user = vftp passwd = 123 host = localhost db = ftpd table = user usercolumn = name passwdcolumn = passwd crypt = 0
Note:
Crypt = n
Crypt = 0: plaintext Password
Crypt = 1: Use the crpyt () function (corresponding to encrypt () in SQL data, encrypt () to randomly generate salt)
Crypt = 2: Use the password () function in MYSQL to encrypt data.
Crypt = 3: Indicates md5 hash.
6. Modify the ftp configuration file
Vi/etc/vsftpd. conf
Pam_service_name = vftp
Guest_enable = YES
Guest_username = vftp
VII. Verification
Log on to ftp as mike and tom