vsftpd服务器学习(四)——与mysql结合实现虚拟帐号登录

1。添加新用户

useradd -d /var/ftp/mysql -s /sbin/nologin virtual

 2。写mysql脚本,添加数据库与表

echo "drop database if exists ftp;
create database ftp;
use ftp;
create table users(name varchar(13) binary not null,passwd varchar(20) binary not null, primary key(name));
insert into users(name,passwd) values('lx','lx'),('eb','eb');
grant select on ftp.users to virtual@localhost identified by 'liumang';
flush privileges;" >> ftp.so

 mysql -u root -pala < ftp.so

测试本地用户能否查询数据库

mysql -u virtual -pliumang;
use ftp;
select * from users;

 3。安装pam_mysql.so

tar xvzf  pam_mysql-0.7RC1.tar.gz
cd pam_mysql-0.7RC1
./configure
make 
make install

此时在/usr/lib/security会有pam_mysql.so,将其复制到/lib/security(也可以不复制)。

注意要先安装mysql-devel,否则会报错。

4。新建pam服务

touch /etc/pam.d/mysql
echo "auth    required        pam_mysql.so    user=virtual    passwd=liumang  host=localhost  db=ftp  table=users     usercolumn=name passwdcolumn=passwd     crypt=0
account required        pam_mysql.so    user=virtual    passwd=liumang  host=localhost  db=ftp  table=users     usercolumn=name passwdcolumn=passwd     crypt=0  " >>/etc/pam.d/mysql

 如果上一步没有复制pam_mysql.so的话,上面的引用要写绝对路径。

5。配置vsftpd.conf

anonymous_enable=NO
local_enable=YES
local_umask=022
connect_from_port_20=YES
guest_enable=YES
guest_username=virtual
user_config_dir=/etc/vsftpd/user_conf2 //用户权限目录
write_enable=YES
pam_service_name=mysql
userlist_enable=YES
listen=YES
chroot_local_user=YES
tcp_wrappers=YES
xferlog_enable=YES
xferlog_std_format=YES
xferlog_file=/var/log/xferlog
vsftpd_log_file=/var/log/vsftpd.log
~                                       

 6。设置用户权限(可省略

mkdir /etc/vsftpd/user_conf2
cd /etc/vsftpd/user_conf2
touch user1 (文件名必须与用户名相同)
echo "anon_upload_enable=YES
......" >>user1
touch user2
.....

 7。重启vsftpd

你可能感兴趣的:(mysql,脚本,Security)