PureFTP借助MySQL完成用戶身份驗證的操作教程。本站提示廣大學習愛好者:(PureFTP借助MySQL完成用戶身份驗證的操作教程)文章只能為提供參考,不一定能成為您想要的結果。以下是PureFTP借助MySQL完成用戶身份驗證的操作教程正文
pureftp集成mysql身份驗證是將ftp用戶信息保留到mysql數據庫中,如許可以對年夜量的ftp辦事器做集中治理,對用戶帳號的保護只需經由過程mysql的操作便可以完成。
1、下載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.51cto.com/497193/104618
個中有幾項要修正:
假如啟用了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
2、樹立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 ;
3、樹立用於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用戶只要讀權限
4、修正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'
5、運轉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測試登錄
6、用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用戶名暗碼表';