PureFTP借助MySQL實(shí)現(xiàn)用戶身份驗(yàn)證的操作教程
pureftp集成mysql身份驗(yàn)證是將ftp用戶信息保存到mysql數(shù)據(jù)庫中,這樣可以對大量的ftp服務(wù)器做集中管理,對用戶帳號(hào)的維護(hù)只要通過mysql的操作就可以完成。
一、下載pureftp源代碼,并確定mysql已經(jīng)安裝好
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 參數(shù)指定了pureftpd的安裝路徑 –with-mysql=/usr/local/mysql 參數(shù)指定了mysql的安裝路徑 –with-language=simplified-chinese 參數(shù)指定了服務(wù)器返回信息使用的語言
添加pureftpd為系統(tǒng)服務(wù)
# 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
其中可以修改最大連接數(shù)、空閑時(shí)間等,詳細(xì)介紹見http://everspring.blog.51cto.com/497193/104618
其中有幾項(xiàng)要修改:
- chrootEveryone yes 限定在自己的家目錄
- NoAnonymous yes 不允許匿名登錄
- Bind 127.0.0.1,21 監(jiān)聽本機(jī)回環(huán) <可選>
- Bind 192.168.0.254,21 監(jiān)聽本機(jī)IP <自行添加的,非必須>
- CreateHomeDir yes 允許用戶登錄后自動(dòng)創(chuàng)建家目錄 <必須>
如果啟用了iptables,還必須修改下面這一行:
PassivePortRange 30000 50000保存退出。
iptables開啟相關(guān)端口:
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認(rèn)證數(shù)據(jù)庫表
在mysql服務(wù)器中建立pureftpd數(shù)據(jù)庫
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認(rèn)證用戶的系統(tǒng)信息
建立用于pureftpd認(rèn)證用戶和ftp服務(wù)器根目錄
創(chuàng)建專門用于上傳文件的用戶
groupadd download -g 2000 useradd download -u 2000 -g download -s /sbin/nologin
創(chuàng)建專門用于下載的用戶
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用戶擁用所有權(quán)限,讓download用戶只有讀權(quán)限
四、修改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命令時(shí)顯示的最多的文件個(gè)數(shù),該選項(xiàng)有兩個(gè)參數(shù)第一個(gè)是文件數(shù),第二個(gè)是目錄深度 LimitRecursion 10000 8 AnonymousCanCreateDirs no MaxLoad 4 PassivePortRange 30000 50000 使用被動(dòng)模式,被動(dòng)端口的范圍是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 禁止登錄用戶自動(dòng)創(chuàng)建家目錄 PIDFile /var/run/pure-ftpd.pid MaxDiskUsage 99 CustomerProof yes
修改pureftp mysql認(rèn)證文件
vi /usr/local/pureftpd/etc/pureftpd-mysql.conf
MYSQLServer 127.0.0.1 MYSQLPort 3306 MYSQLUser pureftpd MYSQLPassword pureftpd MYSQLDatabase pureftpd MYSQLCrypt cleartext 密碼在數(shù)據(jù)表中的存儲(chǔ)方式,這里選擇明文用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'
五、運(yùn)行pureftpd
添加upload用戶,用戶名可以任意,但是要對應(yīng)系統(tǒng)用戶的的uid和gid,以獲取文件系統(tǒng)的的相關(guān)權(quán)限
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');
運(yùn)行pureftpd服務(wù)器
/usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
現(xiàn)在在客戶端使用瀏覽器打開http://服務(wù)器IP:21 使用用戶upload和download測試登錄
六、用facl實(shí)現(xiàn)相同目錄不同用戶使用不同訪問權(quán)限
chown -R upload:upload /ftproot chomod 700 /ftproot setfacl -R d:u:download:rx /ftproot
后以后創(chuàng)建的子目錄和子文件繼承facl
setfacl -R u:download:rx /frptoot
讓當(dāng)前目錄的facl生效
Pureftp表字段說明
CREATE TABLE IF NOT EXISTS `ftpd` ( `User` varchar(16) NOT NULL DEFAULT ” COMMENT ‘用戶名', `status` enum(‘0′,'1′) NOT NULL DEFAULT ‘0' COMMENT ‘可用狀態(tài):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 ‘擁有的權(quán)限路徑', `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用戶名密碼表';
相關(guān)文章
Linux下mysql 5.6.17安裝圖文教程詳細(xì)版
這篇文章主要為大家詳細(xì)介紹了Linux下mysql 5.6.17安裝圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09MySQL無法重啟報(bào)錯(cuò)Warning: World-writable config file ‘/etc/my.cnf’
最近在維護(hù)公司服務(wù)器的時(shí)候,在關(guān)閉數(shù)據(jù)庫的命令發(fā)現(xiàn)mysql關(guān)不了了,提示錯(cuò)誤為Warning: World-writable config file '/etc/my.cnf' is ignored,通過查找網(wǎng)上的資料終于解決了,現(xiàn)在將解決的方法分享給大家,同樣遇到這個(gè)問題的朋友們可以參考借鑒。2016-12-12mysql查詢語句join、on、where的執(zhí)行順序
這篇文章主要介紹了mysql查詢語句join、on、where的執(zhí)行順序,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11MySQL的Redo Log數(shù)據(jù)恢復(fù)核心機(jī)制面試精講
這篇文章主要為大家介紹了MySQL的Redo Log數(shù)據(jù)恢復(fù)核心機(jī)制面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10