PureFTP uses MySQL to implement user authentication,
Pureftp integrates mysql authentication to save ftp user information to the mysql database, which enables centralized management of a large number of ftp servers, to maintain a user account, you only need to perform mysql operations.
1. Download the source code of pureftp and confirm that mysql has been installed.
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-altlogmakemake checkmake installmkdir -m 777 /usr/local/pureftpd/etccp pureftpd-mysql.conf /usr/local/pureftpd/etc/pureftpd-mysql.confcp configuration-file /pure-ftpd.conf /usr/local/pureftpd/etc/pure-ftpd.confcp configuration-file/pure-config.pl /usr/local/pureftpd/bin/pure-config.pl
Note: The prefix =/usr/local/pureftpd parameter specifies the installation path of pureftpd-with-mysql =/usr/local/mysql parameter specifies the installation path of mysql-with-language = the simplified-chinese parameter specifies the language in which the server returns information.
Add pureftpd as System Service
# cp contrib/redhat.init /etc/init.d/pureftpd# vi /etc/init.d/pureftpd
Modify row 18/19
fullpath=/usr/local/sbin/$progpureftpwho=/usr/local/sbin/pure-ftpwho
Is:
fullpath=/usr/local/pureftpd/sbin/$progpureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho
Modify 24 rows
$fullpath /etc/pure-ftpd.conf --daemonize
Is
$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize# chmod 755 /etc/init.d/pureftpd# chkconfig --add pureftpd# chkconfig pureftpd on
Modify configuration file
# vi /usr/local/pureftpd/etc/pure-ftpd.conf
Which can modify the maximum number of connections, idle time, etc., see the http://everspring.blog.51cto.com/497193/104618 for details
There are several items to modify:
- ChrootEveryone yes is limited to your home directory
- NoAnonymous yes Anonymous Logon not allowed
- Bind 127.0.0.1, 21 listens to local loopback <optional>
- Bind 192.168.0.254, 21 listens to the local IP address <self-added, not required>
- CreateHomeDir yes allows users to automatically create home directories after logon <required>
-
If iptables is enabled, you must modify the following line:
PassivePortRange 30000 50000 save and exit.
Enable related ports in iptables:
iptables -I INPUT -p tcp --dport 21 -j ACCEPTiptables -I INPUT -p tcp --dport 30000:50000 -j ACCEPT
/etc/rc.d/init.d/iptables save
2. Create a mysql database table
Create a pureftpd database on the mysql server
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. Establish system information for users authorized by pureftpd
Create root directories for pureftpd Authenticated Users and ftp servers
Create a User Dedicated to uploading files
groupadd download -g 2000 useradd download -u 2000 -g download -s /sbin/nologin
Create a User Dedicated for download
Groupadd upload-g 2001 useradd upload-u 2001-g download-s/sbin/nologinmkdir/ftproot chown-R upload/ftproot // Let the upload user act as the master chgrp of the ftp root directory -R download/ftproot // set the download user to the chmod 750/ftproot group in the ftp root directory. // set the upload user to have all permissions, allow the download user to have only the read permission
4. modify the configuration file of pureftpd
Modify the master configuration file of pureftp
vi /usr/local/pureftpd/etc/pure-ftpd.conf
Optional values noMaxClientsNumber 50 Daemonize yesMaxClientsPerIP 8 VerboseLog yesDisplayDotFiles cannot exceed noSyslogFacility DontResolve yesMaxIdleTime 15 # the maximum number of files displayed when using the ls command. This option has two parameters: the first is the number, the second is the directory depth LimitRecursion 10000 8 AnonymousCanCreateDirs noMaxLoad 4 PassivePortRange 30000 50000 using the passive mode, the passive port range is 30000 to 50000 AntiWarez yesUserBandwidth 1000 Umask 133: 022 MinUID 100 AllowUserFXP guest noProhibitDotFilesRead noAutoRename noAnonymousCantUpload yes prohibit anonymous users from uploading CreateHomeDir no prohibit users from automatically creating home directories PIDFile/var/run/pure-ftpd.pidMaxDiskUsage 99 customerproyes
Modify the pureftp mysql authentication File
vi /usr/local/pureftpd/etc/pureftpd-mysql.conf
MYSQLServer 127.0.0.1MYSQLPort 3306 MYSQLUser pureftpdMYSQLPassword pureftpdMYSQLDatabase pureftpdMYSQLCrypt cleartext Password Storage Method in the data table, here cleartext and encryption are selected. Use cryptMYSQLGetPW 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. Run pureftpd
Add an upload user. The user name can be arbitrary, but the uid and gid of the corresponding system user must be used to obtain the relevant permissions of the file system.
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');
Add download user
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');
Run the pureftpd Server
/usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
Now open http: // server IP: 21 in the browser on the client and use upload and download to test logon.
6. Use facl to implement different access permissions for different users in the same directory
chown -R upload:upload /ftprootchomod 700 /ftprootsetfacl -R d:u:download:rx /ftproot
Sub-directories and sub-files created later inherit facl
setfacl -R u:download:rx /frptoot
Make the facl of the current directory take effect
Fields in the Pureftp table
Create table if not exists 'ftpd' ('user' varchar (16) not null default "COMMENT 'username', 'status' enum ('0', '1 ′) not null default '0' comment' available status: 0-unavailable; 1-In use ', 'Password' varchar (64) not null default "COMMENT 'Password ', 'uid' varchar (11) not null default'-1' COMMENT 'user id', 'gid' varchar (11) not null default'-1' COMMENT 'group id ', 'dir' varchar (128) not null default "comment' permission path ', 'ulbandwidth' smallint (5) not null default '0' comment' upload bandwid ', 'dlbandwidth' smallint (5) not null default '0' comment' download bandwidth', 'comment' tinytext not null comment' COMMENT ', 'ipaccess' varchar (15) not null default '* 'comment' IP address', 'quotasize 'smallint (5) not null default '0' comment' size quota', 'quotafiles' int (11) not null default '0' comment' file type quota ', primary key ('user') ENGINE = MyISAM default charset = gbk COMMENT = 'ftp username and password table ';
Articles you may be interested in:
- How to configure virtual user Disk Quota using PureFTPd + Mysql + PHP_Manager
- How to verify user permissions in MySQL
- Php + mysql authentication code