今天是: 收藏本站 设为主页
网站首页 >  技术专栏  >  linux  > 

centos安装proftpd+mysql虚拟用户认证

日期:2012-07-07  点击率:1317


yum install proftpd
yum install proftpd-mysql


groupadd -g 2010 ftpgroup //增加一个组ID为2010的ftpgroup组
useradd -u 2010 -s /bin/false -d /liuxun/null -c "proftpd user" -g ftpgroup -r ftpuser


//////////////////////////////////////////////////////////////////////////////////////////////////
您可以在/etc/passwd 中找到 ftp用户一行,比如类似下面这行

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
在这行中,14是ftp用户的UID,我们要改为1000,50为ftp用户组的GID,也改为1000,其它的可以不变;也就是

ftp:x:1000:1000:FTP User:/var/ftp:/sbin/nologin
接着我们再找到 /etc/group ;在这个文件中找到一行,类似如下的;

ftp:x:50:
把这行中的50改为1000;也就是这样的;

ftp:x:1000:
//////////////////////////////////////////////////////////////////////////////////////////////////


chkconfig --levels 235 proftpd on
service proftpd start  

chown ftpuser /liuxun/ftp
chgrp ftpgroup  /liuxun/ftp

 

 


cp /etc/proftpd.conf /etc/proftpd.conf.bak
vi /etc/proftpd.conf


# Use pam to authenticate (default) and be authoritative
#AuthPAMConfig                  proftpd
#AuthOrder                      mod_auth_pam.c* mod_auth_unix.c

 


LoadModule mod_sql.c
LoadModule mod_sql_mysql.c
LoadModule mod_quotatab.c
LoadModule mod_quotatab_sql.c
# The passwords in MySQL are encrypted using CRYPT
SQLAuthTypes               Plaintext Crypt
SQLAuthenticate            users groups

# 配置数据库、连接用户及密码信息
# databasename@host  database_user user_password
SQLConnectInfo     ftp@localhost:3306 ftp 123456
SQLUserInfo              ftpuser userid passwd uid gid homedir shell
SQLGroupInfo             ftpgroup groupname gid members

SQLNamedQuery getcount SELECT "count from ftpuser where userid='%u'"
SQLNamedQuery getlastlogin SELECT "lastlogin from ftpuser where userid='%u'"
SQLShowInfo PASS "230" "You've logged on %{getcount} times, last login at %{getlastlogin}"
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser
SQLLog     STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

# User quotas
# ===========
# ===========
QuotaEngine on
QuotaDirectoryTally on
QuotaDisplayUnits Mb
QuotaShowQuotas on
SQLNamedQuery get-quota-limit SELECT "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 FROM ftpquotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"
SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftpquotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
RootLogin off
RequireValidShell off
CreateHome on

 

 

 

 

 

 

 

 

用下面的方法添加数据库和用户.
grant all privileges on 数据库名称.* to 数据库用户名@localhost identified by '密码';
flush privileges;

 

mysql -u root -p

 create database ftp;
 GRANT select,insert,update,delete,create,drop,index,alter,create temporary tables,lock tables ON ftp.* TO ftp@'localhost' IDENTIFIED BY '123456';
 GRANT Sselect,insert,update,delete,create,drop,index,alter,create temporary tables,lock tables ON ftp.* TO ftp@'localhost.localdomain'  IDENTIFIED BY '123456';
 FLUSH PRIVILEGES;
USE ftp;
 CREATE TABLE ftpgroup (
 groupname varchar(16) NOT NULL default '',
 gid smallint(6) NOT NULL default '2010',
 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 '2010',
 gid smallint(6) NOT NULL default '2010',
 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';

 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 ('ftptest', 'user', 'true', 'hard', 15728640, 0, 0, 0, 0, 0);
 INSERT INTO `ftpuser` (`id`, `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`, `count`, `accessed`, `modified`) VALUES (1,'ftptest', 'aaabbb', 2010, 2010, '/liuxun/ftp/ftptest', '/sbin/nologin', 0, '', '');

 


LoadModule mod_sql.c
LoadModule mod_sql_mysql.c
LoadModule mod_quotatab.c
LoadModule mod_quotatab_sql.c

SQLConnectInfo ftpusers@localhost:3306 root
SQLAuthTypes Plaintext Crypt
SQLUserInfo users userid passwd uid gid home shell
SQLGroupInfo grps grpname gid members
RequireValidShell off
 RootLogin off
SQLAuthenticate users  groups
CreateHome on
SystemLog /liuxun/proftpd.syslog
TransferLog /liuxun/proftpd.transferlog





下一篇:Nginx设置alias实现虚拟目录 alias与root的用法区别   上一篇:linux下用phpize给PHP动态添加扩展