环境
mariadb-server:192.168.103.74
ftp:192.168.103.75
创建mysql数据库
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE vsftpd;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> USE vsftpd;
Database changed
MariaDB [vsftpd]> CREATE TABLE users (
-> id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
-> name CHAR(50) BINARY NOT NULL,
-> password CHAR(48) BINARY NOT NULL
-> );
Query OK, 0 rows affected (0.00 sec)
MariaDB [vsftpd]> INSERT INTO users(name,password) values('ftp_ptg',password('ptg123'));
Query OK, 1 row affected (0.00 sec)
MariaDB [vsftpd]> GRANT SELECT ON vsftpd.* TO vsftpd@'192.168.103.%' IDENTIFIED BY 'ptg123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [vsftpd]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [vsftpd]>
安装pam模块,并写入调用PAM模块参数
[root@localhost ~]# wget http://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz
--2021-05-22 17:16:36-- http://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz
Resolving prdownloads.sourceforge.net (prdownloads.sourceforge.net)... 216.105.38.13
Connecting to prdownloads.sourceforge.net (prdownloads.sourceforge.net)|216.105.38.13|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://downloads.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz [following]
--2021-05-22 17:16:40-- http://downloads.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz
Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.105.38.13
Reusing existing connection to prdownloads.sourceforge.net:80.
HTTP request sent, awaiting response... 302 Found
Location: https://nchc.dl.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz [following]
--2021-05-22 17:16:40-- https://nchc.dl.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz
Resolving nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)... 140.110.96.69, 2001:e10:ffff:1f02::17
Connecting to nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)|140.110.96.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 335240 (327K) [application/x-gzip]
Saving to: ‘pam_mysql-0.7RC1.tar.gz’
100%[============================================================================>] 335,240 308KB/s in 1.1s
2021-05-22 17:16:42 (308 KB/s) - ‘pam_mysql-0.7RC1.tar.gz’ saved [335240/335240]
[root@localhost ~]# tar xf pam_mysql-0.7RC1.tar.gz
[root@localhost ~]# cd pam_mysql-0.7RC1/
[root@localhost pam_mysql-0.7RC1]# ./configure --with-pam-mods-dir=/lib64/security
[root@localhost pam_mysql-0.7RC1]# make && make install
[root@localhost ~]# vi /etc/pam.d/vsftpd.mysql
auth required /lib64/security/pam_mysql.so user=vsftpd passwd=ptg123 host=192.168.103.74 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 table=users usercolumn=name passwdcolumn=password crypt=2
account required /lib64/security/pam_mysql.so user=vsftpd passwd=ptg123 host=192.168.103.74 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
vsftp调用参数
[root@localhost ~]# vi /etc/vsftpd/vsftpd.conf
userlist_enable=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=vuser
pam_service_name=vsftpd.mysql
测试
[root@localhost ~]# ftp 192.168.103.75
Connected to 192.168.103.75 (192.168.103.75).
220 (vsFTPd 3.0.2)
Name (192.168.103.75:root): ftp_ptg
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>