pureftp集成mysql身份验证是将ftp用户信息保存到mysql数据库中,这样可以对大量的ftp服务器做集中管理,对用户帐号的维护只要通过mysql的操作就可以完成。
一、下载pureftp源代码,并确定mysql已经安装好
tar zxvf pure-ftpd-1.0.20.tar.gz cd pure-ftpd-1.0.20 ./configure --prefix=/usr/local/pureftpd \ --with-cookie \ --with-throttling \ --with-ratios \ --with-quotas \ --with-sysquotas \ --with-uploadscript \ --with-virtualhosts \ --with-virtualchroot \ --with-virtualchroot \ --with-diraliases \ --with-peruserlimits \ --with-language=simplified-chinese \ --with-mysql=/usr/local/mysql \ --with-paranoidmsg \ --with-altlog make make check make install mkdir -m 777 /usr/local/pureftpd/etc cp pureftpd-mysql.conf /usr/local/pureftpd/etc/pureftpd-mysql.conf cp configuration-file /pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.conf cp configuration-file/pure-config.pl /usr/local/pureftpd/bin/pure-config.pl
注意 –prefix=/usr/local/pureftpd 参数指定了pureftpd的安装路径 –with-mysql=/usr/local/mysql 参数指定了mysql的安装路径 –with-language=simplified-chinese 参数指定了服务器返回信息使用的语言
添加pureftpd为系统服务
# cp contrib/redhat.init /etc/init.d/pureftpd # vi /etc/init.d/pureftpd
修改18/19行
fullpath=/usr/local/sbin/$prog pureftpwho=/usr/local/sbin/pure-ftpwho
为:
fullpath=/usr/local/pureftpd/sbin/$prog pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho
修改24行
$fullpath /etc/pure-ftpd.conf --daemonize
为
$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize # chmod 755 /etc/init.d/pureftpd # chkconfig --add pureftpd # chkconfig pureftpd on
修改配置文件
# vi /usr/local/pureftpd/etc/pure-ftpd.conf
其中可以修改最大连接数、空闲时间等,详细介绍见http://everspring.blog.bitsCN.com/497193/104618
其中有几项要修改:
chrootEveryone yes 限定在自己的家目录
NoAnonymous yes 不允许匿名登录
Bind 127.0.0.1,21 监听本机回环
Bind 192.168.0.254,21 监听本机IP
CreateHomeDir yes 允许用户登录后自动创建家目录
如果启用了iptables,还必须修改下面这一行:
PassivePortRange 30000 50000保存退出。
iptables开启相关端口:
iptables -I INPUT -p tcp --dport 21 -j ACCEPT iptables -I INPUT -p tcp --dport 30000:50000 -j ACCEPT
/etc/rc.d/init.d/iptables save
二、建立mysql认证数据库表
在mysql服务器中建立pureftpd数据库
mysql>CREATE DATABASE pureftpd; mysql>grant all on pureftpd.* to pureftpd@"localhost" identified by 'pureftpd'; mysql>use pureftpd; mysql>CREATE TABLE `users` ( `id` int(32) unsigned NOT NULL auto_increment, `User` varchar(16) NOT NULL default '', `Password` varchar(64) NOT NULL default '', `Uid` varchar(11) NOT NULL default '-1', `Gid` varchar(11) NOT NULL default '-1', `Dir` varchar(128) NOT NULL default '', `QuotaSize` smallint(5) NOT NULL default '0', `QuotaFiles` int(11) NOT NULL default '0', `ULBandwidth` smallint(5) NOT NULL default '0', `DLBandwidth` smallint(5) NOT NULL default '0', `ULRatio` smallint(6) NOT NULL default '0', `DLRatio` smallint(6) NOT NULL default '0', `comment` tinytext NOT NULL, `ipaccess` varchar(15) NOT NULL default '*', `status` enum('0','1') NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `modify_date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`,`User`), UNIQUE KEY `User` (`User`) ) TYPE=MyISAM AUTO_INCREMENT=5 ;
三、建立用于pureftpd认证用户的系统信息
建立用于pureftpd认证用户和ftp服务器根目录
创建专门用于上传文件的用户
groupadd download -g 2000 useradd download -u 2000 -g download -s /sbin/nologin
创建专门用于下载的用户
groupadd upload -g 2001 useradd upload -u 2001 -g download -s /sbin/nologin mkdir /ftproot chown -R upload /ftproot //让upload用户作为ftp根目录的属主 chgrp -R download /ftproot //让download用户为ftp根目录的属组 chmod 750 /ftproot //让upload用户拥用所有权限,让download用户只有读权限
四、修改pureftpd的配置文件
修改pureftp主配置文件
vi /usr/local/pureftpd/etc/pure-ftpd.conf
ChrootEveryone yes BrokenClientsCompatibility no MaxClientsNumber 50 Daemonize yes MaxClientsPerIP 8 VerboseLog yes DisplayDotFiles yes AnonymousOnly no NoAnonymous no SyslogFacility DontResolve yes MaxIdleTime 15 # 在使用ls命令时显示的最多的文件个数,该选项有两个参数第一个是文件数,第二个是目录深度 LimitRecursion 10000 8 AnonymousCanCreateDirs no MaxLoad 4 PassivePortRange 30000 50000 使用被动模式,被动端口的范围是30000到50000 AntiWarez yes UserBandwidth 1000 Umask 133:022 MinUID 100 AllowUserFXP no AllowAnonymousFXP no ProhibitDotFilesWrite no ProhibitDotFilesRead no AutoRename no AnonymousCantUpload yes 禁止匿名用户上传 CreateHomeDir no 禁止登录用户自动创建家目录 PIDFile /var/run/pure-ftpd.pid MaxDiskUsage 99 CustomerProof yes
修改pureftp mysql认证文件
vi /usr/local/pureftpd/etc/pureftpd-mysql.conf
MYSQLServer 127.0.0.1 MYSQLPort 3306 MYSQLUser pureftpd MYSQLPassword pureftpd MYSQLDatabase pureftpd MYSQLCrypt cleartext 密码在数据表中的存储方式,这里选择明文用cleartext、加密使用crypt MYSQLGetPW SELECT Password FROM users WHERE User='\L' MYSQLGetUID SELECT Uid FROM users WHERE User='\L' MYSQLGetGID SELECT Gid FROM users WHERE User='\L' MYSQLGetDir SELECT Dir FROM users WHERE User='\L' MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User='\L' MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User='\L'
五、运行pureftpd
添加upload用户,用户名可以任意,但是要对应系统用户的的uid和gid,以获取文件系统的的相关权限
INSERT INTO `users` VALUES (1, 'download','download', '2000', '2000', '/ftproot', 0, 0, 0, 0, 0, 0, '','*', '1', '2013-06-24 16:10:00', '2013-06-24 16:10:00');
添加download用户
INSERT INTO `users` VALUES (2, 'upload','upload', '2001', '2001', '/ftproot', 0, 0, 0, 0, 0, 0, '','*', '1', '2013-06-24 16:10:00', '2013-06-24 16:10:00');
运行pureftpd服务器
/usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
现在在客户端使用浏览器打开http://服务器IP:21 使用用户upload和download测试登录
六、用facl实现相同目录不同用户使用不同访问权限
chown -R upload:upload /ftproot chomod 700 /ftproot setfacl -R d:u:download:rx /ftproot
后以后创建的子目录和子文件继承facl
setfacl -R u:download:rx /frptoot
让当前目录的facl生效
Pureftp表字段说明
CREATE TABLE IF NOT EXISTS `ftpd` ( `User` varchar(16) NOT NULL DEFAULT ” COMMENT ‘用户名', `status` enum(‘0′,'1′) NOT NULL DEFAULT ‘0' COMMENT ‘可用状态:0 – 不可用;1 – 正在使用', `Password` varchar(64) NOT NULL DEFAULT ” COMMENT ‘密码', `Uid` varchar(11) NOT NULL DEFAULT ‘-1′ COMMENT ‘用户ID', `Gid` varchar(11) NOT NULL DEFAULT ‘-1′ COMMENT ‘组ID', `Dir` varchar(128) NOT NULL DEFAULT ” COMMENT ‘拥有的权限路径', `ULBandwidth` smallint(5) NOT NULL DEFAULT ‘0' COMMENT ‘上传带宽', `DLBandwidth` smallint(5) NOT NULL DEFAULT ‘0' COMMENT ‘下载带宽', `comment` tinytext NOT NULL COMMENT ‘备注', `ipaccess` varchar(15) NOT NULL DEFAULT ‘*' COMMENT ‘IP地址', `QuotaSize` smallint(5) NOT NULL DEFAULT ‘0' COMMENT ‘大小配额', `QuotaFiles` int(11) NOT NULL DEFAULT ‘0' COMMENT ‘文件类型配额', PRIMARY KEY (`User`) ) ENGINE=MyISAM DEFAULT CHARSET=gbk COMMENT='ftp用户名密码表';
以上就是PureFTP借助MySQL实现用户身份验证的操作教程_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
