Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[HowTo]PureFTPD + MySQL + TLS
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Deutsche Dokumentation
View previous topic :: View next topic  
Author Message
gabelhonz
Apprentice
Apprentice


Joined: 30 Aug 2004
Posts: 222
Location: 10010100111110011

PostPosted: Fri Jun 02, 2006 9:37 pm    Post subject: [HowTo]PureFTPD + MySQL + TLS Reply with quote

Halli hallo,

in diesem HowTo geht es um die Installation eines Pure-FTPD Server mit MySQL anbindung und einer gesicherten Verbindung über TLS.
Mir ist grad langweilig *gg*

1. Pure-FTPD installieren

Als erstes müssen wir pure-ftpd installieren, das emergen wir ganz normal!
Allerdings installieren wir diesen mit folgenden USE Flags damit das ganze funktioniert und auch sicher läuft:

Code:
USE="vchroot mysql pam ssl" emerge pure-ftpd



2. MySQL Datenbank erstellen

Als nächstes erstellen wir unsere MySQL Datenbank, dazu gehen wir wie folgt vor:
Wir loggen uns als root auf unserem MySQL Server ein und erstellen erstmal unsere DB mit:

Code:
CREATE DATABASE ftpusers;


Nun legen wir unseren User dafür an:

Code:
GRANT ALL privileges ON ftpusers.* TO ftp@localhost IDENTIFIED BY 'password';


als letztes nur noch die Privileges table refreshen mit:

Code:
flush privileges;


Jetzt können wir unsere DB Struktur anlegen, die sieht passend zu meiner config so aus:

Code:
CREATE TABLE users (
User varchar(16) NOT NULL DEFAULT '',
Password varchar(64) NOT NULL DEFAULT '',
Uid int(11) NOT NULL DEFAULT '-1',
Gid int(11) NOT NULL DEFAULT '-1',
Dir varchar(128) NOT NULL DEFAULT '',
QuotaFiles int(10) NOT NULL DEFAULT '500',
QuotaSize int(10) NOT NULL DEFAULT '100',
ULBandwidth int(10) NOT NULL DEFAULT '80',
DLBandwidth int(10) NOT NULL DEFAULT '80',
PRIMARY KEY  (User)
);


Oder einfach das in eine Datei schreiben und mit:

Code:
mysql -u ftp ftpusers < pureftpd.sql -ppassword


Möchte man seine MySQL Datenbank auch für andere Server zur Verfügung stellen(bzw. als Zentrale FTP Verwaltung) muss
man in der /etc/mysql/my.cnf dein Eintrag von:

Code:
bind-address    = 127.0.0.1

auf
Code:
bind-address    = 0.0.0.0

ändern ! Zudem ganzen muss man auch dem User dann nicht mit @localhost sonder mit @% anlegen, was soviel heißt das jeder host zugreifen darf. Man kann auch explizit nur bestimmte Hosts erlauben, was sinnvoll ist !
Keep Security in Mind !

3. Zertifikat erstellen

Wir gehen folgendermaßen vor:
1. ssl dir erstellen

Code:
mkdir -p /etc/ssl/private


Dann das Zertifikat:

Code:
openssl req -x509 -nodes -newkey rsa:1024 -keyout \
  /etc/ssl/private/pure-ftpd.pem \
  -out /etc/ssl/private/pure-ftpd.pem


Und zum Schluss die Berechtigungen!

Code:
chmod 600 /etc/ssl/private/*.pem


p.s. man kann auch ein csr bei cacert anfordern, kurz:

Code:
openssl genrsa -out webmail.mydomain.com.key 1024
openssl req -new -key webmail.mydomain.com.key -out webmail.mydomain.com.csr



4. Konfiguration anpassen

Nach unserer Installation müssen wir 2 Konfigurationsdateien anpassen(erstellen).
Einmal /etc/conf.d/pure-ftpd und einmal /etc/conf.d/pure-ftpd-mysql
Unsere pure-ftpd muss dabei wie folgt aussehen:

Code:
# Config file for /etc/init.d/pure-ftpd
 
IS_CONFIGURED="yes"
 
SERVER="-S 21"
 
MAX_CONN="-c 30"
MAX_CONN_IP="-C 10"
 
DAEMON="-B"
 
DISK_FULL="-k 90%"
 
AUTH="-l mysql:/etc/conf.d/pure-ftpd-mysql -l unix"
 
LOG="-f facility"
 
MISC_OTHER="-A -E -i -X -j -R -s -Y 1 -Z -U 022:022 -O stats:/var/log/pureftpd.log"


-O stats:/var/log/pureftpd.log bedeutet das der FTP alles in form einer Statistik loggt, es gibt verschieden FTP Statistik tools die das decrypten
können. Ein einfaches commandline tool was schon dabei ist heißt pureftp-statsdecode. Es gibt auch noch andere Log Methoden. Siehe man pure-ftpd.
Die verschiedenen startoptionen für den FTP kann man unter:
http://pureftpd.sourceforge.net/README nachlesen.
Unsere pure-ftpd-mysql so:

Code:
#Config File for MYSQL Authentication Module#
MYSQLServer     127.0.0.1
MYSQLPort       3306
MYSQLSocket     /tmp/mysql.sock
MYSQLUser       ftp
MYSQLPassword   password
MYSQLDatabase   ftpusers
MYSQLCrypt      md5
 
#Per User settings
MYSQLGetPW              SELECT Password FROM users WHERE User="\L"
MYSQLGetUID             SELECT Uid FROM users WHERE User="\L"
MYSQLGetGID             SELECT Gid FROM users WHERE User="\L"
MYSQLGetDir             SELECT Dir FROM users WHERE User="\L"
MySQLGetQTAFS           SELECT QuotaFiles FROM users WHERE User="\L"
MySQLGetQTASZ           SELECT QuotaSize FROM users WHERE User="\L"
MySQLGetBandwidthUL     SELECT ULBandwidth FROM users WHERE User="\L"
MySQLGetBandwidthDL     SELECT DLBandwidth FROM users WHERE User="\L"


Wobei man natürlich die Daten anpassen muss.

Und fertig ist das ganze !
Jetzt noch den pure-ftpd starten und virtuelle user anlegen und alles sollte laufen ! Zudem gibt es noch ein ganz schönes Administrationsinterface als Frontend.
hier:
http://machiel.generaal.net/index.php?subject=user_manager_pureftpd

gruß gabelhonz
_________________
Wenn Chuck Norris ins Wasser fällt, wird Chuck Norris nicht nass. Wasser wird Chuck Norris.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Deutsche Dokumentation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum