CentOS下Pure-ftp安装配置 - 图1

一、安装 pure-ftp

  1. #默认的yum源不包含pure-ftpd,需先安装epel扩展源
  2. yum install -y epel-release
  3. yum install -y pure-ftpd

二、配置 pure-ftp

1、创建 ftp 系统用户

  1. # 创建用户 ftp
  2. useradd ftp -s /sbin/nologin

2、配置FTP存储根目录

  1. # 创建 FTP 存储根目录
  2. mkdir /data/ftp
  3. # 设置 FTP 根目录权限
  4. chown -R ftp.ftp /data/ftp/

3、编辑 pure-ftp 配置文件

编辑 pure-ftp 配置文件 /etc/pure-ftpd/pure-ftpd.conf 部分参数如下:

  1. # PureDB 用户数据库路径(重要)
  2. PureDB /etc/pure-ftpd/pureftpd.pdb
  3. # 锁定所有用户到家目录中
  4. ChrootEveryone yes
  5. # 如果虚拟用户的目录不存在则自动创建
  6. CreateHomeDir yes
  7. # 兼容不同客户端
  8. BrokenClientsCompatibility yes
  9. # 显示隐藏文件
  10. DisplayDotFiles no
  11. # 防止命令误操作
  12. CustomerProof yes
  13. # 被动模式端口范围
  14. PassivePortRange 30000 50000
  15. # 被动模式 IP
  16. ForcePassiveIP 192.168.1.100
  17. # 只允许匿名用户访问
  18. AnonymousOnly no
  19. # 不允许匿名用户访问(为 no 时允许)
  20. NoAnonymous yes
  21. # 不允许匿名用户上传文件(为 no 时允许)
  22. AnonymousCantUpload yes
  23. # 不允许匿名用户创建目录(为 no 时允许)
  24. AnonymousCanCreateDirs yes
  25. # 仅运行认证用户进行FXP传输
  26. AllowUserFXP no
  27. # 对匿名用户和非匿名用户允许进行匿名 FXP 传输
  28. AllowAnonymousFXP no
  29. # 设置日志的告警级别,默认为 ftp,none 是禁止记录日志
  30. SyslogFacility none

4、创建 ftp 虚拟用户

  1. # 创建 ftp 用户 aaa 家目录
  2. mkdir /data/ftp/aaa
  3. chown -R ftp.ftp /data/ftp/aaa/
  4. # 创建 ftp 用户 aaa, -u 是将虚拟用户 aaa 与系统用户 ftp 关联在一起,aaa 账号登录后是以 ftp 的身份来读取和下载文件,-d 是指定ftp_usera账户的家目录,这样可以使用户 aaa 只能访问其家目录 /data/ftp/aaa/。
  5. pure-pw useradd aaa -u ftp -d /data/ftp/aaa/
  6. # 创建用户信息数据库文件,这一步很关键。
  7. pure-pw mkdb
  8. # 查看已创建的账号列表
  9. pure-pw list

5、启动 pure-ftp 服务

  1. # 启动 pure-ftp 服务
  2. systemctl start pure-ftpd.service
  3. # 添加开机启动项
  4. systemctl enable pure-ftpd.service
  5. # 或使用
  6. systemctl enable --now pure-ftpd.service

6、使用客户端测试连接

使用 Windows 或 Linux 客户端登录 FTP 测试服务是否正常。

