In questa breve guida vediamo come installare PureFTPD su Debian, utilizzando gli utenti di un database MySQL invece che quelli di sistema.
Installare MySQL
Come prima cosa è necessario installare MySQL sul proprio server, se non è ancora presente.
aptitude install mysql-server mysql-client
Nella fase di installazione saranno chieste alcune informazioni come la password di root per accedere a MySQL e il server web utilizzato.
Installare PureFTPd
L’installazione di PureFTPd con il supporto MySQL risulta essere molto semplice su Debian, esiste infatti un pacchetto con queste caratteristiche chiamato pure-ftpd-mysql.
aptitude install pure-ftpd-mysql
Terminata l’installazione, è possibile creare l’utente di sistema a cui saranno mappati tutti gli utenti virtuali presenti sul database.
groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c “pureftpd user” -g ftpgroup ftpuser
Creare il database per PureFTPd
La fase successiva consiste nel creare un database e un utente MySQL che saranno utilizzati da PureFTPd.
mysql -u root -p
CREATE DATABASE pureftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO ‘pureftpd’@’localhost’ IDENTIFIED BY ‘ftpdpass’;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO ‘pureftpd’@’localhost.localdomain’ IDENTIFIED BY ‘ftpdpass’;
FLUSH PRIVILEGES;
La stringa ftpdpass può essere sostituita con la password che si vuole utilizzare per l’utente pureftpd.
USE pureftpd;
CREATE TABLE ftpd (
User varchar(16) NOT NULL default ”,
status enum(’0′,’1′) NOT NULL default ’0′,
Password varchar(64) NOT NULL default ”,
Uid varchar(11) NOT NULL default ‘-1′,
Gid varchar(11) NOT NULL default ‘-1′,
Dir varchar(128) NOT NULL default ”,
ULBandwidth smallint(5) NOT NULL default ’0′,
DLBandwidth smallint(5) NOT NULL default ’0′,
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default ‘*’,
QuotaSize smallint(5) NOT NULL default ’0′,
QuotaFiles int(11) NOT NULL default 0,
PRIMARY KEY (User),
UNIQUE KEY User (User)
) TYPE=MyISAM;
quit;
Configurare PureFTPd
A questo punto è possibile configurare PureFTPd in modo che venga utilizato il database creato.
Il file /etc/pure-ftpd/db/mysql.conf dovrà essere quindi simile al seguente.
MYSQLSocket /var/run/mysqld/mysqld.sock
#MYSQLServer localhost
#MYSQLPort 3306
MYSQLUser pureftpd
MYSQLPassword ftpdpass
MYSQLDatabase pureftpd
#MYSQLCrypt md5, cleartext, crypt() or password() – md5 is VERY RECOMMENDABLE uppon cleartext
MYSQLCrypt md5
MYSQLGetPW SELECT Password FROM ftpd WHERE User=”L” AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MYSQLGetUID SELECT Uid FROM ftpd WHERE User=”L” AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MYSQLGetGID SELECT Gid FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MYSQLGetDir SELECT Dir FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User=”L”AND status=”1″ AND (ipaccess = “*” OR ipaccess LIKE “R”)
La stringa ftpdpass deve essere sostituita con la password impostata in precedenza per l’utente MySQL pureftpd.
Dopo che si sono salvate le modifiche, bisogna creare il file /etc/pure-ftpd/conf/ChrootEveryone che contiene solamente la stringa yes.
echo “yes” > /etc/pure-ftpd/conf/ChrootEveryone
In questo modo viene effettuato il chroot di ogni utente virtuale all’interno della propria home.
Bisogna quindi creare anche il file CreateHomeDir, all’interno del quale è presente la stringa yes, che specifica che deve essere creata una home per ogni utente che effettua l’accesso.
echo “yes” > /etc/pure-ftpd/conf/CreateHomeDir
A questo punto bisogna configurare PureFTPd come demone standalone modificando il paramentro STANDALONE_OR_INETD presente nel file /etc/default/pure-ftpd-common.
vi /etc/default/pure-ftpd-common
# VIRTUALCHROOT:
# whether to use binary with virtualchroot support
# valid values are “true” or “false”
# Any change here overrides the setting in debconf.
VIRTUALCHROOT=false
Inoltre bisogna commentare la riga ftp all’interno del file /etc/inetd.conf
vi /etc/inetd.conf
#:STANDARD: These are standard services.
#ftp stream tcp nowait root
Fatto questo è possibile riavviare Inetd e PureFTPd.
/etc/init.d/openbsd-inetd restart
/etc/init.d/pure-ftpd-mysql restart
Inserire le utenze del database
Per utilizzare la configurazione specificata, è necessario inserire le utenze all’interno del database
mysql -u root -p
USE pureftpd;
INSERT INTO `ftpd` (`User`, `status`, `Password`, `Uid`, `Gid`, `Dir`, `ULBandwidth`, `DLBandwidth`, `comment`, `ipaccess`, `QuotaSize`, `QuotaFiles`) VALUES (‘exampleuser’, ’1′, MD5(‘secret’), ’2001′, ’2001′, ‘/home/prova’, ’100′, ’100′, ”, ‘*’, ’50′, ’0′);
In questo esempio viene creato l’utente exampleuser che ha password secret, uid e gid 2001 che corrispondono a quello dell’utente di sistema creato in precedenza e una quota di 50 mb.
Nel momento in cui ci si collega al server con l’utente exampleuser viene creata automaticamente la directory /home/prova.