| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Best Common Practices</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b><i>Best Common Practices</i></b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | This document describes the best practices, common and recommended, when |
| 15 | configuring and using <code>proftpd</code> servers. The first few |
| 16 | recommendations are covered in detail elsewhere: <a href="ConfigFile.html#Identity">role accounts</a>, <a href="Chroot.html">chroots</a>, and <a href="Logging.html">logging directories</a>. |
| 17 | |
| 18 | <p><a name="VirtualHosts"></a> |
| 19 | <b><code><VirtualHost></code>s</b><br> |
| 20 | When configuration a <code><VirtualHost></code>, it is best to use |
| 21 | an IP address, and not a DNS name. Not only does this reduce network traffic |
| 22 | a little when the daemon starts up (as it will not need to resolve the DNS |
| 23 | name to its IP address), but it will also reduce confusion. Unlike HTTP, |
| 24 | FTP does not support name-based virtual hosts; all contact to virtual hosts is |
| 25 | done based on IP addresses (and ports). If a DNS name is used in a |
| 26 | <code><VirtualHost></code> configuration, there is the possibility that |
| 27 | that DNS name will resolve to an IP address of another virtual host in the |
| 28 | configuration. |
| 29 | |
| 30 | <p><a name="ResourceLimits"></a> |
| 31 | <b>Resource Limits</b><br> |
| 32 | One of the most common requests on the mailing list is to be able to limit |
| 33 | the number of connections, in various ways, a given user may make to the |
| 34 | <code>proftpd</code> daemon. There are different configuration directives for |
| 35 | doing so, depending on the situation: |
| 36 | <ul> |
| 37 | <li><code>MaxInstances</code>: Limits the overall number of connections<br> |
| 38 | <br> |
| 39 | |
| 40 | <li><code>MaxClients</code>: Limits the number of connections on a per-server/vhost basis<br> |
| 41 | <br> |
| 42 | |
| 43 | <li><code>MaxClientsPerHost</code>: Limits the number of clients that may be connecting from the same host<br> |
| 44 | <br> |
| 45 | |
| 46 | <li><code>MaxClientsPerUser</code>: Limits the number of clients that may be logged in at one time using the same username<br> |
| 47 | <br> |
| 48 | |
| 49 | <li><code>MaxHostsPerUser</code>: Limits the number of hosts from which clients may be logged in at one time using the same username<br> |
| 50 | </ul> |
| 51 | |
| 52 | <p> |
| 53 | If you are using a <code>ServerType</code> of <code>inetd</code>, then you |
| 54 | should be aware of the default concurrency limits in <code>inetd</code> (see |
| 55 | <a href="http://bugs.proftpd.org/show_bug.cgi?id=1243">Bug#1243</a>). For |
| 56 | <code>xinetd</code>, the <code>per_source</code> and <code>cps</code> |
| 57 | attributes can be used to configure concurrency limits. For a |
| 58 | <code>ServerType</code> of <code>standalone</code>, the |
| 59 | <code>MaxConnectionRate</code> configuration directive can be used to provide |
| 60 | connection limitations. |
| 61 | |
| 62 | <p> |
| 63 | Intensive use of CPU and/or memory by FTP sessions can be restricted by use |
| 64 | of <code>RLimitCPU</code> and <code>RLimitMemory</code>. Here's an example: |
| 65 | <pre> |
| 66 | RLimitCPU session 10 |
| 67 | RLimitMemory session 4096 |
| 68 | </pre> |
| 69 | This applies CPU and memory resource limits to session processes. In order |
| 70 | to limit the use of such resources by the daemon, should this be a concern, |
| 71 | the directives can be used similarly: |
| 72 | <pre> |
| 73 | RLimitMemory daemon 8192 max |
| 74 | </pre> |
| 75 | In general, one should not set an <code>RLimitCPU</code> limit on the daemon, |
| 76 | as a long-lived daemon (as all should be) will eventually encounter such a |
| 77 | limit. <b>Note</b>: appropriate settings to use will vary from site to site - |
| 78 | <i>do not blindly copy these examples</i>. |
| 79 | |
| 80 | <p> |
| 81 | One concern associated with unrestricted use of resources is globbing; the |
| 82 | topic has been mentioned, in relation to FTP servers, in security forums in |
| 83 | the past. This <a href="Globbing.html">mini-HOWTO</a> discusses, in-depth, |
| 84 | the defenses against globbing attacks that ProFTPD provides. |
| 85 | |
| 86 | <p> |
| 87 | Some sites like to be able to restrict the size of files transferred, |
| 88 | particularly uploaded files, as disk space is also a precious resource. For |
| 89 | this purpose, the <code>MaxRetrieveFileSize</code> and |
| 90 | <code>MaxStoreFileSize</code> configuration directives are provided. |
| 91 | |
| 92 | <p> |
| 93 | There are also several third-party modules that can add various resource |
| 94 | limiting abilities to a <code>proftpd</code> server: |
| 95 | <ul> |
| 96 | <li><a href="http://www.castaglia.org/proftpd/modules/mod_diskuse.html">mod_diskuse</a> |
| 97 | <li><a href="../contrib/mod_load.html">mod_load</a> |
| 98 | <li><a href="../contrib/mod_quotatab.html">mod_quotatab</a> |
| 99 | </ul> |
| 100 | |
| 101 | <p><a name="AccessControls"></a> |
| 102 | <b>Access Controls</b><br> |
| 103 | ProFTPD provides a <a href="Limit.html"><code><Limit></code></a> |
| 104 | directive for configuring fine-grained access controls that can be applied to |
| 105 | logins as well as FTP commands. The contributed |
| 106 | <a href="../contrib/mod_wrap.html"><code>mod_wrap</code></a> module |
| 107 | allows a <code>proftpd</code> daemon to use the standard |
| 108 | <code>/etc/hosts.allow</code> and <code>/etc/hosts.deny</code> access control |
| 109 | files. Of interest to some is the next generation of this module, |
| 110 | <a href="../contrib/mod_wrap2.html"><code>mod_wrap2</code></a>, which allows |
| 111 | for storing access control rules in SQL tables. |
| 112 | |
| 113 | <p> |
| 114 | On systems which support the /proc filesystem, such as Linux and several others, |
| 115 | it is <b>highly recommended</b> that the /proc filesystem be guarded, especially |
| 116 | for non-chroot sessions. Malicious clients can read or write to that filesystem |
| 117 | and cause quite a bit of damage. Thus we encourge administrators to use |
| 118 | the following in their <code>proftpd.conf</code>: |
| 119 | <pre> |
| 120 | <Directory /proc> |
| 121 | <Limit ALL> |
| 122 | DenyAll |
| 123 | </Limit> |
| 124 | </Directory> |
| 125 | </pre> |
| 126 | |
| 127 | <p><a name="PerformanceTuning"></a> |
| 128 | <b>Performance Tuning</b><br> |
| 129 | When configuring a <code>proftpd</code> for performance, here are some |
| 130 | settings to try. First, make sure that you have <code>ident</code> and |
| 131 | reverse DNS lookups disabled: |
| 132 | <pre> |
| 133 | IdentLookups off |
| 134 | UseReverseDNS off |
| 135 | </pre> |
| 136 | By default, both are done for each new FTP session, and, depending on the |
| 137 | response time from both <code>identd</code> and DNS servers, this can add |
| 138 | a noticeable delay during the login process. |
| 139 | |
| 140 | <p> |
| 141 | Another possible source of delays during the login process is a very large |
| 142 | <code>/etc/passwd</code> file (a large <code>/etc/group</code> file will |
| 143 | have the same effect). The standard library functions used for doing |
| 144 | user lookups scan these files line-by-line, which means that the scan time |
| 145 | increases with the number of entries. If this is the case at your site, you |
| 146 | might consider using a different storage format for your user account |
| 147 | information. The <code>mod_sql</code> and <code>mod_ldap</code> modules |
| 148 | provided with ProFTPD can be used for storing such information in SQL tables |
| 149 | or LDAP servers. |
| 150 | |
| 151 | <p> |
| 152 | In some cases, it's also possible that PAM checks may introduce delays. If |
| 153 | you suspect this to be happening, try adding the following to your |
| 154 | <code>proftpd.conf</code>: |
| 155 | <pre> |
| 156 | <IfModule mod_auth_pam.c> |
| 157 | AuthPAM off |
| 158 | </IfModule> |
| 159 | </pre> |
| 160 | |
| 161 | <p> |
| 162 | The listing of directories during an FTP session can impose quite a bit |
| 163 | of disk I/O on a server machine. This is most often seen when site-mirroring |
| 164 | scripts do recursive directory listings, and for deeply nested directory |
| 165 | structures. To deal with the former, the following can be used: |
| 166 | <pre> |
| 167 | ListOptions +R strict |
| 168 | </pre> |
| 169 | This setting blocks the use of the <code>-R</code> option, which is how clients |
| 170 | request recurse directory listings. The <em>strict</em> keyword prevents |
| 171 | client options from overriding the <code>proftpd.conf</code> setting. Also, |
| 172 | new in <code>1.2.9rc1</code> are some <code>ListOptions</code> options |
| 173 | that allow recursive directory listings, but can be used to set limits on |
| 174 | the recursion: |
| 175 | <pre> |
| 176 | ListOptions "" maxdepth 3 |
| 177 | ListOptions "" maxdirs 10 |
| 178 | ListOptions "" maxfiles 1000 |
| 179 | </pre> |
| 180 | The first line above limits the directory depth of recursion; the second |
| 181 | line does not limit the recursion depth, rather it limits the maximum number |
| 182 | of directories that may be listed at one time; the third limit limits the |
| 183 | maximum number of files that may be listed at one time. |
| 184 | |
| 185 | <p> |
| 186 | Another way to speed up directory listings to disable proftpd's checking |
| 187 | for <code>.ftpaccess</code> files in every directory encountered. To do |
| 188 | this, use: |
| 189 | <pre> |
| 190 | AllowOverride off |
| 191 | </pre> |
| 192 | This disable's <code>proftpd</code>'s honouring of <code>.ftpaccess</code> |
| 193 | files. How does this reduce disk I/O? In order to properly process |
| 194 | <code>.ftpaccess</code> files, the daemon has to check for such a file in |
| 195 | each and every directory when performing an operation in that directory, |
| 196 | <i>each time an operation is requested</i> (it's possible for a |
| 197 | <code>.ftpaccess</code> file to be added or updated after the daemon has |
| 198 | already checked the directory). This constant checking is noticeable on |
| 199 | heavily loaded servers. By disabling use of these files, the daemon no |
| 200 | longer has to check each directory each time. |
| 201 | |
| 202 | <p> |
| 203 | The type of logging also has an impact, performance-wise. By default, |
| 204 | a <code>proftpd</code> daemon logs using <code>syslog</code>; |
| 205 | <code>syslogd</code>, however, is known to not scale well at all, and can |
| 206 | break under heavy load. Directing logging to a file in such cases, |
| 207 | using the <code>ServerLog</code> and/or <code>SystemLog</code> directives |
| 208 | can reduce this bottleneck. Also, depending on the type of authentication |
| 209 | done, disabling <code>utmp/wtmp</code> logging can reduce overhead: |
| 210 | <pre> |
| 211 | WtmpLog off |
| 212 | </pre> |
| 213 | for <code><VirtualHost></code>s that only allow anonymous logins, or |
| 214 | that authenticate non-<code>/etc/passwd</code> accounts, helps to reduce |
| 215 | the amount of unnecessary "clutter" in the <code>utmp/wtmp</code> |
| 216 | log files. |
| 217 | |
| 218 | <p> |
| 219 | If your <code>proftpd</code> server is on a high-bandwidth Internet link, |
| 220 | it may benefit from tuning the size of <b>kernel</b>-level (as opposed |
| 221 | to <b>application</b>-level) socket buffers used when transferring data. |
| 222 | The |
| 223 | <a href="../modules/mod_core.html#SocketOptions"><code>SocketOptions</code></a> configuration directive can be used to specify larger buffer sizes: |
| 224 | <pre> |
| 225 | # The 'sndbuf' parameter tunes the size of the buffer used for sending |
| 226 | # files to clients; the 'rcvbuf' tunes the buffer used for receiving |
| 227 | # files uploaded by clients. |
| 228 | # |
| 229 | # This configures 16K buffers for both, which assumes a very |
| 230 | # well-connected site. |
| 231 | SocketOptions sndbuf 16384 rcvbuf 16384 |
| 232 | </pre> |
| 233 | Again, these are example numbers, and should <b>not be blindly copied</b>. |
| 234 | |
| 235 | <p> |
| 236 | Finally, there are some <code>configure</code> options that can be used |
| 237 | to tune your <code>proftpd</code> daemon. All of the |
| 238 | <code>--enable-</code> options are available; of particular interest |
| 239 | are <code>--enable-buffer-size</code> and |
| 240 | <code>--enable-sendfile</code>. Use of the <code>sendfile(2)</code> function |
| 241 | (via the latter <code>configure</code> option) may or may not increase |
| 242 | download speeds, but it will reduce disk I/O: <code>sendfile(2)</code> |
| 243 | implements zero-copy transfers, meaning that the kernel will read data |
| 244 | directly from the file into the socket, all in kernel space; normal |
| 245 | <code>read()</code> transfers spend time copying buffers from kernel space |
| 246 | to application space (reading the file), and then back to kernel space |
| 247 | (writing to the socket). By increasing the buffer size using the |
| 248 | <code>--enable-buffer-size</code> option, proftpd reads and writes |
| 249 | data in larger chunks, and makes fewer expensive system calls. Use of |
| 250 | this option to set buffer sizes of 8K or more has been reported to drastically |
| 251 | increase transfer speeds (depending on network configurations). |
| 252 | |
| 253 | <p><a name="ConfigDelegation"></a> |
| 254 | <b>Configuration Delegation</b><br> |
| 255 | A configuration is considered "delegated" when the |
| 256 | <code>Include</code> configuration directive is used in |
| 257 | <code>proftpd.conf</code> to specify a portion of the server configuration |
| 258 | that may not be under the daemon administrator's control. This situation |
| 259 | often arises for sites that have multiple virtual servers; the administrator |
| 260 | for a given virtual server may be allowed to configure their particular |
| 261 | server via an <code>Include</code>d file. <b>If possible, avoid this</b>. |
| 262 | |
| 263 | <p> |
| 264 | Here's why: by delegating a configuration, you are trusting someone else with |
| 265 | a great deal of possible control over the daemon. A given |
| 266 | <code><VirtualHost></code> section can have an <code>AuthUserFile</code>. |
| 267 | In that <code>AuthUserFile</code>, the virtual server administrator could |
| 268 | define a user who has a UID of 0, thus basically giving herself root access. |
| 269 | Most sites probably would not like this. The trouble here is the lack of |
| 270 | control over the contents of <code>AuthUserFile</code>s (and |
| 271 | <code>AuthGroupFile</code>s). There are a couple of ways of handling this |
| 272 | situation. First, the daemon administrator can make sure that any |
| 273 | <code>Include</code> directives occur as early as possible in the |
| 274 | <code>proftpd.conf</code> file. Most configuration directives in the |
| 275 | <code>Include</code>d file can be overridden by setting the directive again, |
| 276 | after the <code>Include</code>, in the main <code>proftpd.conf</code>. |
| 277 | |
| 278 | <p> |
| 279 | The <a href="../modules/mod_auth_file.html"><code>mod_auth_file</code></a> |
| 280 | module, now part of the core distribution, was developed specifically to |
| 281 | provide finer control over the contents of <code>AuthUserFile</code> and |
| 282 | <code>AuthGroupFile</code> files. It does so by enhancing these configuration |
| 283 | directives to support optional "filters" that restrict the UIDs, GIDs, |
| 284 | user names, and/or home directories in such files. |
| 285 | |
| 286 | <p><a name="Miscellaneous"></a> |
| 287 | <b>Miscellaneous</b><br> |
| 288 | For the security-wary administrator, there are a few more directives that |
| 289 | may be of interest: <a href="../modules/mod_auth.html#AnonRejectPasswords"><code>AnonRejectPasswords</code></a>, |
| 290 | which configures a regular expression that matches and blocks scripted FTP |
| 291 | clients that try to find and exploit ill-configured anonymous FTP sites, and |
| 292 | <a href="../modules/mod_auth.html#RootRevoke"><code>RootRevoke</code></a>, |
| 293 | which causes <code>proftpd</code> to drop root privileges completely (read the |
| 294 | description for details). |
| 295 | |
| 296 | <p> |
| 297 | <hr> |
| 298 | <font size=2><b><i> |
| 299 | © Copyright 2017 The ProFTPD Project<br> |
| 300 | All Rights Reserved<br> |
| 301 | </i></b></font> |
| 302 | <hr> |
| 303 | |
| 304 | </body> |
| 305 | </html> |