三、配置文件 /etc/pure-ftpd/pure-ftpd.conf 完整参数说明

  1. ############################################################
  2. # #
  3. # Configuration file for pure-ftpd wrappers #
  4. # #
  5. ############################################################
  6. # If you want to run Pure-FTPd with this configuration
  7. # instead of command-line options, please run the
  8. # following command :
  9. #
  10. # /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
  11. #
  12. # Please don't forget to have a look at documentation at
  13. # http://www.pureftpd.org/documentation.shtml for a complete list of
  14. # options.
  15. # Cage in every user in his home directory
  16. # 锁定所有用户到家目录中
  17. ChrootEveryone yes
  18. # If the previous option is set to "no", members of the following group
  19. # won't be caged. Others will be. If you don't want chroot()ing anyone,
  20. # just comment out ChrootEveryone and TrustedGID.
  21. # 信任组ID100,可以不锁定
  22. # TrustedGID 100
  23. # Turn on compatibility hacks for broken clients
  24. # 兼容不同客户端
  25. BrokenClientsCompatibility no
  26. # Maximum number of simultaneous users
  27. # 最大的客户端数量
  28. MaxClientsNumber 50
  29. # Fork in background
  30. # 后台运行
  31. Daemonize yes
  32. # Maximum number of sim clients with the same IP address
  33. # 每个ip最大连接数
  34. MaxClientsPerIP 8
  35. # If you want to log all client commands, set this to "yes".
  36. # This directive can be duplicated to also log server responses.
  37. # 记录日志
  38. VerboseLog no
  39. # List dot-files even when the client doesn't send "-a".
  40. # 显示隐藏文件
  41. DisplayDotFiles no
  42. # Don't allow authenticated users - have a public anonymous FTP only.
  43. # 只允许匿名用户访问
  44. AnonymousOnly no
  45. # Disallow anonymous connections. Only allow authenticated users.
  46. # 不允许匿名用户
  47. NoAnonymous yes
  48. # Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
  49. # The default facility is "ftp". "none" disables logging.
  50. # 设置日志的告警级别,默认为ftp,none是禁止记录日志
  51. SyslogFacility ftp
  52. # Display fortune cookies
  53. # 定制用户登陆后的显示信息
  54. # FortunesFile /usr/share/fortune/zippy
  55. # Don't resolve host names in log files. Logs are less verbose, but
  56. # it uses less bandwidth. Set this to "yes" on very busy servers or
  57. # if you don't have a working DNS.
  58. # 是否在日志文件中进行主机名解析,不进行客户端DNS解析
  59. DontResolve yes
  60. # Maximum idle time in minutes (default = 15 minutes)
  61. # 最大空闲时间
  62. MaxIdleTime 30
  63. # LDAP configuration file (see README.LDAP)
  64. # LDAP 配置文件路径
  65. # LDAPConfigFile /etc/pureftpd-ldap.conf
  66. # MySQL configuration file (see README.MySQL)
  67. # MySQL 配置文件路径
  68. MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf
  69. # Postgres configuration file (see README.PGSQL)
  70. # Postgres 配置文件路径
  71. # PGSQLConfigFile /etc/pureftpd-pgsql.conf
  72. # PureDB user database (see README.Virtual-Users)
  73. # PureDB 用户数据库路径
  74. PureDB /usr/local/pureftpd/etc/pureftpd.pdb
  75. # Path to pure-authd socket (see README.Authentication-Modules)
  76. # pure-authd 的socket 路径
  77. # ExtAuth /var/run/ftpd.sock
  78. # If you want to enable PAM authentication, uncomment the following line
  79. # 如果你要启用 PAM 认证方式, 去掉下面行的注释
  80. # PAMAuthentication yes
  81. # If you want simple Unix (/etc/passwd) authentication, uncomment this
  82. # 如果你要启用 简单的 Unix系统 认证方式(/etc/passwd), 去掉下面行的注释
  83. # UnixAuthentication yes
  84. # Please note that LDAPConfigFile, MySQLConfigFile, PAMAuthentication and
  85. # UnixAuthentication can be used only once, but they can be combined
  86. # together. For instance, if you use MySQLConfigFile, then UnixAuthentication,
  87. # the SQL server will be asked. If the SQL authentication fails because the
  88. # user wasn't found, another try # will be done with /etc/passwd and
  89. # /etc/shadow. If the SQL authentication fails because the password was wrong,
  90. # the authentication chain stops here. Authentication methods are chained in
  91. # the order they are given.
  92. # 'ls' recursion limits. The first argument is the maximum number of
  93. # files to be displayed. The second one is the max subdirectories depth
  94. # 'ls' 命令的递归限制。第一个参数给出文件显示的最大数目。第二个参数给出最大的子目录深度。
  95. LimitRecursion 10000 8
  96. # Are anonymous users allowed to create new directories ?
  97. # 是否允许匿名用户创建新目录
  98. AnonymousCanCreateDirs no
  99. # If the system is more loaded than the following value,
  100. # anonymous users aren't allowed to download.
  101. # 超出负载后禁止下载
  102. MaxLoad 4
  103. # Port range for passive connections replies. - for firewalling.
  104. # 被动模式的端口范围
  105. # PassivePortRange 30000 50000
  106. # Force an IP address in PASV/EPSV/SPSV replies. - for NAT.
  107. # Symbolic host names are also accepted for gateways with dynamic IP
  108. # addresses.
  109. # 强制一个IP地址使用被动响应
  110. # ForcePassiveIP 192.168.0.1
  111. # Upload/download ratio for anonymous users.
  112. # 匿名用户的上传/下载的比率
  113. # AnonymousRatio 1 10
  114. # Upload/download ratio for all users.
  115. # This directive superscedes the previous one.
  116. # 所有用户的上传/下载的比率
  117. # UserRatio 1 10
  118. # Disallow downloading of files owned by "ftp", ie.
  119. # files that were uploaded but not validated by a local admin.
  120. # 禁止下载匿名用户上传但未经验证的文件
  121. AntiWarez yes
  122. # IP address/port to listen to (default=all IP and port 21).
  123. # 服务监听的IP 地址和端口。(默认是所有IP地址和21端口)
  124. # Bind 127.0.0.1,21
  125. # Maximum bandwidth for anonymous users in KB/s
  126. # 匿名用户带宽限制(KB)
  127. # AnonymousBandwidth 8
  128. # Maximum bandwidth for *all* users (including anonymous) in KB/s
  129. # Use AnonymousBandwidth *or* UserBandwidth, both makes no sense.
  130. # 所有用户的最大带宽(KB/s),包括匿名用户。
  131. UserBandwidth 1024
  132. # File creation mask. <umask for files>:<umask for dirs> .
  133. # 177:077 if you feel paranoid.
  134. # 新建目录及文件的属性掩码值
  135. Umask 133:022
  136. # Minimum UID for an authenticated user to log in.
  137. # 认证用户允许登陆的最小组ID(UID)
  138. MinUID 100
  139. # Allow FXP transfers for authenticated users.
  140. # 仅允许认证用户进行 FXP 传输。
  141. AllowUserFXP no
  142. # Allow anonymous FXP for anonymous and non-anonymous users.
  143. # 对匿名用户和非匿名用户允许进行匿名 FXP 传输
  144. AllowAnonymousFXP no
  145. # Users can't delete/write files beginning with a dot ('.')
  146. # even if they own them. If TrustedGID is enabled, this group
  147. # will have access to dot-files, though.
  148. # 不能删除/写入隐藏文件
  149. ProhibitDotFilesWrite no
  150. # Prohibit *reading* of files beginning with a dot (.history, .ssh...)
  151. # 禁止读取隐藏文件
  152. ProhibitDotFilesRead no
  153. # Never overwrite files. When a file whose name already exist is uploaded,
  154. # it get automatically renamed to file.1, file.2, file.3, ...
  155. # 有同名文件时自动重新命名
  156. AutoRename no
  157. # Disallow anonymous users to upload new files (no = upload is allowed)
  158. # 不允许匿名用户上传文件
  159. AnonymousCantUpload no
  160. # Only connections to this specific IP address are allowed to be
  161. # non-anonymous. You can use this directive to open several public IPs for
  162. # anonymous FTP, and keep a private firewalled IP for remote administration.
  163. # You can also only allow a non-routable local IP (like 10.x.x.x) to
  164. # authenticate, and keep a public anon-only FTP server on another IP.
  165. # 仅允许来自以下IP地址的非匿名用户连接。你可以使用这个指令来打开几个公网IP来提供匿名FTP,
  166. # 而保留一个私有的防火墙保护的IP来进行远程管理。你还可以只允许一内网地址进行认证,而在另外
  167. # 一个IP上提供纯匿名的FTP服务。
  168. #
  169. #TrustedIP 10.1.1.1
  170. # If you want to add the PID to every logged line, uncomment the following
  171. # line.
  172. # 如果你要为日志每一行添加 PID 去掉下面行的注释
  173. #LogPID yes
  174. # Create an additional log file with transfers logged in a Apache-like format :
  175. # fw.c9x.org - jedi [13/Dec/1975:19:36:39] "GET /ftp/linux.tar.bz2" 200 21809338
  176. # This log file can then be processed by www traffic analyzers.
  177. # 使用类似于Apache的格式创建一个额外的日志文件
  178. # AltLog clf:/var/log/pureftpd.log
  179. # Create an additional log file with transfers logged in a format optimized
  180. # for statistic reports.
  181. # 使用优化过的格式为统计报告创建一个额外的日志文件
  182. # AltLog stats:/var/log/pureftpd.log
  183. # Create an additional log file with transfers logged in the standard W3C
  184. # format (compatible with most commercial log analyzers)
  185. # 使用标准的W3C格式创建一个额外的日志文件
  186. # AltLog w3c:/var/log/pureftpd.log
  187. # Disallow the CHMOD command. Users can't change perms of their files.
  188. # 不接受 CHMOD 命令。用户不能更改他们文件的属性
  189. #NoChmod yes
  190. # Allow users to resume and upload files, but *NOT* to delete them.
  191. # 允许用户恢复和上传文件,却不允许删除他们
  192. #KeepAllFiles yes
  193. # Automatically create home directories if they are missing
  194. # 用户主目录不存在的话,自动创建
  195. CreateHomeDir yes
  196. # Enable virtual quotas. The first number is the max number of files.
  197. # The second number is the max size of megabytes.
  198. # So 1000:10 limits every user to 1000 files and 10 Mb.
  199. # 限制用户可以创建的最大文件数和用户空间大小
  200. Quota 10000:10240
  201. # If your pure-ftpd has been compiled with standalone support, you can change
  202. # the location of the pid file. The default is /var/run/pure-ftpd.pid
  203. # PID文件位置
  204. #PIDFile /var/run/pure-ftpd.pid
  205. # If your pure-ftpd has been compiled with pure-uploadscript support,
  206. # this will make pure-ftpd write info about new uploads to
  207. # /var/run/pure-ftpd.upload.pipe so pure-uploadscript can read it and
  208. # spawn a script to handle the upload.
  209. # Don't enable this option if you don't actually use pure-uploadscript.
  210. # 如果你的 pure-ftpd 编译时加入了 pure-uploadscript 支持,这个指令将会使 pure-ftpd
  211. # 发送关于新上传的情况信息到 /var/run/pure-ftpd.upload.pipe,这样 pure-uploadscript
  212. # 就能读然后调用一个脚本去处理新的上传
  213. #
  214. #CallUploadScript yes
  215. # This option is useful with servers where anonymous upload is
  216. # allowed. As /var/ftp is in /var, it save some space and protect
  217. # the log files. When the partition is more that X percent full,
  218. # new uploads are disallowed.
  219. # 文件所在磁盘的最大使用率
  220. MaxDiskUsage 99
  221. # Set to 'yes' if you don't want your users to rename files.
  222. # 是否允许重命名文件(默认不允许)
  223. #NoRename yes
  224. # Be 'customer proof' : workaround against common customer mistakes like
  225. # 'chmod 0 public_html', that are valid, but that could cause ignorant
  226. # customers to lock their files, and then keep your technical support busy
  227. # with silly issues. If you're sure all your users have some basic Unix
  228. # knowledge, this feature is useless. If you're a hosting service, enable it.
  229. # 打开以防止用户犯常识性错误
  230. CustomerProof yes
  231. # Per-user concurrency limits. It will only work if the FTP server has
  232. # been compiled with --with-peruserlimits (and this is the case on
  233. # most binary distributions) .
  234. # The format is : <max sessions per user>:<max anonymous sessions>
  235. # For instance, 3:20 means that the same authenticated user can have 3 active
  236. # sessions max. And there are 20 anonymous sessions max.
  237. # 单个用户限制:每一个用户最大允许的进程;最大的匿名用户进程
  238. # PerUserLimits 3:20
  239. # When a file is uploaded and there is already a previous version of the file
  240. # with the same name, the old file will neither get removed nor truncated.
  241. # Upload will take place in a temporary file and once the upload is complete,
  242. # the switch to the new version will be atomic. For instance, when a large PHP
  243. # script is being uploaded, the web server will still serve the old version and
  244. # immediatly switch to the new one as soon as the full file will have been
  245. # transfered. This option is incompatible with virtual quotas.
  246. # NoTruncate yes
  247. # This option can accept three values :
  248. # 0 : disable SSL/TLS encryption layer (default).
  249. # 1 : accept both traditional and encrypted sessions.
  250. # 2 : refuse connections that don't use SSL/TLS security mechanisms,
  251. # including anonymous sessions.
  252. # Do _not_ uncomment this blindly. Be sure that :
  253. # 1) Your server has been compiled with SSL/TLS support (--with-tls),
  254. # 2) A valid certificate is in place,
  255. # 3) Only compatible clients will log in.
  256. # TLS 1
  257. # List of ciphers that will be accepted for SSL/TLS connections
  258. # Prefix with -S: in order to totally disable SSL but not TLS.
  259. # TLSCipherSuite HIGH:MEDIUM:+TLSv1:!SSLv2:+SSLv3
  260. # Listen only to IPv4 addresses in standalone mode (ie. disable IPv6)
  261. # By default, both IPv4 and IPv6 are enabled.
  262. # IPV4Only yes
  263. # Listen only to IPv6 addresses in standalone mode (ie. disable IPv4)
  264. # By default, both IPv4 and IPv6 are enabled.
  265. # IPV6Only yes
  266. # UTF-8 support for file names (RFC 2640)
  267. # Define charset of the server filesystem and optionnally the default charset
  268. # for remote clients if they don't use UTF-8.
  269. # Works only if pure-ftpd has been compiled with --with-rfc2640
  270. # FileSystemCharset big5
  271. # ClientCharset big5