Fedora 11 - Proftpd,MySQL,Virtuális felhasználókkal
A cikk feltételezi, hogy a rendszerre telepítve van egy MySQL 5 kiszolgáló, illetve valamilyen MySQL adminisztratív eszköz (administrator, query-browser, phpmyadmin...)
1. Telepítsük a Proftpd-t és a MySQL támogatást hozzá
yum install proftpd proftpd-mysql
2. Vegyünk fel egy csoportot és egy felhasználót a proftpd számára:
groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
Létrehoztuk az ftp csoportot ("ftpgroup") és az ftp felhasználót ("ftpuser"), mind a kettő id-je legyen 2001 (group és user id)
3. Készítsük el a szükséges adatbázist és felhasználót a MySQL-ben
mysql -u root -p
create database ftp;
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'proftpd'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'proftpd'@'localhost.localdomain' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Ne felejtsük el kicserélni a scriptben a password szót a valós jelszóra.. Természetesen használhatunk más felhasználó nevet is, de akkor a későbbi scriptekben, konfigokban is azt kell használni.
Most pedig készítsük egy a szükséges táblákat is:
USE ftp;
CREATE TABLE ftpgroup (
groupname varchar(16) NOT NULL default '',
gid smallint(6) NOT NULL default '5500',
members varchar(16) NOT NULL default '',
KEY groupname (groupname)
) TYPE=MyISAM COMMENT='ProFTP group table';
CREATE TABLE ftpquotalimits (
name varchar(30) default NULL,
quota_type enum('user','group','class','all') NOT NULL default 'user',
per_session enum('false','true') NOT NULL default 'false',
limit_type enum('soft','hard') NOT NULL default 'soft',
bytes_in_avail int(10) unsigned NOT NULL default '0',
bytes_out_avail int(10) unsigned NOT NULL default '0',
bytes_xfer_avail int(10) unsigned NOT NULL default '0',
files_in_avail int(10) unsigned NOT NULL default '0',
files_out_avail int(10) unsigned NOT NULL default '0',
files_xfer_avail int(10) unsigned NOT NULL default '0'
) TYPE=MyISAM;
CREATE TABLE ftpquotatallies (
name varchar(30) NOT NULL default '',
quota_type enum('user','group','class','all') NOT NULL default 'user',
bytes_in_used int(10) unsigned NOT NULL default '0',
bytes_out_used int(10) unsigned NOT NULL default '0',
bytes_xfer_used int(10) unsigned NOT NULL default '0',
files_in_used int(10) unsigned NOT NULL default '0',
files_out_used int(10) unsigned NOT NULL default '0',
files_xfer_used int(10) unsigned NOT NULL default '0'
) TYPE=MyISAM;
CREATE TABLE ftpuser (
id int(10) unsigned NOT NULL auto_increment,
userid varchar(32) NOT NULL default '',
passwd varchar(32) NOT NULL default '',
uid smallint(6) NOT NULL default '5500',
gid smallint(6) NOT NULL default '5500',
homedir varchar(255) NOT NULL default '',
shell varchar(16) NOT NULL default '/sbin/nologin',
count int(11) NOT NULL default '0',
accessed datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id),
UNIQUE KEY userid (userid)
) TYPE=MyISAM COMMENT='ProFTP user table';
quit;
4. A Proftpd beállítása
Nyissuk meg szerkesztésre az /etc/proftpd.conf fájl. (Javallott az eredit elmenteni)
Új sorok a konfig végére:
# nem kell a PAM autentikációja
AuthPAM off
# SQL-s autentikáció és modulok betöltése
<IfModule mod_dso.c>
LoadModule mod_sql.c
LoadModule mod_sql_mysql.c<IfModule>
# Az ftp felhasználó jelszavának kódolása, sorrendben.
SQLAuthTypes Plaintext Crypt
SQLAuthenticate users groups
# hogyan csatlakozzon a Proftpd a MySQL-hez
# databasename@host database_user user_password
SQLConnectInfo ftp@localhost proftpd jelszó
# Itt mondjuk meg a Proftpd-nek, hogy hogyan néz ki az ftpuser tábla a MySQL-ben
# A táblaneveknek egyezni-e kell az itt felsoroltakkal és viszont
SQLUserInfo ftpuser userid passwd uid gid homedir shell
# Mint az előző csak az ftpgroup-ra értelmezve
SQLGroupInfo ftpgroup groupname gid members
# UID és GID - beállítása
SQLMinID 500
# Login után frissítjük a felhasználó rekordját, belépésszám, időpont...
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser
# Minden módosításnál loggolunk...
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
Meglevő sorok változása:
# Use pam to authenticate (default) and be authoritative
#AuthPAMConfig proftpd
#AuthOrder mod_auth_pam.c* mod_auth_unix.cRootLogin off
RequireValidShell off
5. Proftpd újraindítása
service proftpd restart
6. Teszt
MySQL-be belépünk:
mysql -u root -p
USE ftp;
Felvesszük az első csoportot:
INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 2001, 'ftpuser');
Felveszünk egy felhasználót:
INSERT INTO `ftpquotalimits` (`name`, `quota_type`, `per_session`, `limit_type`, `bytes_in_avail`, `bytes_out_avail`, `bytes_xfer_avail`, `files_in_avail`, `files_out_avail`, `files_xfer_avail`) VALUES ('probauser', 'user', 'true', 'hard', 15728640, 0, 0, 0, 0, 0);
INSERT INTO `ftpuser` (`id`, `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`, `count`, `accessed`, `modified`) VALUES (1, 'probauser', 'jelszavam', 2001, 2001, '/home/ftpmappa', '/sbin/nologin', 0, '', '');
quit;
Fontos, hogy a felhasználó mappája legyen elkészítve és az ftpgroup:ftpuser legyenek hozzárendelve (chown), különben nem lehet be jelentkezni. Vagy meg kell adni a Proftpd-nek, hogy bejelentkezéskor készítse el a felhasználó mappáját..
# create a user's home directory on demand if it doesn't exist
CreateHome on
7. Proftpd hibakeresés
Hibakereséshez logfile használat, /etc/proftpd.conf-ba tegyük bele a következő sort:
SQLLogFile /var/log/proftpdlog.log
Ha nem szervízként futtatjuk akkor, indítási paraméterként adjuk ki ezt:
proftpd -nd6
Ilyenkor futásidőben kommentálja éppen mi történik.
8. FTP Adatbázis adminisztrálása (fordítás alatt...)
ftpuser Table:
The important columns are these (the others are handled by MySQL or Proftpd automatically, so do not fill these manually!):
* userid: The name of the virtual Proftpd user (e.g. exampleuser).
* passwd: The unencrypted (i.e., clear-text) password of the user.
* uid: The userid of the ftp user you created at the end of step two (e.g. 2001).
* gid: The groupid of the ftp group you created at the end of step two (e.g. 2001).
* homedir: The home directory of the virtual Proftpd user (e.g. /home/www.example.com). If it does not exist, it will be created when the new user logs in the first time via FTP. The virtual user will be jailed into this home directory, i.e., he cannot access other directories outside his home directory.
* shell: It is ok if you fill in /sbin/nologin here by default.
ftpquotalimits Table:
The important columns are these (the others are handled by MySQL or Proftpd automatically, so do not fill these manually!):
* name: The name of the virtual Proftpd user (e.g. exampleuser).
* quota_type: user or group. Normally, we use user here.
* per_session: true or false. true means the quota limits are valid only for a session. For example, if the user has a quota of 15 MB, and he has uploaded 15 MB during the current session, then he cannot upload anything more. But if he logs out and in again, he again has 15 MB available. false means, that the user has 15 MB at, no matter if he logs out and in again.
* limit_type: hard or soft. A hard quota limit is a never-to-exceed limit, while a soft quota can be temporarily exceeded. Normally you use hard here.
* bytes_in_avail: Upload limit in bytes (e.g. 15728640 for 15 MB). 0 means unlimited.
* bytes_out_avail: Download limit in bytes. 0 means unlimited.
* bytes_xfer_avail: Transfer limit in bytes. The sum of uploads and downloads a user is allowed to do. 0 means unlimited.
* files_in_avail: Upload limit in files. 0 means unlimited.
* files_out_avail: Download limit in files. 0 means unlimited.
* files_xfer_avail: Tranfer limit in files. 0 means unlimited.
Referenciák:
Proftpd: http://www.proftpd.org/
MySQL: http://www.mysql.com/
