Setup Open Source Pure-FTPd with MySQL on CentOS/RedHat 6.x

Pure-FTPd is a free and secure FTP server. It provides efficiency and ease of use, simple answers to common needs, plus unique useful features for personal users as well as hosting providers.
This how to guide will help you to setup Pure-FTPd with MySQL as user database. Also providing detailed instruction to create a user and test it.

mysql-pureftpd

Setup Open Source Pure-FTPd with MySQL on CentOS/RedHat 6.x

System Requirements:

  • A CentOS/RHEL 6.x machine
  • Internet connection

Let’s begin:

Step 1 – Install MYSQL – Skip this step if MYSQL is already installed

Install mysql and mysql-server packages using the yum command.

# yum install mysql mysql-server

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

Install MySQL

Hit Y when prompt to verify installation.

Step 2 – Install Pure-FTPd on your Linux machine

Install Pure-FTPd using yum (the -y means Assume Yes):

# yum install pure-ftpd -y

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

Install Pure-FTPd on your Linux machine

Step 3 – Start MySQL server daemon and create MySQL user and database

Type the following command to start MySQL:

# /etc/init.d/mysqld start

Now log into your mysql server:

If it’s a fresh installation of MySQL then running the next command will log you in:

# mysql

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

Start MySQL server daemon and create MySQL user and database

If you had previous MySQL installation on your server then run:

# mysql -u root -p

And insert root’s password when prompt.

Now, let’s create the database, grant appropriate permissions and create the table, you can copy & paste the values:

mysql> CREATE DATABASE pureftpd;
mysql> GRANT ALL ON pureftpd.* to 'pureftpd'@'localhost' IDENTIFIED BY '_password_';
mysql> FLUSH PRIVILEGES;
mysql> use pureftpd;
mysql> CREATE TABLE `users` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`User` varchar(32) NOT NULL DEFAULT '',
`Password` varchar(64) NOT NULL DEFAULT '',
`Uid` int(3) NOT NULL DEFAULT '500',
`Gid` int(3) NOT NULL DEFAULT '500',
`Dir` varchar(255) NOT NULL DEFAULT '',
`QuotaSize` int(4) NOT NULL DEFAULT '50',
`Status` enum('0','1') NOT NULL DEFAULT '1',
`ULBandwidth` int(2) NOT NULL DEFAULT '100',
`DLBandwidth` int(2) NOT NULL DEFAULT '100',
`Date` date NOT NULL DEFAULT '0000-00-00',
`LastModif` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`),
UNIQUE KEY `User` (`User`),
KEY `Uid` (`Uid`),
KEY `Gid` (`Gid`),
KEY `Dir` (`Dir`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

mysql> quit

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

Step 4 – Configure Pure-FTPd

Configure pure-ftpd to store user login details in mysql database. First edit pure-ftpd main configuration file:

# vim /etc/pure-ftpd/pure-ftpd.conf

And make the following changes:

ChrootEveryone yes
MaxClientsNumber 50
MaxClientsPerIP 2
VerboseLog yes
AnonymousOnly no
NoAnonymous yes
MaxIdleTime 15
MySQLConfigFile /etc/pure-ftpd/pureftpd-mysql.conf
PAMAuthentication no
UnixAuthentication no

After making changes in pure-ftpd configuration, let’s edit pure-ftpd mysql configuration file:

# vim /etc/pure-ftpd/pureftpd-mysql.conf

And update the following values:

MYSQLCrypt md5
MYSQLDatabase pureftpd
MYSQLGetDir SELECT Dir FROM users WHERE User='\L'
MYSQLGetGID SELECT Gid FROM users WHERE User='\L'
MYSQLGetPW SELECT Password FROM users WHERE User='\L'
MYSQLGetUID SELECT Uid FROM users WHERE User='\L'
MYSQLPassword password
MYSQLSocket /var/lib/mysql/mysql.sock
MYSQLUser pureftpd

Replace with the password you’ve set in Step 3 inside mysql server.

Step 5 – Create a system user

At this step, we have completed pure-ftpd setup.

Now we need to test our setup by creating a ftp account. To do that we need to create a system user in Linux and then we will use that user’s UID and GID to create our virtual ftp account.

Create a user account and set it’s password:

# useradd itaig
# passwd itaig

Get UID and GID of the user’s account:

# grep itaig /etc/passwd
itaig:x:500:500::/home/itaig:/bin/bash

itaig:x:500:500::/home/itaig:/bin/bash

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

You can see that both UID and GID of the user is 500 .

Step 6 – Create a FTP account

Let’s login to mysql server again:

# mysql

or

# mysql -u root -p

Then, select the pureftpd database:

mysql> use pureftpd

Copy & paste the command which creates the virtual account:

mysql> INSERT INTO `users` (`User`, `Password`, `Uid`, `Gid`, `Dir`, `QuotaSize`,
`Status`, `ULBandwidth`, `DLBandwidth`, `Date`, `LastModif`)
VALUES ('itaig', md5('geekkb'), '500', '500', '/home/itaig',
'20', 2, '10', '10', now(), '');
mysql> quit

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

Step 7 – Testing our pure-ftpd setup

Using the username and password you inserted into mysql in the previous step, open a FTP session to the server and try logging in:

# ftp localhost

Example:

How to: Setup Pure-FTPd with MySQL on CentOS/RedHat 6.x - Geek-KB.com

You can see in the example that I’ve connected to the local ftp server using the credentials I inserted to mysql in the previous step and I’ve downloaded successfully a file called geek-kb.com from there.

I hope you liked this article, please feel free to leave comments or ask questions.

Comments

comments

Leave a Comment

You must be logged in to post a comment.