Pure-FTPd is a free and secure FTP server. It doesn’t provide useless bells and whistles, but focuses on efficiency and ease of use. It provides simple answers to common needs, plus unique useful features for personal users as well as hosting providers.

Advertisement

pure-ftpd-with-mysql

This how to guide will help you to setup Pure-FTPD with MySQL as user database. Also providing detailed instruction to create user and test.

Step 1: Install MySQL ( Skip if Already Have )

Firstly we need to install MySQL on our system using following steps of command.

# yum install mysql mysql-server

click here for detailed instruction’s for mysql installation.

Step 2: Install Pure-FTPD

Use following command to install pure-ftpd on your linux system.

# yum install pure-ftpd

Step 3: Create MySQL User and Database

After installation pure-ftpd package, lets create a mysql database, table and user for storing user information.

# mysql -u root -p
Enter password:

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

Step 4: Configure Pure-FTPD

We are going to 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 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 edit pure-ftpd mysql configuration file

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

and update following variables

   MYSQLUser       pureftpd
   MYSQLPassword   _password_
   MYSQLDatabase   pureftpd
   MYSQLCrypt      md5

Step 5: Test Pure-FTPD Setup

At this step we have completed pure-ftpd setup, Now we need to test our setup by creating our first ftp account. To test our setup, first we need to create an user in linux system. After that we will use that users UID and GID to create our virtual ftp accounts.

Create User Account:

# useradd demouser1
# passwd demouser1

Get UID and GID of this Account:

# cat /etc/passwd | grep demouser1
demouser1:x:504:505::/home/demouser1:/bin/bash

As per above output we found that usres UID is 504 and GID is 505.

Create FTP Account
Lets login to mysql server or access through phpMyAdmin and create your first account. For this tutorial, I am using command line.

# mysql -u root -p
Enter password:

mysql> INSERT INTO `users` (`User`, `Password`, `Uid`, `Gid`, `Dir`, `QuotaSize`,
`Status`, `ULBandwidth`, `DLBandwidth`, `Date`, `LastModif`)
VALUES ('ftpuser1', md5('_password_'), '504', '505', '/home/demouser1',
'20', 2, '10', '10', now(), '');
mysql> quit

As per above query we have successfully created our first ftp account ftpuser1 with password _password_,

Connect to FTP Server using newly created ftp account and try to upload a test file.

C:> ftp ftp.tecadmin.net

Connected to ftp.tecadmin.net.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 21:39. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
User (ftp.tecadmin.net:(none)): ftpuser1
331 User ftpuser1 OK. Password required
Password:
230 OK. Current restricted directory is /
ftp> put test.txt
200 PORT command successful
150 Connecting to port 57216
226-File successfully transferred
226 0.004 seconds (measured here), 0.65 Mbytes per second
ftp: 2593 bytes sent in 0.00Seconds 2593.00Kbytes/sec.
ftp> bye
221-Goodbye. You uploaded 3 and downloaded 0 kbytes.
221 Logout.
C:>

As per above results we have successfully connected to ftp user and uploaded a test file. Lets check the permissions of that files on server.

# ls -l /home/demouser1/test.txt
-rw-r--r-- 1 demouser1 demouser1 2525 Dec  4 21:39 /home/demouser1/test.txt

Now you can see that the files gets the permissions of that user which UID, GID we have used for that FTP accounts.

Share.

1 Comment

  1. i m getting an error in the centos 6 pureftpd souce code compilation with mysql parameter…..

    the configuration command i used is given below :-

    ./configure –prefix=/usr/local/pureftpd –with-mysql=/usr/local/lib/ –with-virtualhosts

    configure: error: Your MySQL client libraries aren’t properly installed

Leave A Reply


Exit mobile version