In this tutorial we’ll install the Debian Linux 9 (squeeze), Apache 2 with mpm-itk (to run each web as a isolated user),...
Pure-FTPd with MySQL backendadmin
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 [email protected] IDENTIFIED BY 'mypasswd';
CREATE DATABASE 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)
INSERT INTO users (user, password, home) VALUES ('username', MD5('mypasswd'), '/home/username');
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:
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:
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';
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:
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:
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!
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”
username password /home/web 0 0 any 0 0 yes
Would really appreciate if you had any ideas?
Thanks in advance.