一、yum安装vsftpd,mysql
# yum -y install vsftpd mysql-server mysql-devel
# mkdir tools
# cd tools/
# tar xf pam_mysql-0.7RC1.tar.gz
# cd pam_mysql-0.7RC1
# ./configure --with-mysql=/usr --with-openssl
# make && make install
注:也可使用yum安装pam_mysql |
备注:
--with-openssl在这里可有可无,若有的话,一定要确保其devel包已经安装了
[root@localhost ~]# rpm -q openssl-devel
openssl-devel-1.0.0-27.el6.x86_64
configure报错:
configure: error: Cannot find pam headers. Please check if your system is ready for pam module development.
解决办法:yum -y install pam-*或yum -y install pam pam-devel
|
这是一个32位的pam库,不过它可以兼容64位
[root@localhost pam_mysql-0.7RC1]# ll /lib/security/
total 140
-rwxr-xr-x 1 root root 876 Apr 2 03:38 pam_mysql.la
-rwxr-xr-x 1 root root 138572 Apr 2 03:38 pam_mysql.so
下面我们将为其创建软连接至64位库中,方便使用
[root@localhost pam_mysql-0.7RC1]# ln -sv /lib/security/pam_mysql.so /lib64/security/
`/lib64/security/pam_mysql.so' -> `/lib/security/pam_mysql.so'
[root@localhost pam_mysql-0.7RC1]# cd
|
[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql
mysql> create database vsftpd;
mysql> grant all on vsftpd.* to 'vsftpd'@'localhost' identified by 'vsftpd';
mysql> grant all on vsftpd.* to 'vsftpd'@'127.0.0.1' identified by 'vsftpd';
mysql> flush privileges;
mysql> exit
Bye
|
[root@localhost ~]# mysql -uvsftpd -hlocalhost -p'vsftpd'
mysql> show databases;
mysql> use vsftpd;
mysql> create table users (
-> id int AUTO_INCREMENT NOT NULL,
-> name char(20) binary NOT NULL,
-> password char(48) binary NOT NULL,
-> primary key(id)
-> );
mysql> insert into users (name,password) values ('tom','mageedu'),('jerry','mageedu');
mysql> \q
Bye
|
auth required /lib64/security/pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
account required /lib64/security/pam_mysql.so user=vsftpd passwd=vsftpd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=0
|
# useradd -s /sbin/nologin -d /var/ftproot vuser
# chmod go+rx /var/ftproot
|
anonymous_enable=YES #启用匿名用户,因为所有的虚拟用户也都是匿名用户
local_enable=YES
#启用本地用户,因为所有的虚拟用户都会被映射成本地用户
write_enable=YES
#此项可有可无
anon_upload_enable=NO #是否启用匿名用户上传的权限,NO表示不启用,此项可有可无
anon_mkdir_write_enable=NO #此项可有可无
chroot_local_user=YES #此项可有可无
|
guest_enable=YES #启用虚拟用户
guest_username=vuser
#虚拟用户映射的系统用户
|
pam_service_name=vsftpd.mysql #vsftpd的pam认证文件名称 |
user_config_dir=/etc/vsftpd/vusers |
# cd /etc/vsftpd/
# mkdir vusers
# vim tom
anon_upload_enable=NO
# vim jerry
anon_upload_enable=YES
anon_other_write_enable=YES
# service vsftpd restart #重启服务是操作生效
|