基于Pureftpd+MySQL的FTP服务器的搭建
假设我们的服务器上边已安装了mysql server和pureftpd,我们需要对pureftpd的配置文件进行更改,使用ports方式安装的pureftpd的配置文件默认保存在/usr/local/etc/目录中,系统会自动为我们创建几个…
本文目录
假设我们的服务器上边已安装了mysql server和pureftpd,我们需要对pureftpd的配置文件进行更改,使用ports方式安装的pureftpd的配置文件默认保存在/usr/local/etc/目录中,系统会自动为我们创建几个sample文件,如:
pure-ftpd.conf.sample
pureftpd-ldap.conf.sample
pureftpd-mysql.conf.sample
pureftpd-pgsql.conf.sample
等.
我们直接在这些文件的基础上进行配置吧.
1cp /usr/local/etc/pure-ftpd.conf.sample /usr/local/etc/pure-ftpd.conf
2cp /usr/local/etc/pureftpd-mysql.conf.sample /usr/local/etc/pureftpd-mysql.conf然后直接对/usr/local/etc/pure-ftpd.conf和/usr/local/etc/pureftpd-mysql.conf进行修改,得到的内容如下:
1more /usr/local/etc/pure-ftpd.conf
2
3############################################################
4# #
5# Configuration file for pure-ftpd wrappers #
6# #
7############################################################
8
9# If you want to run Pure-FTPd with this configuration
10# instead of command-line options, please run the
11# following command :
12#
13# /usr/local/sbin/pure-config.pl /usr/local/etc/pure-ftpd.conf
14#
15# Please don't forget to have a look at documentation at
16# http://www.pureftpd.org/documentation.shtml for a complete list of
17# options.
18
19# Cage in every user in his home directory
20
21ChrootEveryone yes
22
23# If the previous option is set to "no", members of the following group
24# won't be caged. Others will be. If you don't want chroot()ing anyone,
25# just comment out ChrootEveryone and TrustedGID.
26
27# TrustedGID 100
28
29# Turn on compatibility hacks for broken clients
30
31BrokenClientsCompatibility no
32
33# Maximum number of simultaneous users
34
35MaxClientsNumber 50
36
37# Fork in background
38
39Daemonize yes
40
41# Maximum number of sim clients with the same IP address
42
43MaxClientsPerIP 8
44
45# If you want to log all client commands, set this to "yes".
46# This directive can be duplicated to also log server responses.
47
48VerboseLog no
49
50# List dot-files even when the client doesn't send "-a".
51
52DisplayDotFiles yes
53
54# Don't allow authenticated users - have a public anonymous FTP only.
55
56AnonymousOnly no
57
58# Disallow anonymous connections. Only allow authenticated users.
59
60NoAnonymous no
61
62# Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
63# The default facility is "ftp". "none" disables logging.
64
65SyslogFacility ftp
66
67# Display fortune cookies
68
69# 自定义ftp欢迎信息
70# FortunesFile /usr/share/fortune/zippy
71FortunesFile /ftpdatadir/welcome.msg
72
73# Don't resolve host names in log files. Logs are less verbose, but
74# it uses less bandwidth. Set this to "yes" on very busy servers or
75# if you don't have a working DNS.
76
77DontResolve yes
78
79# Maximum idle time in minutes (default = 15 minutes)
80
81MaxIdleTime 15
82
83# LDAP configuration file (see README.LDAP)
84
85# LDAPConfigFile /etc/pureftpd-ldap.conf
86
87# MySQL configuration file (see README.MySQL)
88
89# 指定用于身份验证的mysql配置文件
90# MySQLConfigFile /etc/pureftpd-mysql.conf
91MySQLConfigFile /usr/local/etc/pureftpd-mysql.conf
92
93# Postgres configuration file (see README.PGSQL)
94
95# PGSQLConfigFile /etc/pureftpd-pgsql.conf
96
97# PureDB user database (see README.Virtual-Users)
98
99# PureDB /etc/pureftpd.pdb
100
101# Path to pure-authd socket (see README.Authentication-Modules)
102
103# ExtAuth /var/run/ftpd.sock
104
105# If you want to enable PAM authentication, uncomment the following line
106
107# PAMAuthentication yes
108
109# If you want simple Unix (/etc/passwd) authentication, uncomment this
110
111# UnixAuthentication yes
112
113# Please note that LDAPConfigFile, MySQLConfigFile, PAMAuthentication and
114# UnixAuthentication can be used only once, but they can be combined
115# together. For instance, if you use MySQLConfigFile, then UnixAuthentication,
116# the SQL server will be asked. If the SQL authentication fails because the
117# user wasn't found, another try # will be done with /etc/passwd and
118# /etc/shadow. If the SQL authentication fails because the password was wrong,
119# the authentication chain stops here. Authentication methods are chained in
120# the order they are given.
121
122# 'ls' recursion limits. The first argument is the maximum number of
123# files to be displayed. The second one is the max subdirectories depth
124
125# 如果你的FTP里边的文件个数比较多,文件夹比较深,你就需要修改这个参数了...
126LimitRecursion 20000 8
127
128# Are anonymous users allowed to create new directories ?
129
130AnonymousCanCreateDirs no
131
132# If the system is more loaded than the following value,
133# anonymous users aren't allowed to download.
134
135MaxLoad 4
136
137# Port range for passive connections replies. - for firewalling.
138
139# PassivePortRange 30000 50000
140
141# Force an IP address in PASV/EPSV/SPSV replies. - for NAT.
142# Symbolic host names are also accepted for gateways with dynamic IP
143# addresses.
144
145# ForcePassiveIP 192.168.0.1
146
147# Upload/download ratio for anonymous users.
148
149# AnonymousRatio 1 10
150
151# Upload/download ratio for all users.
152# This directive superscedes the previous one.
153
154# UserRatio 1 10
155
156# Disallow downloading of files owned by "ftp", ie.
157# files that were uploaded but not validated by a local admin.
158
159AntiWarez yes
160
161# IP address/port to listen to (default=all IP and port 21).
162
163# Bind 127.0.0.1,21
164
165# Maximum bandwidth for anonymous users in KB/s
166
167# AnonymousBandwidth 8
168
169# Maximum bandwidth for *all* users (including anonymous) in KB/s
170# Use AnonymousBandwidth *or* UserBandwidth, both makes no sense.
171
172# UserBandwidth 8
173
174# File creation mask. :.
175# 177:077 if you feel paranoid.
176
177Umask 133:022
178
179# Minimum UID for an authenticated user to log in.
180
181MinUID 100
182
183# Allow FXP transfers for authenticated users.
184
185AllowUserFXP no
186
187# Allow anonymous FXP for anonymous and non-anonymous users.
188
189AllowAnonymousFXP no
190
191# Users can't delete/write files beginning with a dot ('.')
192# even if they own them. If TrustedGID is enabled, this group
193# will have access to dot-files, though.
194
195ProhibitDotFilesWrite no
196
197# Prohibit *reading* of files beginning with a dot (.history, .ssh...)
198
199ProhibitDotFilesRead no
200
201# Never overwrite files. When a file whoose name already exist is uploaded,
202# it get automatically renamed to file.1, file.2, file.3, ...
203
204AutoRename no
205
206# Disallow anonymous users to upload new files (no = upload is allowed)
207
208AnonymousCantUpload no
209
210# Only connections to this specific IP address are allowed to be
211# non-anonymous. You can use this directive to open several public IPs for
212# anonymous FTP, and keep a private firewalled IP for remote administration.
213# You can also only allow a non-routable local IP (like 10.x.x.x) to
214# authenticate, and keep a public anon-only FTP server on another IP.
215
216#TrustedIP 10.1.1.1
217
218# If you want to add the PID to every logged line, uncomment the following
219# line.
220
221#LogPID yes
222
223# Create an additional log file with transfers logged in a Apache-like format :
224# fw.c9x.org - jedi [13/Dec/1975:19:36:39] "GET /ftp/linux.tar.bz2" 200 21809338
225# This log file can then be processed by www traffic analyzers.
226
227# AltLog clf:/var/log/pureftpd.log
228
229# Create an additional log file with transfers logged in a format optimized
230# for statistic reports.
231
232# AltLog stats:/var/log/pureftpd.log
233
234# Create an additional log file with transfers logged in the standard W3C
235# format (compatible with most commercial log analyzers)
236
237# AltLog w3c:/var/log/pureftpd.log
238
239# Disallow the CHMOD command. Users can't change perms of their files.
240
241#NoChmod yes
242
243# Allow users to resume and upload files, but *NOT* to delete them.
244
245#KeepAllFiles yes
246
247# Automatically create home directories if they are missing
248
249#CreateHomeDir yes
250
251# Enable virtual quotas. The first number is the max number of files.
252# The second number is the max size of megabytes.
253# So 1000:10 limits every user to 1000 files and 10 Mb.
254
255#Quota 1000:10
256
257# If your pure-ftpd has been compiled with standalone support, you can change
258# the location of the pid file. The default is /var/run/pure-ftpd.pid
259
260#PIDFile /var/run/pure-ftpd.pid
261
262# If your pure-ftpd has been compiled with pure-uploadscript support,
263# this will make pure-ftpd write info about new uploads to
264# /var/run/pure-ftpd.upload.pipe so pure-uploadscript can read it and
265# spawn a script to handle the upload.
266
267#CallUploadScript yes
268
269# This option is useful with servers where anonymous upload is
270# allowed. As /var/ftp is in /var, it save some space and protect
271# the log files. When the partition is more that X percent full,
272# new uploads are disallowed.
273
274MaxDiskUsage 95
275
276# Set to 'yes' if you don't want your users to rename files.
277
278#NoRename yes
279
280# Be 'customer proof' : workaround against common customer mistakes like
281# 'chmod 0 public_html', that are valid, but that could cause ignorant
282# customers to lock their files, and then keep your technical support busy
283# with silly issues. If you're sure all your users have some basic Unix
284# knowledge, this feature is useless. If you're a hosting service, enable it.
285
286CustomerProof yes
287
288# Per-user concurrency limits. It will only work if the FTP server has
289# been compiled with --with-peruserlimits (and this is the case on
290# most binary distributions) .
291# The format is : :
292# For instance, 3:20 means that the same authenticated user can have 3 active
293# sessions max. And there are 20 anonymous sessions max.
294
295# PerUserLimits 3:20
296
297# When a file is uploaded and there is already a previous version of the file
298# with the same name, the old file will neither get removed nor truncated.
299# Upload will take place in a temporary file and once the upload is complete,
300# the switch to the new version will be atomic. For instance, when a large PHP
301# script is being uploaded, the web server will still serve the old version and
302# immediatly switch to the new one as soon as the full file will have been
303# transfered. This option is incompatible with virtual quotas.
304
305# NoTruncate yes
306
307# This option can accept three values :
308# 0 : disable SSL/TLS encryption layer (default).
309# 1 : accept both traditional and encrypted sessions.
310# 2 : refuse connections that don't use SSL/TLS security mechanisms,
311# including anonymous sessions.
312# Do _not_ uncomment this blindly. Be sure that :
313# 1) Your server has been compiled with SSL/TLS support (--with-tls),
314# 2) A valid certificate is in place,
315# 3) Only compatible clients will log in.
316
317# TLS 1
318
319# Listen only to IPv4 addresses in standalone mode (ie. disable IPv6)
320# By default, both IPv4 and IPv6 are enabled.
321
322# IPV4Only yes
323
324# Listen only to IPv6 addresses in standalone mode (ie. disable IPv4)
325# By default, both IPv4 and IPv6 are enabled.
326
327# IPV6Only yes
328
329# UTF-8 support for file names (RFC 2640)
330# Define charset of the server filesystem and optionnally the default charset
331# for remote clients if they don't use UTF-8.
332# Works only if pure-ftpd has been compiled with --with-rfc2640
333
334# FileSystemCharset big5
335# ClientCharset big5
336FileSystemCharset gb2312
337ClientCharset gb2312 1more /usr/local/etc/pureftpd-mysql.conf
2
3##############################################
4# #
5# Sample Pure-FTPd Mysql configuration file. #
6# See README.MySQL for explanations. #
7# #
8##############################################
9
10# Optional : MySQL server name or IP. Don't define this for unix sockets.
11
12MYSQLServer 127.0.0.1
13
14# Optional : MySQL port. Don't define this if a local unix socket is used.
15
16# MYSQLPort 3306
17
18# Optional : define the location of mysql.sock if the server runs on this host.
19
20MYSQLSocket /tmp/mysql.sock
21
22# Mandatory : user to bind the server as.
23
24MYSQLUser root
25
26# Mandatory : user password. You must have a password.
27
28MYSQLPassword rootpw
29
30# Mandatory : database to open.
31
32MYSQLDatabase pureftpd
33
34# Mandatory : how passwords are stored
35# Valid values are : "cleartext", "crypt", "md5" and "password"
36# ("password" = MySQL password() function)
37# You can also use "any" to try "crypt", "md5" *and* "password"
38
39#MYSQLCrypt cleartext
40MYSQLCrypt crypt
41
42# In the following directives, parts of the strings are replaced at
43# run-time before performing queries :
44#
45# \L is replaced by the login of the user trying to authenticate.
46# \I is replaced by the IP address the user connected to.
47# \P is replaced by the port number the user connected to.
48# \R is replaced by the IP address the user connected from.
49# \D is replaced by the remote IP address, as a long decimal number.
50#
51# Very complex queries can be performed using these substitution strings,
52# especially for virtual hosting.
53
54# Query to execute in order to fetch the password
55
56#MYSQLGetPW SELECT Password FROM users WHERE User="\L"
57# 自定义验证语句
58MYSQLGetPW SELECT user_password FROM users WHERE user_name="\L" and host_group="\I" and auth_by="ftp" and (exceed_date >= date(now()) or user_always_effective = 1)
59
60# Query to execute in order to fetch the system user name or uid
61
62#MYSQLGetUID SELECT Uid FROM users WHERE User="\L"
63MYSQLGetUID SELECT uid FROM users WHERE user_name="\L" and host_group="\I" and auth_by="ftp"
64
65# Optional : default UID - if set this overrides MYSQLGetUID
66
67MYSQLDefaultUID 1000
68
69# Query to execute in order to fetch the system user group or gid
70
71#MYSQLGetGID SELECT Gid FROM users WHERE User="\L"
72MYSQLGetGID SELECT gid FROM users WHERE user_name="\L" and host_group="\I" and auth_by="ftp"
73
74# Optional : default GID - if set this overrides MYSQLGetGID
75
76MYSQLDefaultGID 1000
77
78# Query to execute in order to fetch the home directory
79
80#MYSQLGetDir SELECT Dir FROM users WHERE User="\L"
81MYSQLGetDir SELECT ftp_dir FROM users WHERE user_name="\L" and host_group="\I" and auth_by="ftp"
82
83# Optional : query to get the maximal number of files
84# Pure-FTPd must have been compiled with virtual quotas support.
85
86# MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User="\L"
87
88# Optional : query to get the maximal disk usage (virtual quotas)
89# The number should be in Megabytes.
90# Pure-FTPd must have been compiled with virtual quotas support.
91
92# MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User="\L"
93
94# Optional : ratios. The server has to be compiled with ratio support.
95
96# MySQLGetRatioUL SELECT ULRatio FROM users WHERE User="\L"
97# MySQLGetRatioDL SELECT DLRatio FROM users WHERE User="\L"
98
99# Optional : bandwidth throttling.
100# The server has to be compiled with throttling support.
101# Values are in KB/s .
102
103# MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="\L"
104# MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="\L"
105
106# Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
107# 1) You know what you are doing.
108# 2) Real and virtual users match.
109
110# MySQLForceTildeExpansion 1
111
112# If you upgraded your tables to transactionnal tables (Gemini,
113# BerkeleyDB, Innobase...), you can enable SQL transactions to
114# avoid races. Leave this commented if you are using the
115# traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.
116
117# MySQLTransactions On然后用pureftpd数据库users表中的用户登录和密码登录就可以了.需要注意的是,users表的user_password的加密方式是mysql的encrpty().
edit(20200326):
补充多几句。在用于认证的 pureftpd 数据库中,users 表的 uid/gid 字段代表当初目录下的权限用户。如果是全权限用户,可以用当前用户的 uid/gid,如果是只读用户,可以用 9999/gid 来代替。
评论
正在载入评论…