GenerationIP

Just for you

  • Increase font size
  • Default font size
  • Decrease font size
Home Documentation Howto Howto install pure-ftpd with a database mysql or postgresql

Howto install pure-ftpd with a database mysql or postgresql

E-mail Print PDF
User Rating: / 8
PoorBest 

Type : System
Operating System : Redhat,Fedora,Centos

This howto explain how to install pure-ftpd on redhat, centos or fedora core server.

Pure-ftpd is a very simple FTP server and can be used with mysql, postgreSQL or LDAP.


INSTALLATION

If you have add the good repositry on your server you have to do a yum install of the package :

# yum install pure-ftpd

But in the case of you repositry don't allow pure-ftpd rpm, you have to download the good package on http://rpm.pbone.net

# rpm -i pure-ftpd

Now you package is ready for the configuration.

 

CONFIGURATION

Now you FTP server is install and you can find all configuraiton file in this folder :

# cd /etc/pure-ftpd

# ls -al
total 36
drwxr-xr-x 2 root root 4096 Jan 12 13:44 .
drwxr-xr-x 82 root root 4096 Feb 28 04:03 ..
-rw-r--r-- 1 root root 11084 Jan 12 13:38 pure-ftpd.conf
-rw-r--r-- 1 root root 1448 Oct 2 2002 pureftpd-ldap.conf
-rw-r--r-- 1 root root 3517 Jan 12 13:44 pureftpd-mysql.conf
-rw-r--r-- 1 root root 2899 Jul 31 2004 pureftpd-pgsql.conf

 

  • Without database

Now we start the configuration of pureftpd without databases:

#vi pure-ftpd.conf

# Cage in every user in his home directory
ChrootEveryone yes
# Turn on compatibility hacks for broken clients
BrokenClientsCompatibility no
# Maximum number of simultaneous users
MaxClientsNumber 2
# Fork in background
Daemonize yes
# Maximum number of sim clients with the same IP address
MaxClientsPerIP 5
# If you want to log all client commands, set this to "yes".
# This directive can be duplicated to also log server responses.
VerboseLog yes

# List dot-files even when the client doesn't send "-a".
DisplayDotFiles yes
# Don't allow authenticated users - have a public anonymous FTP only.
AnonymousOnly no
# Disallow anonymous connections. Only allow authenticated users.
NoAnonymous yes
# Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
# The default facility is "ftp". "none" disables logging.
SyslogFacility ftp
# Display fortune cookies
# FortunesFile /usr/share/fortune/zippy
# Don't resolve host names in log files. Logs are less verbose, but
# it uses less bandwidth. Set this to "yes" on very busy servers or
# if you don't have a working DNS.
DontResolve yes
# Maximum idle time in minutes (default = 15 minutes)
MaxIdleTime 5

# If you want to enable PAM authentication, uncomment the following line
PAMAuthentication yes
# If you want simple Unix (/etc/passwd) authentication, uncomment this
UnixAuthentication yes

# Minimum UID for an authenticated user to log in.
MinUID 500
# Do not use the /etc/ftpusers file to disable accounts. We're already
# using MinUID to block users with uid < 500
UseFtpUsers no
# Allow FXP transfers for authenticated users.
AllowUserFXP no
# Allow anonymous FXP for anonymous and non-anonymous users.
AllowAnonymousFXP no
# Users can't delete/write files beginning with a dot ('.')
# even if they own them. If TrustedGID is enabled, this group
# will have access to dot-files, though.
ProhibitDotFilesWrite no
# Prohibit *reading* of files beginning with a dot (.history, .ssh...)
ProhibitDotFilesRead no
# Never overwrite files. When a file whoose name already exist is uploaded,
# it get automatically renamed to file.1, file.2, file.3, ...
AutoRename no
# Disallow anonymous users to upload new files (no = upload is allowed)
AnonymousCantUpload yes
# Create an additional log file with transfers logged in a Apache-like format :
# fw.c9x.org - jedi [13/Dec/1975:19:36:39] "GET /ftp/linux.tar.bz2" 200 21809338
# This log file can then be processed by www traffic analyzers.
AltLog clf:/var/log/pureftpd.log
# Be 'customer proof' : workaround against common customer mistakes like
# 'chmod 0 public_html', that are valid, but that could cause ignorant
# customers to lock their files, and then keep your technical support busy
# with silly issues. If you're sure all your users have some basic Unix
# knowledge, this feature is useless. If you're a hosting service, enable it.
CustomerProof yes
# This option is useful with servers where anonymous upload is
# allowed. As /var/ftp is in /var, it save some space and protect
# the log files. When the partition is more that X percent full,
# new uploads are disallowed.
MaxDiskUsage 95
# Listen only to IPv4 addresses in standalone mode (ie. disable IPv6)
# By default, both IPv4 and IPv6 are enabled.
IPV4Only yes
# Listen only to IPv6 addresses in standalone mode (ie. disable IPv4)
# By default, both IPv4 and IPv6 are enabled.
# IPV6Only yes
# Per-user concurrency limits. It will only work if the FTP server has
# been compiled with --with-peruserlimits (and this is the case on
# most binary distributions) .
# The format is : <max sessions per user>:<max anonymous sessions>
# For instance, 3:20 means that the same authenticated user can have 3 active
# sessions max. And there are 20 anonymous sessions max.
PerUserLimits 3:20

