Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Categories


Pure-FTPd with MySQL backend

adminadmin

Pure-FTPd is a free, secure, production-quality and standard-conformant 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.

In this tutorial we’ll install Pure-FTPd with MySQL backend.

Install Pure-FTPd with mysql backend
apt-get install pure-ftpd-mysql

Create user and group used to run the ftp server
groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser

Create database and a table that will store user information
mysql -u root -p
GRANT SELECT ON ftpd.* TO vhosts@localhost IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;
CREATE DATABASE ftpd;
USE ftpd;
 
CREATE TABLE users (
user varchar(30) NOT NULL,
password varchar(64) NOT NULL,
home varchar(128) NOT NULL,
bandwidth_limit_upload smallint(5) NOT NULL default 0,
bandwidth_limit_download smallint(5) NOT NULL default 0,
ip_allow varchar(15) NOT NULL default 'any',
quota smallint(5) NOT NULL default '0',
quota_files int(11) NOT NULL default 0,
active enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (user),
UNIQUE KEY User (user)
) TYPE=MyISAM;
 
INSERT INTO users (user, password, home) VALUES ('username', MD5('mypasswd'), '/home/username');
 
quit;

You will be able to control bandwidth limits and quotas for each user. Using zero for these fields will allow unlimited use of resources. The bandwidth limits are specified in KB/s and the quota in MB.

Configure Pure-ftpd (pico /etc/pure-ftpd/db/mysql.conf). Remove everything from the default configuration file and add these lines:
MYSQLSocket /var/run/mysqld/mysqld.sock
MYSQLUser vhosts
MYSQLPassword mypasswd
MYSQLDatabase ftpd
MYSQLCrypt md5
MYSQLDefaultUID 2001
MYSQLDefaultGID 2001
MYSQLGetPW SELECT password FROM users WHERE user = "\L" AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MYSQLGetDir SELECT home FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetBandwidthUL SELECT bandwidth_limit_upload FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetBandwidthDL SELECT bandwidth_limit_download FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetQTASZ SELECT quota FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")
MySQLGetQTAFS SELECT quota_files FROM users WHERE user = "\L"AND active = "yes" AND (ip_allow = "any" OR ip_allow LIKE "\R")

Create these simple text files that will force the server to create home directories for users if they don’t exist and chroot the user to it’s home directory:

pico /etc/pure-ftpd/conf/ChrootEveryone
yes

pico /etc/pure-ftpd/conf/CreateHomeDir
yes

Since we are using pure-ftpd-mysql insted of pure-ftpd, make the following change (pico /usr/sbin/pure-ftpd-wrapper):
my $daemon = '/usr/sbin/pure-ftpd-mysql';

Restart Pure-ftpd
/etc/init.d/pure-ftpd-mysql restart

We’re all done. You should be able to make connections to the servers with your favorite FTP client.

Update – 29th October 2008

I’ve had problems with debian-minimal installations where the ftp server simply won’t start and doesn’t leave any trace in the log files. To fix that I had to make one minor change to the inetd config file (pico /etc/inetd.conf):

ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/pure-ftpd-mysql

Open the config file and in the ftp line, change pure-ftpd-wrapper to pure-ftpd-mysql

When done, restart inetd:

/etc/init.d/openbsd-inetd restart

Update – 20th April 2010

In lenny, use this command to restart the service or change the variable STANDALONE_OR_INETD to standalone in /etc/default/pure-ftpd-common:

/etc/init.d/openbsd-inetd restart

Comments 11
  • fantasio
    Posted on

    fantasio fantasio

    Author

    perfect


  • Alex
    Posted on

    Alex Alex

    Author

    Your blog is interesting!

    Keep up the good work!


  • fantasio
    Posted on

    fantasio fantasio

    Author

    you are updated your article but it doesn’t work.Because you’ve changed “” ‘
    active enum(’yes’,’no’) NOT NULL default ‘yes’,
    active enum(‘yes’,’no’) NOT NULL default ‘yes’ as you can see ‘ symbol different both sql clause .


  • admin
    Posted on

    admin admin

    Author

    Thanks fantasio, I’ve updated the article.


  • Josh Rosenbaum
    Posted on

    Josh Rosenbaum Josh Rosenbaum

    Author

    1st off, great article, very straightforward and well written! Easy to follow!

    I’m not sure if you’re still taking questions, but if you are: I’m trying to change the “home” directory for the ftp folders to a different partition. I have a 2nd hard drive that I want the folders to be created on. The goal would be to have sites go to /ftp/ftpsites/username and that’s what I put in in the last INSERT INTO step (changed from /home/username/

    Is that the only location I’d need to change to the new setting? If so then I’ve got other issues ’cause the user’s sub folder isn’t being created. I’ve made sure that rights to that partition are 777 so I don’t think its a rights issue, but it may be.

    Thanks in advance for your help, and again great article!

    -Josh


  • admin
    Posted on

    admin admin

    Author

    Thank you Josh.

    You only need to set the home directory in the MySql row and you should be able to use directories on other partitions.

    I did some tests and learned that Pure-FTPd requiers both user and group owners to have full control to the parent directory. Can you run these commands and try again:

    chown ftpuser.ftpgroup /ftp/ftpsites
    chmod 775 /ftp/ftpsites


  • Josh Rosenbaum
    Posted on

    Josh Rosenbaum Josh Rosenbaum

    Author

    YOU ROCK!!!! It was a rights issue, those two lines just made my week! Thank you!


  • joey
    Posted on

    joey joey

    Author

    can someone tell me where to disable the DNS look up ???

    Can find it man!

    But the tutorial was great every thing is working 😉


  • t3ch
    Posted on

    t3ch t3ch

    Author

    Thanks a lot for the guide, explained nice and fast. 🙂

    I’m having one problem tho. I can connect to the FTP with anonymous, which i btw don’t want to allow, but the real problem is, i can’t connect with the users i’ve created in MySQL. Did exactly like explained in the guide.

    I’m running pure-ftpd under Debian-Lenny-5-64.

    I have created a user in the database ftpd under “users”

    Example:

    username password /home/web 0 0 any 0 0 yes

    Would really appreciate if you had any ideas?

    Thanks in advance.


  • t3ch
    Posted on

    t3ch t3ch

    Author

    I tried adding log=/var/lib/mysql/general.log to my.cnf and restarted mysql and pureftpd.

    The login tries from ftp client aint showing in general.log, so i seem to have a problem connecting to MySQL somehwere, just can’t figure it out.


  • Shen
    Posted on

    Shen Shen

    Author

    BEST pure ftpd tutorial ever!