| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Logins and Authentication</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Logins and Authentication</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | Logging into <code>proftpd</code> and being successfully authenticated by |
| 15 | the server involves a lot of different modules and different checks. This |
| 16 | document aims to discuss the sort of checks and configuration involved, and |
| 17 | hopefully provide a better idea of how <code>proftpd</code> authenticates users. |
| 18 | |
| 19 | <p><b>PAM</b><br> |
| 20 | PAM, which stands for <b>P</b>luggable <b>A</b>uthentication <b>M</b>odules, |
| 21 | is an API intended to make it easy to replace the old Unix-style DES password |
| 22 | hashes stored in <code>/etc/passwd</code> with a flexible system that allows |
| 23 | system administrators to use MD5 checksums, SQL tables, LDAP servers, |
| 24 | RADIUS servers, <i>etc</i> in place of that password check. However, what |
| 25 | PAM does <b>not</b> provide is the rest of the user account information in |
| 26 | <code>/etc/passwd</code>, <i>i.e.</i> the user's UID and GID, home directory, |
| 27 | and shell. This means that PAM <b>cannot</b> be used as a drop-in replacement |
| 28 | for user information stored in <code>/etc/passwd</code>. <a href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Name-Service-Switch.html#Name%20Service%20Switch">NSS</a> (<b>N</b>ame <b>S</b>ervice <b>S</b>witch) modules, supported by |
| 29 | some operating systems, are a complementary API to PAM which can be used to |
| 30 | supply the rest of this user information. <code>proftpd</code> uses the normal |
| 31 | <code>libc</code> functions for looking up user information, and those |
| 32 | <code>libc</code> functions typically read <code>/etc/passwd</code>. NSS is |
| 33 | an abstraction layer within some <code>libc</code> implementations that causes |
| 34 | those functions to read other sources rather than <code>/etc/passwd</code>. |
| 35 | Regardless of NSS support, <code>proftpd</code> has support for |
| 36 | "<a href="#virtual">virtual</a>" users via its authentication |
| 37 | <a href="#modules">modules</a>. |
| 38 | |
| 39 | <p> |
| 40 | When configuring <code>proftpd</code>, the <code>configure</code> script |
| 41 | will automatically try to determine whether your operating system supports PAM. |
| 42 | If it does, the <code>mod_auth_pam</code> module will automatically be compiled |
| 43 | into your <code>proftpd</code>. If you explicitly do not want PAM support, |
| 44 | you can use the <code>--disable-auth-pam</code> configure option to disable |
| 45 | this automatic detection. The point of using PAM is that it can provide an |
| 46 | extra authentication step during a login. By "authentication", I |
| 47 | mean that PAM answers a yes/no question: "Is this user who they say they |
| 48 | are?". PAM modules are configured either in <code>/etc/pam.conf</code> or |
| 49 | <code>/etc/pam.d/</code>, depending on your operating system. However, |
| 50 | many of the PAM modules provided by vendors are not designed to work well |
| 51 | with some of the authentication <a href="#modules">modules</a> supported by |
| 52 | <code>proftpd</code>. If PAM is not a necessity for you, and you plan to |
| 53 | use one of the authentication modules (other than <code>mod_auth_unix</code>), |
| 54 | then you need do nothing. By default, proftpd uses PAM as an <i>additional</i> |
| 55 | check during logins, but if that check fails, the login may still succeed. |
| 56 | If you <i>do</i> need the PAM check to be authoritative, then you need to |
| 57 | use the <code>AuthOrder</code> directive, <i>e.g.</i>: |
| 58 | <pre> |
| 59 | AuthOrder mod_auth_pam.c* ... |
| 60 | </pre> |
| 61 | To disable use of PAM entirely, use: |
| 62 | <pre> |
| 63 | <IfModule mod_auth_pam.c> |
| 64 | AuthPAM off |
| 65 | </IfModule> |
| 66 | </pre> |
| 67 | |
| 68 | <p><a name="directives"><b>Configuration Directives</b><br> |
| 69 | There are several configuration directives that can cause login problems. |
| 70 | The most common one is <a href="../modules/mod_auth.html#RequireValidShell"><code>RequireValidShell</code></a>, so common that it is a |
| 71 | <a href="http://www.proftpd.org/docs/faq/faq_full.html#AEN267">FAQ</a>. |
| 72 | If <code>proftpd</code> does not actually <i>use</i> the shell configured for |
| 73 | a user, why does it check to see if the shell is valid by looking in |
| 74 | <code>/etc/shells</code>? Certain other FTP servers (<i>e.g.</i> |
| 75 | <code>wu-ftpd</code>, <code>pure-ftpd</code>) do check for invalid shells and |
| 76 | deny logins based on this criterion; <code>proftpd</code> follows this pattern |
| 77 | so as not to surprise too many system administrators. Use of invalid shells |
| 78 | is a common sysadmin trick for denying shell-based login access (<i>e.g.</i> |
| 79 | <code>ssh</code> logins); many sites use other means, however, and so use of |
| 80 | the <code>RequireValidShell</code> directive is also frequently seen. |
| 81 | |
| 82 | <p> |
| 83 | Another reason why a client cannot login might be if the login user is |
| 84 | <code>root</code> (or has a UID of zero, and hence has root privileges). |
| 85 | Logging in as <code>root</code> is dangerous, and should be avoided if |
| 86 | possible. If you do find it absolutely necessary to login as <code>root</code>, |
| 87 | <i>please</i> use <a href="TLS.html">SSL/TLS</a>, or at least <a href="SSH.html">tunnel</a> your FTP connection using SSH. The <a href="../modules/mod_auth.html#RootLogin"><code>RootLogin</code></a> configuration directive is needed |
| 88 | in your <code>proftpd.conf</code> in order for <code>proftpd</code> to |
| 89 | explicitly allow root logins. |
| 90 | |
| 91 | <p> |
| 92 | One uncommon obstacle that you might encounter to allowing a user to login is |
| 93 | the possibility that that user is listed in an <code>/etc/ftpusers</code> |
| 94 | file. This is another legacy check, courtesy of <code>wu-ftpd</code>. |
| 95 | Any user that is listed in <code>/etc/ftpusers</code> is <b>not</b> allowed |
| 96 | to login via FTP. A little backwards from what might be expected from the |
| 97 | file name, I agree. <code>proftpd</code> was made to similarly honor any <code>/etc/ftpusers</code> file by default in order to ease the pain for sites |
| 98 | migrating from <code>wu-ftpd</code> to <code>proftpd</code>. Disabling |
| 99 | <code>proftpd</code>'s check for this file is as simple as using the |
| 100 | <a href="../modules/mod_auth.html#UseFtpUsers"><code>UseFtpUsers</code></a> |
| 101 | configuration directive, like so: |
| 102 | <pre> |
| 103 | UseFtpUsers off |
| 104 | </pre> |
| 105 | in your <code>proftpd.conf</code> file. |
| 106 | |
| 107 | <p> |
| 108 | The <a href="../modules/mod_auth_unix.html#PersistentPasswd"><code>PersistentPasswd</code></a> configuration directive can |
| 109 | be necessary in some environments, particularly those that use NIS/YP, |
| 110 | NSS modules, or (in the case of Mac OSX) the <code>netinfo</code> service. |
| 111 | In order to be able to lookup and map UIDs and GIDs to names, as when |
| 112 | listing directories and files, <code>proftpd</code> tries to keep the |
| 113 | <code>/etc/passwd</code> file open. This is particularly relevant if the |
| 114 | <code>DefaultRoot</code> directive is in effect, for once <code>chroot</code>ed, |
| 115 | <code>proftpd</code> cannot open <code>/etc/passwd</code>. However, services |
| 116 | such as NIS, NSS, and <code>netinfo</code> function very differently while |
| 117 | providing a file-like interface, and they do not function properly if |
| 118 | <code>proftpd</code> keeps them open. Using: |
| 119 | <pre> |
| 120 | PersistentPasswd off |
| 121 | </pre> |
| 122 | in your <code>proftpd.conf</code> should cause name lookups to work |
| 123 | properly if you use NIS, NSS, or <code>netinfo</code>. |
| 124 | |
| 125 | <p> |
| 126 | If you feel your logins are slow, then you might be encountering another |
| 127 | <a href="http://www.proftpd.org/docs/faq/faq_full.html#AEN519">FAQ</a>. |
| 128 | The timeouts when performing RFC931 <code>ident</code> lookups, and |
| 129 | DNS reverse resolutions, add a noticeable delay to a login. |
| 130 | |
| 131 | <p><a name="anonymous"><b>Anonymous Logins</b><br> |
| 132 | Anonymous logins are allowed by defining an <a href="http://www.proftpd.org/docs/modules/mod_core.html#Anonymous"><code><Anonymous></code></a> |
| 133 | section, or <i>context</i>, in your <code>proftpd.conf</code>. No |
| 134 | <code><Anonymous></code> contexts mean that <code>proftpd</code> will |
| 135 | not allow anonymous logins. As the documentation describes, |
| 136 | <code>proftpd</code> knows to treat a given login name (given to the server by |
| 137 | the client via the <code>USER</code> FTP command) by seeing if the login |
| 138 | name is the same as the <code>User</code> name in an |
| 139 | <code><Anonymous></code> context. For example: |
| 140 | <pre> |
| 141 | <Anonymous /var/ftp/anon/dave> |
| 142 | User dave |
| 143 | Group ftpanon |
| 144 | ... |
| 145 | </Anonymous> |
| 146 | </pre> |
| 147 | would cause any client logging in as <code>dave</code> to be treated as an |
| 148 | anonymous login, and to be handled using the <code><Anonymous></code> |
| 149 | context above. This structure allows for multiple login names to be treated |
| 150 | as anonymous logins, and for each anonymous login to have its own specific |
| 151 | anonymous configuration. Some administrators use <code><Anonymous></code> |
| 152 | contexts to define "virtual" users directly in their |
| 153 | <code>proftpd.conf</code>, but this practice is <b>discouraged</b>. Virtual |
| 154 | user accounts are discussed next. |
| 155 | |
| 156 | <p><a name="homedir"><b>Resolving <code>~</code></b><br> |
| 157 | The <code>DefaultRoot</code> directive is commonly used to restrict or |
| 158 | "<a href="Chroot.html">jail</a>" users into specific directories, |
| 159 | usually their individual home directories. This is done via: |
| 160 | <pre> |
| 161 | DefaultRoot ~ |
| 162 | </pre> |
| 163 | where the tilde (<code>~</code>) is expanded to the home directory of the |
| 164 | logging in user. Now, when <code>proftpd</code> is resolving the tilde, |
| 165 | it switches to the privileges of the logging-in user and attempts to resolve |
| 166 | the home directory. This ensures that the user will, once restricted to |
| 167 | that directory, will have the ability to see files and move around. So |
| 168 | if using the tilde does not appear to be working in your configuration, |
| 169 | double-check that the permissions on the home directory of the user in |
| 170 | question at least allow that user to change into the directory (which requires |
| 171 | execute permission on the home directory). If <code>proftpd</code> finds |
| 172 | that the permissions are too restrictive, an error message like: |
| 173 | <pre> |
| 174 | chroot("~"): No such file or directory |
| 175 | </pre> |
| 176 | will be logged. |
| 177 | |
| 178 | <p><a name="virtual"><b>Virtual Users</b><br> |
| 179 | One question that often arises is "How do I create a proftpd user?" |
| 180 | <code>proftpd</code> uses your system's <code>/etc/passwd</code> file by |
| 181 | default, and so <code>proftpd</code> users are the same as your system users. |
| 182 | "Virtual" users, sometimes described as FTP-only user accounts, are |
| 183 | users that can login to <code>proftpd</code>, but who are separate from the |
| 184 | normal system users, and who do not have entries in <code>/etc/passwd</code>. |
| 185 | <code>proftpd</code> does not care how or where user information is defined. |
| 186 | The daemon is designed with an abstraction layer on top of user information |
| 187 | sources, and that abstraction is responsible for supplying that data that is |
| 188 | <b>required</b> for every user: a name, a UID, a GID, a home directory, and a |
| 189 | shell. A user's shell will not be used except in |
| 190 | <code>RequireValidShell</code> checks, but it must still present. The code |
| 191 | that is responsible for supplying this data, reading it from whatever storage |
| 192 | format is supported, lies in <code>proftpd</code>'s various configurable |
| 193 | authentication modules. |
| 194 | |
| 195 | <p><a name="modules"><b>Authentication Modules</b><br> |
| 196 | <code>proftpd</code> uses authentication modules for accessing user account |
| 197 | information. These modules implement an API that that daemon uses to |
| 198 | lookup account information by name or by ID, to authenticate a user using |
| 199 | the provided password, and to resolve names to IDs or IDs to names. The |
| 200 | following authentication modules are all provided with <code>proftpd</code>: |
| 201 | <ul> |
| 202 | <li><code>mod_auth_unix</code><br> |
| 203 | Handles normal authentication via <code>/etc/passwd</code>, <code>/etc/group</code> |
| 204 | </li> |
| 205 | |
| 206 | <p> |
| 207 | <li><a href="../modules/mod_auth_file.html"><code>mod_auth_file</code></a><br> |
| 208 | Handles the <code>AuthUserFile</code> and <code>AuthGroupFile</code> directives, for storing user account information in <a href="AuthFiles.html">other files</a> |
| 209 | </li> |
| 210 | |
| 211 | <p> |
| 212 | <li><a href="../contrib/mod_ldap.html"><code>mod_ldap</code></a><br> |
| 213 | Handles user account information stored in LDAP directories |
| 214 | </li> |
| 215 | |
| 216 | <p> |
| 217 | <li><a href="../contrib/mod_radius.html"><code>mod_radius</code></a><br> |
| 218 | Handles user account information provided by RADIUS servers |
| 219 | </li> |
| 220 | |
| 221 | <p> |
| 222 | <li><a href="../contrib/mod_sql.html"><code>mod_sql</code></a><br> |
| 223 | Handles user account information stored in <a href="SQL.html">SQL tables</a> |
| 224 | </li> |
| 225 | </ul> |
| 226 | Note that <code>mod_auth_pam</code> is not on this list because it cannot |
| 227 | provide the necessary user account information. It can be used to supplement |
| 228 | other auth modules by adding its PAM checks, however. |
| 229 | |
| 230 | <p><a name="order"> |
| 231 | Since <code>proftpd</code> supports multiple authentication modules at the |
| 232 | same time, how does it know which authentication module to use? What if you |
| 233 | want to tell <code>proftpd</code> which modules to check, and in which order? |
| 234 | What if you want some authentication modules to be used in one |
| 235 | <code><VirtualHost></code>, and different authentication modules in |
| 236 | another? |
| 237 | |
| 238 | <p> |
| 239 | By default, <code>proftpd</code> will ask every configured authentication |
| 240 | module about a given user, until it finds an authentication module that knows |
| 241 | about that user, or until an authentication module signals an unrecoverable |
| 242 | error. The order in which these modules are asked depends on the order of |
| 243 | modules in the <code>--with-modules</code> option used when configuring |
| 244 | <code>proftpd</code>. |
| 245 | |
| 246 | <p> |
| 247 | Some modules can be figured to not "play nice" and allow other |
| 248 | authentication modules a chance at providing user information. That is, some |
| 249 | modules can be "authoritative", and if that module does not know |
| 250 | about the user, it will signal an error and prevent <code>proftpd</code> |
| 251 | from asking other modules. <code>mod_auth_pam</code>'s |
| 252 | <code>AuthPAMAuthoritative</code> directive, and the <code>*</code> syntax |
| 253 | in the <code>SQLAuthenticate</code> directive of <code>mod_sql</code>, are |
| 254 | examples of this authoritativeness. In general, it is best to avoid using |
| 255 | such mechanisms, and to use the |
| 256 | <a href="../modules/mod_core.html#AuthOrder"><code>AuthOrder</code></a> configuration directive instead. |
| 257 | |
| 258 | <p> |
| 259 | The following illustrates a situation where <code>AuthOrder</code> is |
| 260 | useful. The default build of <code>proftpd</code> has two authentication |
| 261 | modules included: <code>mod_auth_file</code> and <code>mod_auth_unix</code>. |
| 262 | <code>proftpd</code> will consult <b>both</b> modules when authenticating a |
| 263 | user: first <code>mod_auth_file</code>, then <code>mod_auth_unix</code>. |
| 264 | (<i>Note</i>: versions of <code>proftpd</code> before 1.2.8rc1 would only |
| 265 | support either <code>AuthUserFile</code> or <code>/etc/passwd</code>, but not |
| 266 | both at the same time.) If any authentication module can authenticate a user, |
| 267 | then authentication succeeds. This holds true of other authentication modules |
| 268 | like <code>mod_ldap</code>, <code>mod_sql</code>, <code>mod_radius</code>, |
| 269 | <i>etc</i>. |
| 270 | |
| 271 | <p> |
| 272 | However, if you only want <code>proftpd</code> to use your |
| 273 | <code>AuthUserFile</code> and no other authentication modules, then you would |
| 274 | use the <code>AuthOrder</code> directive like this: |
| 275 | <pre> |
| 276 | AuthOrder mod_auth_file.c |
| 277 | </pre> |
| 278 | Or, if you use <code>mod_sql</code> and wanted <code>proftpd</code> to check |
| 279 | your SQL tables first, and then default to system users: |
| 280 | <pre> |
| 281 | AuthOrder mod_sql.c mod_auth_unix.c |
| 282 | </pre> |
| 283 | Note that the <code>mod_auth.c</code> module should <b>never</b> be used in an |
| 284 | <code>AuthOrder</code> directive. |
| 285 | |
| 286 | <p><a name="FAQ"></a> |
| 287 | <b>Frequently Asked Questions</b><br> |
| 288 | |
| 289 | <p><a name="LogPassword"> |
| 290 | <font color=red>Question</font>: How can I configure <code>proftpd</code> to |
| 291 | log/show the password typed by the user?<br> |
| 292 | <font color=blue>Answer</font>: You cannot. Period. The <code>proftpd</code> |
| 293 | code goes out of its way to ensure that the password is never logged. |
| 294 | |
| 295 | <p> |
| 296 | <hr> |
| 297 | <font size=2><b><i> |
| 298 | © Copyright 2017 The ProFTPD Project<br> |
| 299 | All Rights Reserved<br> |
| 300 | </i></b></font> |
| 301 | <hr> |
| 302 | |
| 303 | </body> |
| 304 | </html> |