Now you can start your pure-ftpd server with :

#/etc/init.d/pure_ftpd start

#chkconfig pure-ftpd on

 

  • With Mysql

To use mysql you have to create a database FTP ans a mysql user for this database:

Database schema :

create database FTP;

use FTP;

CREATE TABLE IF NOT EXISTS `FTP` (
`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 '81',
`Gid` int(3) NOT NULL default '81',
`Dir` varchar(255) NOT NULL default '',
`QuotaSize` int(4) NOT NULL default '20',
`Status` enum('0','1') NOT NULL default '1',
`ULBandwidth` int(2) NOT NULL default '10',
`DLBandwidth` int(2) NOT NULL default '10',
`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 DEFAULT CHARSET=utf8;

Now you habve enable the mysql on the pure-ftpd.conf file:

Add this option :

MySQLConfigFile /etc/pure-ftpd/pureftpd-mysql.conf

But you have to disbale the PAM and unix authentification before

# If you want to enable PAM authentication, uncomment the following line
PAMAuthentication no

# If you want simple Unix (/etc/passwd) authentication, uncomment this
UnixAuthentication no

We have to configure pureftpd-mysql.conf

##############################################
# #
# Sample Pure-FTPd Mysql configuration file. #
# See README.MySQL for explanations. #
# #
##############################################
# Optional : MySQL server name or IP. Don't define this for unix sockets.
# MYSQLServer 127.0.0.1
# Optional : MySQL port. Don't define this if a local unix socket is used.
# MYSQLPort 3306
# Optional : define the location of mysql.sock if the server runs on this host.
MYSQLSocket /var/lib/mysql/mysql.sock
# Mandatory : user to bind the server as.
MYSQLUser user_mysql
# Mandatory : user password. You must have a password.
MYSQLPassword password
# Mandatory : database to open.
MYSQLDatabase database
# Mandatory : how passwords are stored
# Valid values are : "cleartext", "crypt", "md5" and "password"
# ("password" = MySQL password() function)
# You can also use "any" to try "crypt", "md5" *and* "password"
MYSQLCrypt cleartext
# In the following directives, parts of the strings are replaced at
# run-time before performing queries :
#
# \L is replaced by the login of the user trying to authenticate.
# \I is replaced by the IP address the user connected to.
# \P is replaced by the port number the user connected to.
# \R is replaced by the IP address the user connected from.
# \D is replaced by the remote IP address, as a long decimal number.
#
# Very complex queries can be performed using these substitution strings,
# especially for virtual hosting.
# Query to execute in order to fetch the password
MYSQLGetPW SELECT Password FROM FTP WHERE User="\L"
# Query to execute in order to fetch the system user name or uid
MYSQLGetUID SELECT Uid FROM FTP WHERE User="\L"
# Optional : default UID - if set this overrides MYSQLGetUID
#MYSQLDefaultUID 100:0
# Query to execute in order to fetch the system user group or gid
MYSQLGetGID SELECT Gid FROM FTP WHERE User="\L"
# Optional : default GID - if set this overrides MYSQLGetGID
#MYSQLDefaultGID 1000
# Query to execute in order to fetch the home directory
MYSQLGetDir SELECT Dir FROM FTP WHERE User="\L"
# Optional : query to get the maximal number of files
# Pure-FTPd must have been compiled with virtual quotas support.
# MySQLGetQTAFS SELECT QuotaFiles FROM FTP WHERE User="\L"
# Optional : query to get the maximal disk usage (virtual quotas)
# The number should be in Megabytes.
# Pure-FTPd must have been compiled with virtual quotas support.
MySQLGetQTASZ SELECT QuotaSize FROM FTP WHERE User="\L"
# Optional : ratios. The server has to be compiled with ratio support.
MySQLGetRatioUL SELECT ULRatio FROM FTP WHERE User="\L"
MySQLGetRatioDL SELECT DLRatio FROM FTP WHERE User="\L"
# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in KB/s .
MySQLGetBandwidthUL SELECT ULBandwidth FROM FTP WHERE User="\L"
MySQLGetBandwidthDL SELECT DLBandwidth FROM FTP WHERE User="\L"
# If you upgraded your tables to transactionnal tables (Gemini,
# BerkeleyDB, Innobase...), you can enable SQL transactions to
# avoid races. Leave this commented if you are using the
# traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.

# MySQLTransactions On

Now you can start your pure-ftpd server with :

#/etc/init.d/pure_ftpd start

#chkconfig pure-ftpd on

  • With PostgreSQL

To use postgres you have to create a database FTP and a postgres user for this database

psql -u pureftpd
psql: Warning: The -u option is deprecated. Use -U.
User name: pureftpd
Password:
Welcome to psql 7.3.2, the PostgreSQL interactive terminal.


Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit


pureftpd=>

Database Schema :

DROP TABLE users CASCADE;
DROP SEQUENCE users_id_seq CASCADE;

CREATE TABLE "users" (
id integer DEFAULT nextval('users_id_seq'::text) NOT NULL,
"User" character varying(16) NOT NULL default '',
status smallint default 0,
"Password" character varying(64) NOT NULL default '',
"Uid" character varying(11) DEFAULT -1 NOT NULL,
"Gid" character varying(11) DEFAULT -1 NOT NULL,
"Dir" character varying(128) NOT NULL,
"comment" text,
ipaccess character varying(15) DEFAULT '*' NOT NULL,
"ULBandwidth" smallint default 0,
"DLBandwidth" smallint default 0,
"QuotaSize" integer DEFAULT 0,
"QuotaFiles" integer DEFAULT 0,
ULRatio smallint default 0,
DLRatio smallint default 0,
create_date timestamp with time zone DEFAULT now() NOT NULL,
modify_date timestamp without time zone DEFAULT now() NOT NULL
);

CREATE SEQUENCE users_id_seq;
CREATE INDEX users_index ON users (id,"User");
ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY KEY (id);
ALTER TABLE ONLY users ADD CONSTRAINT users_id_key UNIQUE (id, "User");


Now you habve enable the postgresql on the pure-ftpd.conf file:

Add this option :

PGSQLConfigFile /etc/pure-ftpd/pureftpd-pgsql.conf

But you have to disbale the PAM and unix authentification before

# If you want to enable PAM authentication, uncomment the following line
PAMAuthentication no

# If you want simple Unix (/etc/passwd) authentication, uncomment this
UnixAuthentication no

We have to configure pureftpd-pgsql.conf


###################################################
# #
# Sample Pure-FTPd PostgreSQL configuration file. #
# See README.PGSQL for explanations. #
# #
###################################################


# If PostgreSQL listens to a TCP socket
PGSQLServer localhost
PGSQLPort 5432
# *or* if PostgreSQL can only be reached through a local Unix socket
# PGSQLServer /tmp
# PGSQLPort .s.PGSQL.5432
# Mandatory : user to bind the server as.
PGSQLUser postgres
# Mandatory : user password. You *must* have a password.
PGSQLPassword rootpw
# Mandatory : database to open.
PGSQLDatabase pureftpd
# Mandatory : how passwords are stored
# Valid values are : "cleartext", "crypt", "md5" and "any"
PGSQLCrypt cleartext

# In the following directives, parts of the strings are replaced at
# run-time before performing queries :
#
# \L is replaced by the login of the user trying to authenticate.
# \I is replaced by the IP address the user connected to.
# \P is replaced by the port number the user connected to.
# \R is replaced by the IP address the user connected from.
# \D is replaced by the remote IP address, as a long decimal number.
#
# Very complex queries can be performed using these substitution strings,
# especially for virtual hosting.
# Query to execute in order to fetch the password
PGSQLGetPW SELECT Password FROM users WHERE User='\L'
# Query to execute in order to fetch the system user name or uid
PGSQLGetUID SELECT Uid FROM users WHERE User='\L'
# Optional : default UID - if set this overrides PGSQLGetUID
#PGSQLDefaultUID 1000
# Query to execute in order to fetch the system user group or gid
PGSQLGetGID SELECT Gid FROM users WHERE User='\L'
# Optional : default GID - if set this overrides PGSQLGetGID
#PGSQLDefaultGID 1000
# Query to execute in order to fetch the home directory
PGSQLGetDir SELECT Dir FROM users WHERE User='\L'
# Optional : query to get the maximal number of files
# Pure-FTPd must have been compiled with virtual quotas support.
# PGSQLGetQTAFS SELECT QuotaFiles FROM users WHERE User='\L'
# Optional : query to get the maximal disk usage (virtual quotas)
# The number should be in Megabytes.
# Pure-FTPd must have been compiled with virtual quotas support.
# PGSQLGetQTASZ SELECT QuotaSize FROM users WHERE User='\L'
# Optional : ratios. The server has to be compiled with ratio support.
PGSQLGetRatioUL SELECT ULRatio FROM users WHERE User='\L'
PGSQLGetRatioDL SELECT DLRatio FROM users WHERE User='\L'
# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in KB/s .
PGSQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User='\L'
PGSQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User='\L'

Now you can start your pure-ftpd server with :

#/etc/init.d/pure_ftpd start

#chkconfig pure-ftpd on

TIPS

pure-ftpd command :

#pure-ftpwho

This command give information about who is online and the bandwith use for the upload and download.

 


 

 

Last Updated on Saturday, 30 January 2010 22:29