proftp 配合 mysql 虚拟用户的配置

#######################################

ubuntu 12.04  


#安装需要的包


apt-get install proftpd proftpd-mod-mysql gcc g++ cmake make libncurses5-dev;


#################################################################################

#添加用户和组


groupadd -g 2001 ftpgroup

useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser


##################################################################################


#使用mysql创建数据库和表,新建用户并且设置权限

create database ftp;


GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'proftpd'@'localhost' IDENTIFIED BY 'password';


FLUSH PRIVILEGES;


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))

ENGINE=MyISAM COMMENT='ProFTP group table';



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)

) ENGINE=MyISAM COMMENT='ProFTP user table';


INSERT INTO ftpgroup (groupname, gid, members) VALUES ('ftpgroup', 2001, 'ftpuser');


INSERT INTO ftpuser (id, userid, passwd, uid, gid, homedir, shell, count, accessed, modified) VALUES ('', 'jastme', ENCRYPT('jastme'), 2001, 2001, '/website/jastme', '/sbin/nologin', 0, now(), now());

创建了一个叫jastme的用户,密码为jastme,用户根目录为/website/jastme


###########################################################################

#添加配置文件

echo

"

#Force the use of mysql backend


SQLBackend                      mysql


# The passwords in MySQL are using its own ENCRYPT function

# There is another SQLAuthTypes you could use called Backend to 

# store passwords.  If you choose this make sure you use mysql's

# OLD_PASSWORD() function to store the data.  I couldn't get the 

# stand PASSWORD() function to work with it.


SQLAuthTypes                    Crypt

SQLAuthenticate                 users* groups*


# used to connect to the database

# databasename@host  database_user user_password


SQLConnectInfo  ftp@localhost  proftpd password


# Here we tell ProFTPd the names of the database columns in the "usertable"

# we want it to interact with. Match the names with those in the db


SQLUserInfo     ftpuser userid passwd uid gid homedir shell


# Tell ProFTPd the names of the database columns in the "grouptable"

# we want it to interact with. Again the names match with those in the db


SQLGroupInfo    ftpgroup groupname gid members


# Update count every time user logs in


SQLLog PASS updatecount

SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser


# Update modified everytime user uploads or deletes a file


SQLLog  STOR,DELE modified

SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

"

> /etc/proftpd/mysql.conf


##############################################################


/etc/proftpd/proftpd.conf

添加以下几行到 Include /etc/proftpd/modules.conf 这行之下


## Begin Customization

######################

Include /etc/proftpd/mysql.conf

RootLogin               off

# Users require a valid shell listed in /etc/shells to login.

# Use this directive to release that constrain.

RequireValidShell       off

# Use this to jail all users in their homes

DefaultRoot             ~

# These two lines help speed up the initial connection to the server

IdentLookups            off

UseReverseDns           off

# Create a user's home directory on demand if it doesn't exist

CreateHome on

## End Customization

####################


###############################################################


/etc/proftpd/modules.conf


取消以下2行的注释


LoadModule mod_sql.c

LoadModule mod_sql_mysql.c


##############################################################


优化 /etc/proftpd/proftpd.conf 配置文件


# Includes DSO modules

Include /etc/proftpd/modules.conf                                          模块文件

## Begin Customization

######################

Include /etc/proftpd/mysql.conf                                            数据库配置

RootLogin               off                                                拒绝管理员登陆ftp

# Users require a valid shell listed in /etc/shells to login.

# Use this directive to release that constrain.

RequireValidShell       off                                                拒绝匿名用户 

# Use this to jail all users in their homes

DefaultRoot             ~                                                  默认用户的根目录是数据库内保存的路径,限制用户只能在根目录里活动

# These two lines help speed up the initial connection to the server

IdentLookups            off                                                防止proftpd进行DNS反查以及对用户端进行ident确认

UseReverseDns           off

# Create a user's home directory on demand if it doesn't exist

CreateHome on                                                              如果目录不存在,自动新建目录


MaxClients 50                                                              最多50个客户端

MaxClientsPerHost 50                                                       允许同一个IP有50个连接

MaxClientsPerUser 50                                                       每一个用户能有50个连接

AllowStoreRestart on                                                       断点上传

