基于数据库存放ftp虚拟账户
使用文本比较low
使用mysql备份和管理更方便
使用8.0没有加密函数,不能加密
基于pam模块连接数据库实现
pam_mysql模块系统默认没有
cnetOS8上不支持
数据库CHAR默认不支持区别大小写需要加binary
环境准备
vsftp CentOS7 10.0.0.183
mysql(8.0以下) 或者mariadb 10.0.0.199
安装并部署数据库
安装数据库并设为开机启动
yum -y install mariadb-server.x86_64
systemctl enable --now mariadb.service
在数据库中创建ftp虚拟用户数据库和表
MariaDB [ ( none) ] > create database vsftpd;
Query OK, 1 row affected ( 0.00 sec)
MariaDB [ vsftpd] > create table users(
-> id int auto_increment not null primary key,
-> name char( 50 ) binary not null,
-> passwd char( 50 ) binary not null) ;
Query OK, 0 rows affected ( 0.00 sec)
MariaDB [ vsftpd] > create table ftper(
-> id int auto_increment not null primary key,
-> uname char( 50 ) binary not null,
-> passwd char( 50 ) binary not null) ;
Query OK, 0 rows affected ( 0.00 sec)
表中插入行,创建ftp用户和对应密码
MariaDB [ vsftpd] > insert into users( name,passwd) values( 'a' ,passwd( 'aaaaaa' )) ;
Query OK, 1 row affected ( 0.01 sec)
MariaDB [ vsftpd] > insert into users( name,passwd) values( 'b' ,passwd( 'bbbbbb' )) ;
Query OK, 1 row affected ( 0.00 sec)
添加虚拟用户,为了安全应该使用passwd函数加密其密码后存储
MariaDB [ vsftpd] > insert into ftper( uname,passwd) values( 'a' ,'aaaaaa' ) ;
Query OK, 1 row affected ( 0.00 sec)
MariaDB [ vsftpd] > insert into ftper( uname,passwd) values( 'b' ,'bbbbbb' ) ;
Query OK, 1 row affected ( 0.01 sec)
使用使用passwd函数和不使用插入数据的结果明显不同
MariaDB [ vsftpd] > select * from users ;
+----+------+-------------------------------------------+
| id | name | passwd |
+----+------+-------------------------------------------+
| 1 | a | *B1461C9C68AFA1129A5F968C343636192A084ADB |
| 2 | b | *43FF523A5DA566E2AA8F14756C0BBD08C522F5F1 |
+----+------+------