博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
proftp 配合 mysql 虚拟用户的配置
阅读量:5938 次
发布时间:2019-06-19

本文共 8057 字,大约阅读时间需要 26 分钟。

  hot3.png

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

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  database_user user_password

SQLConnectInfo  ftp  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会自动新建用户的根目录。

转载于:https://my.oschina.net/jastme/blog/323438

你可能感兴趣的文章
python 中的字符和字符串
查看>>
C#Winform限制Textbox只能输入数字
查看>>
EL表达式经典用法
查看>>
java.lang.NoClassDefFoundError: javax/mail/Authenticator
查看>>
联想集团涨超7% 杨元庆持股比例升至8.12%
查看>>
各省光伏十三五规划汇总:总规模将超130GW
查看>>
Apache Storm 官方文档 —— 常用模式
查看>>
聊聊JVM的年轻代
查看>>
lvm逻辑卷管理
查看>>
VS2010不能断点/下断的问题
查看>>
[Android]权限处理
查看>>
Spark bind on port 0. Attempting port 1 问题解决
查看>>
兼容所有浏览器的复制到剪切板功能,悬浮层不能复制问题解决
查看>>
day 20 第一阶段考试总结
查看>>
我的友情链接
查看>>
Centos 7.5 部署DNS
查看>>
yum简介
查看>>
cp讲解
查看>>
MariaDB Galera Cluster 部署(如何快速部署MariaDB集群)
查看>>
如何在 Swift 语言下使用 iOS Charts API 制作漂亮图表?
查看>>