AllowRetrieveRestart on                                                    断点下载

RateReadBPS RateReadFreeBytes                                              下载限速

RateWriteBPS RateWriteFreeBytes                                            上传限速

## End Customization

####################


# Set off to disable IPv6 support which is annoying on IPv4 only boxes.

UseIPv6                         off                                        取消IPV6 使用IPV4


ServerName                      "XXX'S Ftp Server"                         随意

ServerType                      standalone                                 单机模式,还有个INET的模式

DeferWelcome                    off                                        欢迎的语句,默认关闭了

ServerIdent                     off                                        关闭服务器版本显示


MultilineRFC2228                on                                         

DefaultServer                   on

ShowSymlinks                    on


TimeoutNoTransfer               600                                        传输超时时间

TimeoutStalled                  600

TimeoutIdle                     1200


DisplayLogin                    welcome.msg

DisplayChdir                    .message true

ListOptions                     "-l"

DenyFilter                      \*.*/

Port                            21


# In some cases you have to specify passive ports range to by-pass

# firewall limitations. Ephemeral ports can be used for that, but

# feel free to use a more narrow range.

# PassivePorts                  49152 65534


# If your host was NATted, this option is useful in order to

# allow passive tranfers to work. You have to use your public

# address and opening the passive ports used on your firewall as well.

# MasqueradeAddress             1.2.3.4


# This is useful for masquerading address with dynamic IPs:

# refresh any configured MasqueradeAddress directives every 8 hours

<IfModule mod_dynmasq.c>

# DynMasqRefresh 28800

</IfModule>


MaxInstances                    30                                     30个proftp的实例,就是子进程了。


# Set the user and group that the server normally runs at.

User                            proftpd

Group                           nogroup


# Umask 022 is a good standard umask to prevent new files and dirs

# (second parm) from being group and world writable.

Umask                           022  022

# Normally, we want files to be overwriteable.

AllowOverwrite                  on                                     允许覆盖文件


# Uncomment this if you are using NIS or LDAP via NSS to retrieve passwords:

# PersistentPasswd              off


# This is required to use both PAM-based authentication and local passwords

# AuthOrder                     mod_auth_pam.c* mod_auth_unix.c


# Be warned: use of this directive impacts CPU average load!

# Uncomment this if you like to see progress and transfer rate with ftpwho

# in downloads. That is not needed for uploads rates.

#

# UseSendFile                   off


TransferLog /var/log/proftpd/xferlog

SystemLog   /var/log/proftpd/proftpd.log


# Logging onto /var/log/lastlog is enabled but set to off by default

#UseLastlog on


# In order to keep log file dates consistent after chroot, use timezone info

# from /etc/localtime.  If this is not set, and proftpd is configured to

# chroot (e.g. DefaultRoot or <Anonymous>), it will use the non-daylight

# savings timezone regardless of whether DST is in effect.

#SetEnv TZ :/etc/localtime


<IfModule mod_quotatab.c>

QuotaEngine off

</IfModule>


<IfModule mod_ratio.c>

Ratios off

</IfModule>



# Delay engine reduces impact of the so-called Timing Attack described in

# http://www.securityfocus.com/bid/11430/discuss

# It is on by default.

<IfModule mod_delay.c>

DelayEngine on

</IfModule>


<IfModule mod_ctrls.c>

ControlsEngine        off

ControlsMaxClients    2

ControlsLog           /var/log/proftpd/controls.log

ControlsInterval      5

ControlsSocket        /var/run/proftpd/proftpd.sock

</IfModule>


<IfModule mod_ctrls_admin.c>

AdminControlsEngine off

</IfModule>


#######################################


启动proftp

/etc/init.d/proftp start


在ftp库中添加如下语句

INSERT INTO ftpuser (id, userid, passwd, uid, gid, homedir, shell, count, accessed, modified) VALUES ('', 'jastme', ENCRYPT('jastme'), 2001, 2001, '/website/jastme', '/sbin/nologin', 0, now(), now());

创建了一个叫jastme的用户,密码为jastme,用户根目录为/website/jastme


本地测试

ftp 127.0.0.1

输入用户名和密码,OK  ftp会自动新建用户的根目录。


你可能感兴趣的:(proftp 配合 mysql 虚拟用户的配置)