环境:两台主机,一台ftp 服务器, 一台mysql server
1 准备数据库
yum install mariadb-server
systemctl restart mariadb
create database vsftpd; 创建用户
use vsftpd
create table vuser;(忽略,下面是创建表的命令)
create table vuser (id int auto_increment primary key,username char(30),password char(50) binary);
insert vuser(username,password)values('ftp1',password('centos')),('ftp2',password('magedu'));
grant select on vsftpd.vuser to vsftpd@'192.168.36.7' identified by 'centos';
2 编译安装pam_mysql.so
1)yum install gcc gcc-c++ pam-devel mariadb-devel
2)tar xf pam_mysql-0.7RC1.tar.gz
cd pam_mysql-0.7RC1/
./configure --with-pam-mods-dir=/lib64/security
make && make install
ll /lib64/security/
3 创建pam配置文件
vim /etc/pam.d/vsftpd.mysql
auth required pam_mysql.so user=vsftpd passwd=centos host=192.168.36.17 db=vsftpd table=vuser usercolumn=username passwdcolumn=password crypt=2
account required pam_mysql.so user=vsftpd passwd=centos host=192.168.36.17 db=vsftpd table=vuser usercolumn=username passwdcolumn=password crypt=2
4 修改vsftpd配置,调用pam配置
vim /etc/vsftpd/vsftpd.conf
pam_service_name=vsftpd.mysql 修改此行
加下面三行
guest_enable=YES
guest_username=vuser
user_config_dir=/etc/vsftpd/vusers.d/