Ubuntu: Installing PureFTPd with MySQL support
by admin on Apr.13, 2011, under Linux (Ubuntu)
1. Install PureFTPd, the MySQL-Server, MySQL-Client as well as the development libraries:
apt-get install pure-ftpd-mysql apt-get install mysql-client apt-get install mysql-server apt-get install libmysqlclient15-dev
2. Create a new group (GID 2001) und a user (UID 2001). All virtual users you will later create in your MySQL database will later receive the same permissions as this user.
groupadd -g 2001 ftpgroup useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser
3. Now it’s time to configure PureFTPd. First of all, backup the original configuration file, then clear it and finally edit it with the text editor vim:
cp /etc/pure-ftpd/db/mysql.conf /etc/pure-ftpd/db/mysql.conf_orig cat /dev/null > /etc/pure-ftpd/db/mysql.conf vi /etc/pure-ftpd/db/mysql.conf
4. The file is empty. Push the A-Button (or I-Button) in order to insert text. Then right click to paste the following text:
MYSQLSocket /var/run/mysqld/mysqld.sock MYSQLUser mysqlUser MYSQLPassword mysqlPassword MYSQLDatabase pureftpd MYSQLCrypt md5 MYSQLGetPW SELECT Password FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MYSQLGetUID SELECT Uid FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MYSQLGetGID SELECT Gid FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MYSQLGetDir SELECT Dir FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R") MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
Don’t forget to replace mysqlUser and mysqlPassword with your own MySQL username and password.
5. Save the file
6. chroot all PureFTPd users:
echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone
8. Create the home directory for each user in case it does not exist:
echo "yes" > /etc/pure-ftpd/conf/CreateHomeDir
9. Restart PureFTPd:
/etc/init.d/pure-ftpd-mysql restart
PureFTPd is now configured properly. Now it’s time to create the database structure and FTP accounts.
Login to your MySQL server via the terminal:
mysql -u root -p
Create the database pureftpd:
CREATE DATABASE pureftpd; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO ‘pureftpd’@'localhost’ IDENTIFIED BY ‘ftpdpass’; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO ‘pureftpd’@'localhost.localdomain’ IDENTIFIED BY ‘ftpdpass’; FLUSH PRIVILEGES;
Now it’s time to create the users table:
USE pureftpd; CREATE TABLE ftpd ( User varchar(16) NOT NULL default '', status enum('0','1') NOT NULL default '0', 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 '', ULBandwidth smallint(5) NOT NULL default '0', DLBandwidth smallint(5) NOT NULL default '0', comment tinytext NOT NULL, ipaccess varchar(15) NOT NULL default '*', QuotaSize smallint(5) NOT NULL default '0', QuotaFiles int(11) NOT NULL default 0, PRIMARY KEY (User), UNIQUE KEY User (User) ) TYPE=MyISAM;
And finally create an FTP user:
INSERT INTO `pureftpd`.`ftpd` ( `User` , `status` , `Password` , `Uid` , `Gid` , `Dir` , `ULBandwidth` , `DLBandwidth` , `comment` , `ipaccess` , `QuotaSize` , `QuotaFiles` ) VALUES ( 'user1', '1', MD5( 'user1' ) , '2001', '2001', '/home/user1/', '0', '0', '', '*', '0', '0' );
You may now close the mysql client by entering the command
QUIT;
or continue adding users. The first working FTP user in my example will be user1, his password will be user1 and he will have access to the directory /home/user1/.
September 23rd, 2011 on 21:42
Well I definitely liked reading it. This post provided by you is very effective for proper planning.