Installing PureFTPd with MySQL Backend on Gentoo


The FTP accounts will be stored in a mysql database table. First let's install pureftpd:

USE="pam ssl mysql" emerge pure-ftpd

Once the installation is finished, there are 2 main configuration files in /etc/conf.d.

/etc/conf.d/pure-ftpd

IS_CONFIGURED="yes" # the server does not start up if set to no
SERVER="-S 21" # server port
MAX_CONN="-c 30" # maximum number of concurrent connections
MAX_CONN_IP="-C 10" # like MAX_CONN, but per IP
DAEMON="-B" # run as daemon ("-D") or in background ("-B")?
DISK_FULL="-k 90%" # prevent uploads if the current partition is more than 90% full
# USE_NAT="-N" # you might want to use nat
AUTH="-l mysql:/etc/conf.d/pure-ftpd-mysql" # authentication via mysql
# TIMEOUT="-I <timeout>'" # max. idle time
# LOG="-f syslog" # which log facility to use
MISC_OTHER="-A -j -u 80 -p 50000:65535 -P 123.45.67.89" # change the IP to the IP which the server shall be listening on
# More details here: "http://pureftpd.sourceforge.net/README"

/etc/conf.d/pure-ftpd-mysql

MYSQLServer     123.45.67.89
#MYSQLSocket    /var/run/mysqld/mysqld.sock
MYSQLUser       ftp
MYSQLPassword   XXXXXXXX
MYSQLDatabase   pureftpd
MYSQLCrypt      MD5
MYSQLGetPW      SELECT Password FROM pureftpd WHERE User="L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetUID     SELECT Uid FROM pureftpd WHERE User="L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetGID     SELECT Gid FROM pureftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MYSQLGetDir     SELECT Dir FROM pureftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetBandwidthUL SELECT ULBandwidth FROM pureftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetBandwidthDL SELECT DLBandwidth FROM pureftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLGetQTASZ   SELECT QuotaSize FROM pureftpd WHERE User="L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "R")
MySQLTransactions Off

Then create the corresponding database and table:

CREATE DATABASE pureftpd;
GRANT ALL ON pureftpd.* TO 'ftp'@'123.45.67.89' IDENTIFIED BY 'XXXXXXXX';
FLUSH PRIVILEGES;
USE pureftpd;
CREATE TABLE `users` (
  `User` varchar(50) NOT NULL default '',
  `Password` varchar(64) binary NOT NULL default '',
  `Uid` int(11) NOT NULL default '2100',
  `Gid` int(11) NOT NULL default '2100',
  `Dir` varchar(128) NOT NULL default '/home/pureftpd',
  `QuotaFiles` int(10) NOT NULL default '5000',
  `QuotaSize` int(10) NOT NULL default '30000',
  `ULBandwidth` int(10) NOT NULL default '80',
  `DLBandwidth` int(10) NOT NULL default '80',
  `Ipaddress` varchar(15) NOT NULL default '*',
  `Comment` tinytext,
  `Status` enum('0','1') NOT NULL default '1',
  `ULRatio` smallint(5) NOT NULL default '1',
  `DLRatio` smallint(5) NOT NULL default '1',
  PRIMARY KEY  (`User`),
  UNIQUE KEY `User` (`User`)
) TYPE=MyISAM;

Then restart PureFTPd: /etc/init.d/pure-ftpd restart

Now just insert the new ftp accounts into the mysql table to create them.