环境 rhel 6.5
1.先安装好各软件
yum install gcc gcc-c++ vsftpd mysql-server openssl openssl-devel pam-devel pam mysql-devel make -y
2.创建mysql数据库
service mssql start
mysql -u root
SQL>create database vsftpd default charset utf8;
SQL>use vsftpd
SQL>create table users (
> id int unsigned not null primary key auto_increment,
-> name varchar(32) not null,
-> passwd varchar(64) not null ,
-> status boolean );
SQL> insert into user values (null,'vuser1',password('123'),true);
SQL> insert into user values (null,'vuser2',password('456'),true);
SQL> insert into user values (null,'vuser3',password('123'),false);
SQL> select * from vsftpd.user;
+----+--------+-------------------------------------------+--------+
| id | name | passwd | status |
+----+--------+-------------------------------------------+--------+
| 1 | vuser1 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 1 |
| 2 | vuser2 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 1 |
| 3 | vuser3 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | 0 |
+----+--------+-------------------------------------------+--------+
mysql> grant all on vsftpd.* to ftp@localhost identified by '123';
mysql> grant all on vsftpd.* to ftp@'127.0.0.1' identified by '123';
安装 pam-mysql 和创认证文件
# tar xjf pam_mysql-0.7RC1.tar.bz2
# cd pam_mysql-0.7RC1/
# ./configure --with-openssl --with-pam-mods-dir=/lib64/security/
# make
# make install
vim /etc/pam.d/vsfpd.mysql
auth required pam_mysql.so user=ftp passwd=123 host=localhost db=vsftpd table=user usercolumn=name passwdcolumn=passwd crypt=2 where=status=true
account required pam_mysql.so user=ftp passwd=123 host=localhost db=vsftpd table=user usercolumn=name passwdcolumn=passwd crypt=2 where=status=true
验证配置问家是否成功调用模块链接数据库验证提交用的用户帐号的有效性
# service saslauthd start
# testsaslauthd -s myftpd -u vuser1 -p 123
0: OK "Success."
# testsaslauthd -s myftpd -u vuser3 -p 123
0: NO "authentication failed"
安装并且配置vsftpd
# vim /etc/vsftpd/vsftpd.conf
pam_service_name=myftpd
guest_enable=YES
guest_username=nobody
user_sub_token=$USER
修改nobody的家目录
# usermod -d '/share/ftproot/$USER' nobody
# mkdir -p /share/ftproot/vuser{1,2,3}
# chown nobody:nobody -R /share/ftproot/vuser*
# service vsftpd restart
测试
登录之后,发现所有的虚拟帐号在上面的配置下,都只有匿名帐号的权限,只能下载,不能上传等写操作
升级配置:每个虚拟帐号都可以指定不能的权限
# vim /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/user_conf
# mkdir /etc/vsftpd/user_conf
# vim /etc/vsftpd/user_conf/vuser1
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_world_readable_only=NO
# service vsftpd restart
chkconfig vsftpd on
chkconfig mysqld on
chkconfig saslauthd on
chkconfig iptables off
禁用SELINUX
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29901741/viewspace-1507849/,如需转载,请注明出处,否则将追究法律责任。