| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Virtual Users</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Virtual Users</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | The core <code>proftpd</code> daemon access all user information via |
| 15 | an Auth API. This API hides all of the details of where user information |
| 16 | is stored, how to retrieve it, <i>etc</i> from the core engine and modules. |
| 17 | This abstraction allows for multiple simultaneous different authentication |
| 18 | layers or mechanisms to be configured. It is also because of this |
| 19 | abstraction that <code>proftpd</code> does not "know" the difference |
| 20 | between a system user and a virtual user; all users are the same. |
| 21 | |
| 22 | <p> |
| 23 | <b>Frequently Asked Questions</b> |
| 24 | |
| 25 | <p><a name="Definition"></a> |
| 26 | <font color=red>Question</font>: What makes a user "virtual", then?<br> |
| 27 | <font color=blue>Answer</font>: A virtual user is, quite simply, a user that |
| 28 | is <i>not</i> defined in the system <code>/etc/passwd</code> file. This file |
| 29 | associates a user name, given by the system administrator, to a user ID |
| 30 | (commonly shortened to UID) and a group ID (GID), among other details. The |
| 31 | Unix kernel does <b>not</b> deal with users in terms of their user names; it |
| 32 | only "knows" about UIDs and GIDs. This means that an application |
| 33 | like <code>proftpd</code> can look up the IDs to use for a given user name |
| 34 | however it sees fit. Using <code>/etc/passwd</code> is not strictly required. |
| 35 | |
| 36 | <p> |
| 37 | Defining users outside of <code>/etc/passwd</code> means that system utilities |
| 38 | like <code>ls</code> and <code>chown</code> do not work as expected. When |
| 39 | first setting up virtual users, most system administrators will experience |
| 40 | this as permissions problems. Virtual users will not be able to login, or |
| 41 | they can login but not upload or download files. Or when the administrator |
| 42 | lists the files uploaded by virtual users, those files will have the wrong |
| 43 | owner names. |
| 44 | |
| 45 | <p> |
| 46 | The permissions problems are almost always caused by ID mismatch. That is, |
| 47 | the UID and/or GID of the virtual user will not match the UID and/or GID |
| 48 | owner of their home directory (or whichever directory is having problems). |
| 49 | The key here is to change the ownership of the virtual user's directories |
| 50 | using <code>chown</code> <i>and IDs</i>, rather than names. The |
| 51 | <code>chown</code> utility can set ownership by ID just as easily as by |
| 52 | name. Most <code>chown</code> examples show setting ownership by name, |
| 53 | but that means <code>chown</code> would look up the IDs for that name via |
| 54 | <code>/etc/passwd</code>, which, as noted above, will not work for virtual |
| 55 | users. |
| 56 | |
| 57 | <p> |
| 58 | By default, <code>ls</code> lists the names of file owners by looking up those |
| 59 | names in <code>/etc/passwd</code>. This is why listing files of virtual |
| 60 | users will often show incorrect names; <code>ls</code> has no knowledge |
| 61 | of virtual user names. When working with files created by virtual users, use |
| 62 | <code>ls -n</code> so that you can see the IDs, not the names, associated with |
| 63 | those files. You will then need to manually make sure those IDs are the |
| 64 | correct ones for the file. |
| 65 | |
| 66 | <p> |
| 67 | Remember that it is the Unix kernel, and <b>not ProFTPD</b>, which enforces |
| 68 | the normal Unix access rules to files for a process such as a ProFTPD session |
| 69 | process. All that ProFTPD does is select the user and group IDs to set |
| 70 | for the process, based on the authentication. ProFTPD <b>never overrides</b> |
| 71 | the normal Unix filesystem permissions. |
| 72 | |
| 73 | <p><a name="IDs"></a> |
| 74 | <font color=red>Question</font>: Which IDs should I use for my virtual users?<br> |
| 75 | <font color=blue>Answer</font>: It does not matter. The only UID and GID |
| 76 | which are special are UID 0 (zero) and GID 0 (zero). These IDs are used |
| 77 | for user <code>root</code> and group <code>root</code>; do <b>not</b> assign |
| 78 | these IDs to your virtual users unless you absolutely trust those users. |
| 79 | |
| 80 | <p> |
| 81 | Other than that, you are free to use any IDs you like. It is generally |
| 82 | a good idea to use IDs for your virtual users that are not already in use |
| 83 | in <code>/etc/passwd</code>, in order to keep the privileges of your |
| 84 | system users separate from the privileges of your virtual users; privileges |
| 85 | are determined by IDs. However, in some cases (such as using ProFTPD |
| 86 | for FTP access to websites), you may want all of your virtual users to |
| 87 | run as the web server user, <i>e.g.</i> user "www" or user |
| 88 | "apache". Use the IDs that make the most sense for your site |
| 89 | needs. |
| 90 | |
| 91 | <p> |
| 92 | One related question often asked is "Can I have my virtual users have |
| 93 | the same IDs?" Yes, you can. This means that all of those virtual |
| 94 | users would have the exact same privileges. If you use this approach, |
| 95 | make sure those virtual users are all confined to separate home (or web site) |
| 96 | directories by using: |
| 97 | <pre> |
| 98 | DefaultRoot ~ |
| 99 | </pre> |
| 100 | in your <code>proftpd.conf</code>. This means that even though those |
| 101 | virtual users would all have the same privileges, they would be unable to see |
| 102 | and affect each others' files since they would all be separated in different |
| 103 | directories. |
| 104 | |
| 105 | <p><a name="Location"></a> |
| 106 | <font color=red>Question</font>: If virtual users are not defined in the system <code>/etc/passwd</code> file, then where <i>are</i> they defined?<br> |
| 107 | <font color=blue>Answer</font>: There are several other locations where |
| 108 | user information can be stored, <i>e.g.</i> <code>AuthUserFiles</code>, |
| 109 | LDAP directories, SQL databases, and RADIUS servers. Note that virtual |
| 110 | users are <b>not</b> defined in the <code>proftpd.conf</code> file directly. |
| 111 | |
| 112 | <p> |
| 113 | One of the simplest virtual user authentication mechanisms is the |
| 114 | <code>AuthUserFile</code>, which is a flat text file in the same format as |
| 115 | the system <code>/etc/passwd</code> file. For more information on the |
| 116 | details, see the <a href="AuthFiles.html">AuthFiles</a> howto. |
| 117 | The <code>AuthUserFile</code> configuration directive is handled by the |
| 118 | <code>mod_auth_file</code> module, whose documentation can be found |
| 119 | <a href="../modules/mod_auth_file.html">here</a>. |
| 120 | |
| 121 | <p> |
| 122 | Once you have created your <code>AuthUserFile</code> and |
| 123 | <code>AuthGroupFile</code> with the <code>ftpasswd</code> tool, you configure |
| 124 | your <code>proftpd</code> to use those files by adding the following directives |
| 125 | to your <code>proftpd.conf</code>: |
| 126 | <pre> |
| 127 | AuthUserFile /path/to/ftpd.passwd |
| 128 | AuthGroupFile /path/to/ftpd.group |
| 129 | </pre> |
| 130 | The <code>ftpasswd</code> tool is a Perl script, distributed with the |
| 131 | ProFTPD source code, under the <code>contrib/</code> directory. A copy |
| 132 | can also be found <a href="https://github.com/proftpd/proftpd/blob/master/contrib/ftpasswd">on GitHub</a>. |
| 133 | |
| 134 | <p> |
| 135 | Another very popular authentication mechanism used for virtual users is a SQL |
| 136 | database such as MySQL or Postgres. This mechanism is supported by ProFTPD's |
| 137 | <code>mod_sql</code> module; more information on using <code>mod_sql</code> |
| 138 | can be found in the <a href="SQL.html">SQL</a> howto, and the |
| 139 | <code>mod_sql</code> <a href="../contrib/mod_sql.html">documentation</a>. |
| 140 | |
| 141 | <p> |
| 142 | Some sites still experience permissions issues, even though everything appears |
| 143 | to be configured properly. If this happens, define an |
| 144 | <a href="../contrib/mod_sql.html#SQLLogFile"><code>SQLLogFile</code></a> in your <code>proftpd.conf</code>: |
| 145 | <pre> |
| 146 | SQLLogFile /path/to/mod_sql.log |
| 147 | </pre> |
| 148 | This log file will show which IDs the <code>mod_sql</code> module is |
| 149 | assigning to users/groups looked up by <code>proftpd</code>. If the IDs |
| 150 | are <b>not</b> what you have in your SQL tables, then you need to use the |
| 151 | following directives: |
| 152 | <a href="../contrib/mod_sql.html#SQLMinUserUID"><code>SQLMinUserUID</code></a>, <a href="../contrib/mod_sql.html#SQLMinUserGID"><code>SQLMinUserGID</code></a>, and <a href="../contrib/mod_sql.html#SQLMinUserID"><code>SQLMinUserID</code></a>. The <code>mod_sql</code> module contains some default limits |
| 153 | on the range of IDs it returns; the above directives are used to tweak those |
| 154 | default limits. |
| 155 | |
| 156 | <p> |
| 157 | User documentation for the <code>mod_ldap</code> module (for virtual users via |
| 158 | LDAP directories) and <code>mod_radius</code> module (for virtual users via |
| 159 | RADIUS servers) is not yet complete. |
| 160 | |
| 161 | <p> |
| 162 | <b>Important</b>: <code>proftpd</code> will use <b>all</b> authentication |
| 163 | mechanisms <b>by default</b>. This is why a user that does not appear |
| 164 | in an <code>AuthUserFile</code>, but <b>is</b> defined in the |
| 165 | system <code>/etc/passwd</code> file, can login by default. Use the |
| 166 | <code>AuthOrder</code> configuration directive to change this. This |
| 167 | directive is explained in more detail in the |
| 168 | <a href="Authentication.html">Authentication</a> howto. |
| 169 | |
| 170 | <p><a name="UsingAnonymous"></a> |
| 171 | <font color=red>Question</font>: But I've seen examples that use the <code><Anonymous></code> section for virtual users. Why don't you mention this?<br> |
| 172 | <font color=blue>Answer</font>: The <code><Anonymous></code> context |
| 173 | should <b>never</b> be used to define a virtual user. This type of |
| 174 | configuration is a crude hack, leftover from ProFTPD's early days. Using |
| 175 | an <code>AuthUserFile</code> is better supported, better documented, more |
| 176 | flexible, and more in line with ProFTPD's design philosophy. |
| 177 | |
| 178 | <p><a name="PAM"></a> |
| 179 | <font color=red>Question</font>: What about using PAM for virtual users?<br> |
| 180 | <font color=blue>Answer</font>: Please read the |
| 181 | <a href="Authentication.html">Authentication</a> howto. |
| 182 | |
| 183 | <p> |
| 184 | <hr> |
| 185 | <font size=2><b><i> |
| 186 | © Copyright 2017-2023 The ProFTPD Project<br> |
| 187 | All Rights Reserved<br> |
| 188 | </i></b></font> |
| 189 | <hr> |
| 190 | |
| 191 | </body> |
| 192 | </html> |