Utiliser Pure-FTP avec MySQL
Installez pure-ftp :
sudo apt-get install pure-ftpd-mysql
Connectez-vous au serveur MySQL :
mysql -u root -p
Créez l’utilisateur MySQL ftp (en changeant le mot de passe) :
CREATE USER 'ftp'@'localhost' IDENTIFIED BY 'mot_de_passe'; GRANT USAGE ON *.* TO 'ftp'@'localhost' IDENTIFIED BY 'mot_de_passe'; CREATE DATABASE IF NOT EXISTS `ftp` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON `ftp`.* TO 'ftp'@'localhost';
Ensuite, créez la table qui contiendra les utilisateurs :
USE `ftp`;
CREATE TABLE `users` (
`login` varchar(16) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`is_active` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
`password` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`uid` varchar(11) COLLATE utf8_unicode_ci NOT NULL DEFAULT '-1',
`gid` varchar(11) COLLATE utf8_unicode_ci NOT NULL DEFAULT '-1',
`home` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`up_bandwidth_kbps` smallint(5) NOT NULL DEFAULT '0',
`down_bandwidth_kbps` smallint(5) NOT NULL DEFAULT '0',
`comment` tinytext COLLATE utf8_unicode_ci NOT NULL,
`quota_megabytes` smallint(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
exit;
Pour créer un utilisateur FTP, il faut exécuter la requête suivante :
INSERT INTO `users` (`login`, `is_active`, `password`, `uid`, `gid`, `home`, `up_bandwidth_kbps`, `down_bandwidth_kbps`, `comment`, `quota_megabytes`) VALUES('login', '1', md5('password'), '1000', '1000', '/home/login', 0, 0, '', 0);
Maintenant que MySQL est prêt, il faut configurer pure-ftp en éditant le fichier /etc/pure-ftpd/db/mysql.conf avec les paramètres MySQL crées précédement :
# 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/run/mysqld/mysqld.sock
# Mandatory : user to bind the server as.
MYSQLUser ftp
# Mandatory : user password. You must have a password.
MYSQLPassword mot_de_passe
# Mandatory : database to open.
MYSQLDatabase ftp
# 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 md5
# 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 users WHERE login="\L" AND is_active="1"
# Query to execute in order to fetch the system user name or uid
MYSQLGetUID SELECT uid FROM users WHERE login="\L" AND is_active="1"
# Optional : default UID - if set this overrides MYSQLGetUID
#MYSQLDefaultUID 1000
# Query to execute in order to fetch the system user group or gid
MYSQLGetGID SELECT gid FROM users WHERE login="\L" AND is_active="1"
# Optional : default GID - if set this overrides MYSQLGetGID
#MYSQLDefaultGID 1000
# Query to execute in order to fetch the home directory
MYSQLGetDir SELECT home FROM users WHERE login="\L" AND is_active="1"
# Optional : query to get the maximal number of files
# Pure-FTPd must have been compiled with virtual quotas support.
# MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE login="\L" AND is_active="1"
# 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 quota_megabytes FROM users WHERE login="\L" AND is_active="1"
# Optional : ratios. The server has to be compiled with ratio support.
# MySQLGetRatioUL SELECT ULRatio FROM users WHERE login="\L" AND is_active="1"
# MySQLGetRatioDL SELECT DLRatio FROM users WHERE login="\L" AND is_active="1"
# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in KB/s .
MySQLGetBandwidthUL SELECT up_bandwidth_kbps FROM users WHERE login="\L" AND is_active="1"
MySQLGetBandwidthDL SELECT down_bandwidth_kbps FROM users WHERE login="\L" AND is_active="1"
# Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
# 1) You know what you are doing.
# 2) Real and virtual users match.
# MySQLForceTildeExpansion 1
# 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
Il reste à configurer certaines options de pure-ftp en créant un fichier par paramètre avec sa valeur. Les noms sont assez explicites :
cd /etc/pure-ftpd-conf sudo echo ,21 > Bind sudo echo 4500 4600 > PassivePortRange sudo echo yes > ChrootEveryone sudo echo yes > ProhibitDotFilesRead sudo echo yes > ProhibitDotFilesWrite sudo echo yes > NoChmod sudo echo yes > BrokenClientsCompatibility sudo echo 4 > MaxClientsPerIP sudo echo 20 > MaxClientsNumber sudo echo no > PAMAuthentication sudo echo no > UnixAuthentication sudo /etc/init.d/pure-ftpd restart
Et c’est tout. Source : How to install and configure pure-ftpd
27/02/2011 — Mots-clés : FTP, Linux, MySQL — Classé dans Geek
— Ecrire un commentaire