一、下载源码
wget https://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.47.tar.gz tar -zxvf pure-ftpd-1.0.47.tar.gz
二、编译
./configure --prefix=/usr/local/pureftpd --with-everything --with-cookie --with-diraliases --with-extauth --with-ftpwho --with-language=english --with-ldap --with-minimal --with-mysql --with-tls
命令解释:
--with-everything //安装几乎所有的功能,包括altlog、cookies、throttling、ratios、ftpwho、upload script、virtual users(puredb)、quotas、virtual hosts、directory aliases、external authentication、Bonjour、privilege separation本次安装只使用这个选项。 --with-cookie //当用户登录时显示指定的横幅 --with-diraliases //支持目录别名,用快捷方式代cd命令 --with-extauth //编译支持扩展验证的模块,大多数用户不使用这个选项 --with-ftpwho //支持pure-ftpwho命令,启用这个功能需要更多的额外内存 --with-language=english //修改服务器语言,默认是英文,如果你要做修改,请翻译‘src/messages_en.h’文件 --with-ldap //LADP目录支持,需要安装openldap --with-minimal //FTP最小安装,最基本的功能 --with-mysql //MySQL支持,如果MySQL安装在自定义目录上,你需要使用命令—with-mysql=/usr/local/mysq这类 --with-nonroot //不需要root用户就可以启动服务 --with-tls // 添加ssl证书支持
三、编译错误解决
configure: error: PAM headers not found. apt install libpam0g-dev configure: error: liblber is needed for LDAP support apt install libldap2-dev configure: error: libmysqlclient is needed for MySQL support apt install libmysqlclient-dev configure: error: OpenSSL headers not found. apt install libssl-dev
四、编译安装
make & make install
五、生成证书
openssl req -x509 -nodes -newkey rsa:1024 -keyout /usr/local/pureftpd/etc/pure-ftpd.pem -out /usr/local/pureftpd/etc/pure-ftpd.pem
六、编辑配置文件
vim /usr/local/pureftpd/etc/pure-ftpd.conf
ChrootEveryone yes BrokenClientsCompatibility no MaxClientsNumber 50 Daemonize no MaxClientsPerIP 10 VerboseLog no DisplayDotFiles yes AnonymousOnly no NoAnonymous yes SyslogFacility ftp DontResolve yes MaxIdleTime 15 PureDB /usr/local/pureftpd/etc/pureftpd.pdb UnixAuthentication yes LimitRecursion 20000 8 AnonymousCanCreateDirs no MaxLoad 4 PassivePortRange 30000 40000 AntiWarez yes Umask 133:022 MinUID 100 AllowUserFXP no AllowAnonymousFXP no ProhibitDotFilesWrite no ProhibitDotFilesRead no AutoRename no AnonymousCantUpload no CreateHomeDir no PIDFile /var/run/pure-ftpd.pid MaxDiskUsage 99 CustomerProof yes TLS 1 CertFile /usr/local/pureftpd/etc/pure-ftpd.pem IPV4Only yes AllowOverwrite on AllowStoreRestart on
############################################################ # # # Configuration file for pure-ftpd # # # ############################################################ # If you want to run Pure-FTPd with this configuration # instead of command-line options, please run the # following command : # # /usr/local/pureftpd/sbin/pure-ftpd /usr/local/pureftpd/etc/etc/pure-ftpd.conf # # Online documentation: # https://www.pureftpd.org/project/pure-ftpd/doc # Restrict users to their home directory ChrootEveryone yes # If the previous option is set to "no", members of the following group # won't be restricted. Others will be. If you don't want chroot()ing anyone, # just comment out ChrootEveryone and TrustedGID. # TrustedGID 100 # Turn on compatibility hacks for broken clients BrokenClientsCompatibility no # Maximum number of simultaneous users MaxClientsNumber 50 # Run as a background process Daemonize no # Maximum number of simultaneous clients with the same IP address MaxClientsPerIP 10 # If you want to log all client commands, set this to "yes". # This directive can be specified twice to also log server responses. VerboseLog no # List dot-files even when the client doesn't send "-a". DisplayDotFiles yes # Disallow authenticated users - Act only as a public FTP server. AnonymousOnly no # Disallow anonymous connections. Only accept authenticated users. NoAnonymous yes # Syslog facility (auth, authpriv, daemon, ftp, security, user, local*) # The default facility is "ftp". "none" disables logging. SyslogFacility ftp # Display fortune cookies # FortunesFile /usr/share/fortune/zippy # Don't resolve host names in log files. Recommended unless you trust # reverse host names, and don't care about DNS resolution being possibly slow. DontResolve yes # Maximum idle time in minutes (default = 15 minutes) MaxIdleTime 15 # LDAP configuration file (see README.LDAP) # LDAPConfigFile /etc/pureftpd-ldap.conf # MySQL configuration file (see README.MySQL) # MySQLConfigFile /etc/pureftpd-mysql.conf # PostgreSQL configuration file (see README.PGSQL) # PGSQLConfigFile /etc/pureftpd-pgsql.conf # PureDB user database (see README.Virtual-Users) PureDB /usr/local/pureftpd/etc/pureftpd.pdb # Path to pure-authd socket (see README.Authentication-Modules) # ExtAuth /var/run/ftpd.sock # If you want to enable PAM authentication, uncomment the following line # PAMAuthentication yes # If you want simple Unix (/etc/passwd) authentication, uncomment this UnixAuthentication yes # Please note that LDAPConfigFile, MySQLConfigFile, PAMAuthentication and # UnixAuthentication can be used specified once, but can be combined # together. For instance, if you use MySQLConfigFile, then UnixAuthentication, # the SQL server will be used first. If the SQL authentication fails because the # user wasn't found, a new attempt will be done using system authentication. # If the SQL authentication fails because the password didn't match, the # authentication chain stops here. Authentication methods are chained in # the order they are given. # 'ls' recursion limits. The first argument is the maximum number of # files to be displayed. The second one is the max subdirectories depth. LimitRecursion 20000 8 # Are anonymous users allowed to create new directories? AnonymousCanCreateDirs no # If the system load is greater than the given value, anonymous users # aren't allowed to download. MaxLoad 4 # Port range for passive connections - keep it as broad as possible. PassivePortRange 30000 40000 # Force an IP address in PASV/EPSV/SPSV replies. - for NAT. # Symbolic host names are also accepted for gateways with dynamic IP # addresses. # ForcePassiveIP 192.168.0.1 # Upload/download ratio for anonymous users. # AnonymousRatio 1 10 # Upload/download ratio for all users. # This directive supersedes the previous one. # UserRatio 1 10 # Disallow downloads of files owned by the "ftp" system user; # files that were uploaded but not validated by a local admin. AntiWarez yes # IP address/port to listen to (default=all IP addresses, port 21). # Bind 127.0.0.1,21 # Maximum bandwidth for anonymous users in KB/s # AnonymousBandwidth 8 # Maximum bandwidth for *all* users (including anonymous) in KB/s # Use AnonymousBandwidth *or* UserBandwidth, not both. # UserBandwidth 8 # File creation mask. : . # 177:077 if you feel paranoid. Umask 133:022 # Minimum UID for an authenticated user to log in. # For example, a value of 100 prevents all users whose user id is below # 100 from logging in. If you want "root" to be able to log in, use 0. MinUID 100 # Allow FXP transfers for authenticated users. AllowUserFXP no # Allow anonymous FXP for anonymous and non-anonymous users. AllowAnonymousFXP no # Users can't delete/write files starting with a dot ('.') # even if they own them. But if TrustedGID is enabled, that group # will exceptionally have access to dot-files. ProhibitDotFilesWrite no # Prohibit *reading* of files starting with a dot (.history, .ssh...) ProhibitDotFilesRead no # Don't overwrite files. When a file whose name already exist is uploaded, # it gets automatically renamed to file.1, file.2, file.3, ... AutoRename no # Prevent anonymous users from uploading new files (no = upload is allowed) AnonymousCantUpload no # Only connections to this specific IP address are allowed to be # non-anonymous. You can use this directive to open several public IPs for # anonymous FTP, and keep a private firewalled IP for remote administration. # You can also only allow a non-routable local IP (such as 10.x.x.x) for # authenticated users, and run a public anon-only FTP server on another IP. # TrustedIP 10.1.1.1 # To add the PID to log entries, uncomment the following line. # LogPID yes # Create an additional log file with transfers logged in a Apache-like format : # fw.c9x.org - jedi [13/Apr/2017:19:36:39] "GET /ftp/linux.tar.bz2" 200 21809338 # This log file can then be processed by common HTTP traffic analyzers. # AltLog clf:/var/log/pureftpd.log # Create an additional log file with transfers logged in a format optimized # for statistic reports. # AltLog stats:/var/log/pureftpd.log # Create an additional log file with transfers logged in the standard W3C # format (compatible with many HTTP log analyzers) # AltLog w3c:/var/log/pureftpd.log # Disallow the CHMOD command. Users cannot change perms of their own files. # NoChmod yes # Allow users to resume/upload files, but *NOT* to delete them. # KeepAllFiles yes # Automatically create home directories if they are missing CreateHomeDir no # Enable virtual quotas. The first value is the max number of files. # The second value is the maximum size, in megabytes. # So 1000:10 limits every user to 1000 files and 10 MB. # Quota 1000:10 # If your pure-ftpd has been compiled with standalone support, you can change # the location of the pid file. The default is /var/run/pure-ftpd.pid PIDFile /var/run/pure-ftpd.pid # If your pure-ftpd has been compiled with pure-uploadscript support, # this will make pure-ftpd write info about new uploads to # /var/run/pure-ftpd.upload.pipe so pure-uploadscript can read it and # spawn a script to handle the upload. # Don't enable this option if you don't actually use pure-uploadscript. # CallUploadScript yes # This option is useful on servers where anonymous upload is # allowed. When the partition is more that percententage full, # new uploads are disallowed. MaxDiskUsage 99 # Set to 'yes' to prevent users from renaming files. # NoRename yes # Be 'customer proof': forbids common customer mistakes such as # 'chmod 0 public_html', that are valid, but can cause customers to # unintentionally shoot themselves in the foot. CustomerProof yes # Per-user concurrency limits. Will only work if the FTP server has # been compiled with --with-peruserlimits. # Format is: :# For example, 3:20 means that an authenticated user can have up to 3 active # sessions, and that up to 20 anonymous sessions are allowed. # PerUserLimits 3:20 # When a file is uploaded and there was already a previous version of the file # with the same name, the old file will neither get removed nor truncated. # The file will be stored under a temporary name and once the upload is # complete, it will be atomically renamed. For example, when a large PHP # script is being uploaded, the web server will keep serving the old version and # later switch to the new one as soon as the full file will have been # transferred. This option is incompatible with virtual quotas. # NoTruncate yes # This option accepts three values: # 0: disable SSL/TLS encryption layer (default). # 1: accept both cleartext and encrypted sessions. # 2: refuse connections that don't use the TLS security mechanism, # including anonymous sessions. # Do _not_ uncomment this blindly. Double check that: # 1) The server has been compiled with TLS support (--with-tls), # 2) A valid certificate is in place, # 3) Only compatible clients will log in. TLS 1 # Cipher suite for TLS sessions. # The default suite is secure and setting this property is usually # only required to *lower* the security to cope with legacy clients. # Prefix with -C: in order to require valid client certificates. # If -C: is used, make sure that clients' public keys are present on # the server. # TLSCipherSuite HIGH # Certificate file, for TLS CertFile /usr/local/pureftpd/etc/pure-ftpd.pem # Listen only to IPv4 addresses in standalone mode (ie. disable IPv6) # By default, both IPv4 and IPv6 are enabled. IPV4Only yes # Listen only to IPv6 addresses in standalone mode (i.e. disable IPv4) # By default, both IPv4 and IPv6 are enabled. # IPV6Only yes # UTF-8 support for file names (RFC 2640) # Set the charset of the server filesystem and optionally the default charset # for remote clients that don't use UTF-8. # Works only if pure-ftpd has been compiled with --with-rfc2640 # FileSystemCharset big5 # ClientCharset big5 AllowOverwrite on AllowStoreRestart on
七、生成用户
useradd -d /dev/null -s /sbin/nologin -M www
八、创建FTP目录
mkdir /www chown -R www:www /www
九、添加用户
/usr/local/pureftpd/bin/pure-pw useradd xiaoyu -u www -d /www –m
十、更新用户数据库(新增用户必须更新数据库才能生效,不需要重启FTP服务)
/usr/local/pureftpd/bin/pure-pw mkdb
十一、新增pure-config.pl脚本
vim /usr/local/pureftpd/sbin/pure-config.pl chmod +x /usr/local/pureftpd/sbin/pure-config.pl
#! /usr/bin/perl # (C) 2001-2013 Aristotle Pagaltzis # derived from code (C) 2001-2002 Frank Denis and Matthias Andree use strict; my ($conffile, @flg) = @ARGV; my $PUREFTPD; -x && ($PUREFTPD=$_, last) for qw( ${exec_prefix}/sbin/pure-ftpd /usr/local/pure-ftpd/sbin/pure-ftpd /usr/local/pureftpd/sbin/pure-ftpd /usr/local/sbin/pure-ftpd /usr/sbin/pure-ftpd ); my %simple_switch_for = ( IPV4Only => "-4", IPV6Only => "-6", ChrootEveryone => "-A", BrokenClientsCompatibility => "-b", Daemonize => "-B", VerboseLog => "-d", DisplayDotFiles => "-D", AnonymousOnly => "-e", NoAnonymous => "-E", DontResolve => "-H", AnonymousCanCreateDirs => "-M", NATmode => "-N", CallUploadScript => "-o", AntiWarez => "-s", AllowUserFXP => "-w", AllowAnonymousFXP => "-W", ProhibitDotFilesWrite => "-x", ProhibitDotFilesRead => "-X", AllowDotFiles => "-z", AutoRename => "-r", AnonymousCantUpload => "-i", LogPID => "-1", NoChmod => "-R", KeepAllFiles => "-K", CreateHomeDir => "-j", NoRename => "-G", CustomerProof => "-Z", NoTruncate => "-0", ); my %string_switch_for = ( FileSystemCharset => "-8", ClientCharset => "-9", SyslogFacility => "-f", FortunesFile => "-F", ForcePassiveIP => "-P", Bind => "-S", AnonymousBandwidth => "-t", UserBandwidth => "-T", TrustedIP => "-V", AltLog => "-O", PIDFile => "-g", TLSCipherSuite => "-J", CertFile => "-2", ); my %numeric_switch_for = ( MaxIdleTime => "-I", MaxDiskUsage => "-k", TrustedGID => "-a", MaxClientsNumber => "-c", MaxClientsPerIP => "-C", MaxLoad => "-m", MinUID => "-u", TLS => "-Y", ); my %numpairb_switch_for = ( LimitRecursion => "-L", PassivePortRange => "-p", AnonymousRatio => "-q", UserRatio => "-Q", ); my %numpairc_switch_for = ( Umask => "-U", Quota => "-n", PerUserLimits => "-y", ); my %auth_method_for = ( LDAPConfigFile => "ldap", MySQLConfigFile => "mysql", PGSQLConfigFile => "pgsql", PureDB => "puredb", ExtAuth => "extauth", ); my $simple_switch = qr/(@{[join "|", keys %simple_switch_for ]})\s+yes/i; my $string_switch = qr/(@{[join "|", keys %string_switch_for ]})\s+(\S+)/i; my $numeric_switch = qr/(@{[join "|", keys %numeric_switch_for ]})\s+(\d+)/i; my $numpairb_switch = qr/(@{[join "|", keys %numpairb_switch_for ]})\s+(\d+)\s+(\d+)/i; my $numpairc_switch = qr/(@{[join "|", keys %numpairc_switch_for ]})\s+(\d+):(\d+)/i; my $auth_method = qr/(@{[join "|", keys %auth_method_for ]})\s+(\S+)/i; die "Usage: pure-config.pl [extra options]\n" unless defined $conffile; open CONF, "< $conffile" or die "Can't open $conffile: $!\n"; !/^\s*(?:$|#)/ and (chomp, push @flg, /$simple_switch/i ? ($simple_switch_for{$1}) : /$string_switch/i ? ($string_switch_for{$1} . $2) : /$numeric_switch/i ? ($numeric_switch_for{$1} . $2) : /$numpairb_switch/i ? ($numpairb_switch_for{$1} . "$2:$3") : /$numpairc_switch/i ? ($numpairc_switch_for{$1} . "$2:$3") : /$auth_method/i ? ("-l" . "$auth_method_for{$1}:$2") : /UnixAuthentication\s+yes/i ? ("-l" . "unix") : /PAMAuthentication\s+yes/i ? ("-l" . "pam") : () ) while ; close CONF; if (-t STDOUT) { print "Running: $PUREFTPD ", join(" ", @flg), "\n"; } exec { $PUREFTPD } ($PUREFTPD, @flg) or die "cannot exec $PUREFTPD: $!";
十二、手动启动FTP
/usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
十三、创建服务脚本
vim /etc/init.d/pure-ftpd chmod +x /etc/init.d/pure-ftpd
#!/bin/bash # # chkconfig: 2345 85 15 # description: Pure-FTPd is an FTP server daemon based upon Troll-FTPd # processname: pure-ftpd ### BEGIN INIT INFO # Provides: pureftpd # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts pureftpd server # Description: starts pureftpd server ### END INIT INFO # Pure-FTPd Settings PURE_PERL="/usr/local/pureftpd/sbin/pure-config.pl" PURE_CONF="/usr/local/pureftpd/etc/pure-ftpd.conf" PURE_PID="/var/run/pure-ftpd.pid" RETVAL=0 prog="Pure-FTPd" start() { echo -n $"Starting $prog... " $PURE_PERL $PURE_CONF -B if [ "$?" = 0 ] ; then echo " done" else echo " failed" fi } stop() { echo -n $"Stopping $prog... " if [ ! -e $PURE_PID ]; then echo -n $"$prog is not running." exit 1 fi kill `cat $PURE_PID` if [ "$?" = 0 ] ; then echo " done" else echo " failed" fi } restart(){ echo $"Restarting $prog..." $0 stop sleep 2 $0 start } status(){ if [ -e $PURE_PID ]; then echo $"$prog is running." else echo $"$prog is not running." fi } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo $"Usage: $0 {start|stop|restart}" esac
十四、重载服务脚本(若不重载,服务脚本只有下次启动才可使用)
systemctl daemon-reload
十五、启动服务
service pure-ftpd start
十六、设置开机启动
update-rc.d pure-ftpd defaults