| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_auth_pam</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_auth_pam</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | PAM stands for <b>P</b>luggable <b>A</b>uthentication <b>M</b>odules, |
| 17 | and is used to configure ways for authenticating users. Now |
| 18 | "authenticating" a user usually means comparing a password they |
| 19 | give with some other information, and returning a "yes/no"-style |
| 20 | answer. PAM does <b>not</b> provide all of the other information for a user, |
| 21 | such as UID, GID, home, and shell. This means that <code>mod_auth_pam</code> |
| 22 | cannot be used, by itself, as an auth module for <code>proftpd</code>; |
| 23 | <code>mod_auth_pam</code> is used to supplement other auth modules by |
| 24 | providing access to PAM's additional authentication checks. |
| 25 | |
| 26 | <p> |
| 27 | Installation instructions for <code>mod_auth_pam</code> can be found |
| 28 | <a href="#Installation">here</a>. |
| 29 | |
| 30 | <p> |
| 31 | The most current version of <code>mod_auth_pam</code> is distributed in the |
| 32 | ProFTPD source distribution. |
| 33 | |
| 34 | <h2>Directives</h2> |
| 35 | <ul> |
| 36 | <li><a href="#AuthPAM">AuthPAM</a> |
| 37 | <li><a href="#AuthPAMConfig">AuthPAMConfig</a> |
| 38 | <li><a href="#AuthPAMOptions">AuthPAMOptions</a> |
| 39 | </ul> |
| 40 | |
| 41 | <hr> |
| 42 | <h3><a name="AuthPAM">AuthPAM</a></h3> |
| 43 | <strong>Syntax:</strong> AuthPAM <em>on|off</em><br> |
| 44 | <strong>Default:</strong> AuthPAM on<br> |
| 45 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 46 | <strong>Module:</strong> mod_auth_pam<br> |
| 47 | <strong>Compatibility:</strong> 1.2.8rc2 and later |
| 48 | |
| 49 | <p> |
| 50 | The <code>AuthPAM</code> directive enables or disables the module's runtime |
| 51 | PAM check. If it is set to <em>off</em> this module does not consult PAM |
| 52 | when authenticating a user. |
| 53 | |
| 54 | <p> |
| 55 | <hr> |
| 56 | <h3><a name="AuthPAMConfig">AuthPAMConfig</a></h3> |
| 57 | <strong>Syntax:</strong> AuthPAMConfig <em>service</em><br> |
| 58 | <strong>Default:</strong> AuthPAMConfig ftp<br> |
| 59 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 60 | <strong>Module:</strong> mod_auth_pam<br> |
| 61 | <strong>Compatibility:</strong> 1.2.8rc2 and later |
| 62 | |
| 63 | <p> |
| 64 | The <code>AuthPAMConfig</code> directive is used to specify the name of |
| 65 | the service used when performing the PAM check; PAM configurations can |
| 66 | vary depending on the service. By default, the "ftp" service |
| 67 | is used. Note that on some platforms, <i>e.g.</i> FreeBSD, this may |
| 68 | need to be set to "ftpd", depending on the PAM configuration |
| 69 | involved. |
| 70 | |
| 71 | <p> |
| 72 | Here's an example of changing the <em>service</em> used: |
| 73 | <pre> |
| 74 | <IfModule mod_auth_pam.c> |
| 75 | AuthPAMConfig ftpd |
| 76 | </IfModule> |
| 77 | </pre> |
| 78 | |
| 79 | <p> |
| 80 | <hr> |
| 81 | <h3><a name="AuthPAMOptions">AuthPAMOptions</a></h3> |
| 82 | <strong>Syntax:</strong> AuthPAMOptions <em>opt1 opt2 ... optN</em><br> |
| 83 | <strong>Default:</strong> None<br> |
| 84 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 85 | <strong>Module:</strong> mod_auth_pam<br> |
| 86 | <strong>Compatibility:</strong> 1.3.2rc1 and later |
| 87 | |
| 88 | <p> |
| 89 | The <code>AuthPAMOptions</code> directive is used to configure various optional |
| 90 | behavior of <code>mod_auth_pam</code>. |
| 91 | |
| 92 | <p> |
| 93 | Example: |
| 94 | <pre> |
| 95 | <IfModule mod_auth_pam.c> |
| 96 | # Do not set the PAM_TTY token when authenticating via PAM |
| 97 | AuthPAMOptions NoTTY |
| 98 | </IfModule> |
| 99 | </pre> |
| 100 | |
| 101 | <p> |
| 102 | The currently implemented options are: |
| 103 | <ul> |
| 104 | <li><code>NoTTY</code><br> |
| 105 | <p> |
| 106 | By default, <code>mod_auth_pam</code> will use the <code>PAM_TTY</code> |
| 107 | PAM API item, and will use a value of "/dev/ftpd<i>PID</i>". The item |
| 108 | can be used by PAM modules for filtering access, for example. This |
| 109 | "NoTTY" option tells <code>mod_auth_pam</code> to <b>not</b> set the |
| 110 | <code>PAM_TTY</code> item. |
| 111 | |
| 112 | <p> |
| 113 | <b>Note</b>: On Solaris platforms, the use of this <code>PAM_TTY</code> |
| 114 | token is <i>mandatory</i>, and cannot be disabled. This is due to |
| 115 | Solaris Bug ID 4250887. |
| 116 | </li> |
| 117 | </ul> |
| 118 | |
| 119 | <p> |
| 120 | <hr> |
| 121 | <h2><a name="Installation">Installation</a></h2> |
| 122 | The <code>mod_auth_pam</code> module is automatically included when |
| 123 | <code>proftpd</code> is built on a system that supports PAM. To disable |
| 124 | this automatic inclusion, use the <code>--disable-auth-pam</code> configure |
| 125 | option. |
| 126 | |
| 127 | <p> |
| 128 | <hr> |
| 129 | <h2><a name="Usage">Usage</a></h2> |
| 130 | The following are some example platform-specific PAM configurations. |
| 131 | |
| 132 | <p> |
| 133 | <i>FreeBSD</i><br> |
| 134 | To use PAM with ProFTPD, you must edit <code>/etc/pam.conf</code> (or |
| 135 | <code>/etc/pam.d/ftpd</code>) and add the following lines, if they are not |
| 136 | already present: |
| 137 | <pre> |
| 138 | ftpd auth required pam_unix.so try_first_pass |
| 139 | ftpd account required pam_unix.so try_first_pass |
| 140 | ftpd session required pam_permit.so |
| 141 | </pre> |
| 142 | In your <code>proftpd.conf</code>, you will need to set |
| 143 | <code>AuthPAMConfig</code> to use the above service name, <i>i.e.</i> "ftpd": |
| 144 | <pre> |
| 145 | <IfModule mod_auth_pam.c> |
| 146 | AuthPAMConfig ftpd |
| 147 | </IfModule> |
| 148 | </pre> |
| 149 | PAM authentication should now work properly. |
| 150 | |
| 151 | <p> |
| 152 | <i>Linux</i><br> |
| 153 | To use PAM with ProFTPD, you must edit <code>/etc/pam.d/ftp</code> and add the |
| 154 | following lines for RedHat installations: |
| 155 | <pre> |
| 156 | #%PAM-1.0 |
| 157 | auth required /lib/security/pam_pwdb.so shadow nullok |
| 158 | account required /lib/security/pam_pwdb.so |
| 159 | session required /lib/security/pam_pwdb.so |
| 160 | </pre> |
| 161 | For SuSE: |
| 162 | <pre> |
| 163 | #%PAM-1.0 |
| 164 | auth required /lib/security/pam_unix.so shadow nullok |
| 165 | account required /lib/security/pam_unix.so |
| 166 | session required /lib/security/pam_unix.so |
| 167 | </pre> |
| 168 | These settings are valid for RedHat and SuSE Linux systems. Other Linux |
| 169 | distributions may differ. |
| 170 | |
| 171 | <p> |
| 172 | <b>NOTE</b>: If you are using a 64-bit system, you may need to change the above |
| 173 | paths from "/lib/security/..." to "/lib64/security/...". Without this |
| 174 | correction, on 64-bit systems, your ProFTPD logs may contain errors like: |
| 175 | <pre> |
| 176 | PAM unable to dlopen(/lib/security/pam_pwdb.so) |
| 177 | PAM [dlerror: /lib/security/pam_pwdb.so: cannot open shared object file: |
| 178 | No such file or directory] |
| 179 | </pre> |
| 180 | After updating the paths in your <code>/etc/pam.d/ftp</code> file, be sure to |
| 181 | restart ProFTPD, so that the new PAM configuration takes effect. |
| 182 | |
| 183 | <p> |
| 184 | <i>Mac OS X</i><br> |
| 185 | To use PAM with ProFTPD, you must edit <code>/etc/pam.d/ftp</code> and add the |
| 186 | following lines: |
| 187 | <pre> |
| 188 | auth required pam_unix.so try_first_pass |
| 189 | account required pam_unix.so try_first_pass |
| 190 | session required pam_permit.so |
| 191 | </pre> |
| 192 | Or, if you are running Mac OSX 10.3 or later, you should have an |
| 193 | <code>/etc/pam.d/ftpd</code> file that contains the following: |
| 194 | <pre> |
| 195 | auth sufficient pam_securityserver.so |
| 196 | auth required pam_deny.so |
| 197 | account required pam_permit.so |
| 198 | password required pam_deny.so |
| 199 | session required pam_permit.so |
| 200 | </pre> |
| 201 | Then, in your <code>proftpd.conf</code>, use: |
| 202 | <pre> |
| 203 | <IfModule mod_auth_pam.c> |
| 204 | AuthPAMConfig ftpd |
| 205 | </IfModule> |
| 206 | </pre> |
| 207 | |
| 208 | <p> |
| 209 | <b>Logging</b><br> |
| 210 | The <code>mod_auth_pam</code> module supports <a href="../howto/Tracing.html">trace logging</a>, via the module-specific log channels: |
| 211 | <ul> |
| 212 | <li>auth.pam |
| 213 | </ul> |
| 214 | Thus for trace logging, to aid in debugging, you would use the following in |
| 215 | your <code>proftpd.conf</code>: |
| 216 | <pre> |
| 217 | TraceLog /path/to/ftpd/trace.log |
| 218 | Trace auth.pam:20 |
| 219 | </pre> |
| 220 | This trace logging can generate large files; it is intended for debugging use |
| 221 | only, and should be removed from any production configuration. |
| 222 | |
| 223 | <p><a name="FAQ"> |
| 224 | <b>Frequently Asked Questions</b><br> |
| 225 | |
| 226 | <p><a name="AuthPAMFailedToReleaseSession"> |
| 227 | <font color=red>Question</font>: I am using <code>mod_auth_pam</code>, and in |
| 228 | the system logs, I see the following messages for my ProFTPD sessions: |
| 229 | <pre> |
| 230 | proftpd[1654993]: pam_unix(proftpd:session): session opened for user paul by (uid=0) |
| 231 | proftpd[1654993]: pam_systemd(proftpd:session): Failed to release session: Access denied |
| 232 | proftpd[1654993]: pam_unix(proftpd:session): session closed for user paul |
| 233 | </pre> |
| 234 | Is this a bug? |
| 235 | <p> |
| 236 | <font color=blue>Answer</font>: No, it is not a bug. It is a consequence of |
| 237 | how ProFTPD manages root privileges, and (bad) assumptions made by the PAM API |
| 238 | and libraries. |
| 239 | |
| 240 | <p> |
| 241 | ProFTPD retains root privileges for a session only long enough to authenticate |
| 242 | the user; this authentication <i>does</i> include opening a PAM session. After |
| 243 | authentication completes, ProFTPD drops root privileges completely by default. |
| 244 | This means that when that session completes, and the <code>mod_auth_pam</code> |
| 245 | module uses the PAM API to close the session, the process no longer has the |
| 246 | root privileges that the underlying PAM libraries need/want, hence the |
| 247 | "Access denied" error. |
| 248 | |
| 249 | <p> |
| 250 | This log message is benign, because it only occurs when the session process |
| 251 | is ending anyway. You can change this by configuring ProFTPD to <em>not</em> |
| 252 | drop root privileges after authentication -- although this is not recommended: |
| 253 | <pre> |
| 254 | # Do not revoke root privileges after authentication |
| 255 | RootRevoke off |
| 256 | </pre> |
| 257 | |
| 258 | <p><a name="AuthPAMAuthoritative"> |
| 259 | <font color=red>Question</font>: I need to use PAM for enforcing the |
| 260 | handling of aged/expired passwords on my Unix system. How do I make sure |
| 261 | that PAM does the right thing?<br> |
| 262 | <font color=blue>Answer</font>: For this sort of requirement, you are |
| 263 | probably already using ProFTPD's default authentication modules, which include |
| 264 | <code>mod_auth_unix</code> and <code>mod_auth_pam</code>. But to make sure |
| 265 | that the PAM rules are enforced, you need to make <code>mod_auth_pam</code> |
| 266 | be "authoritative", <i>i.e.</i> have the final say on whether a given password |
| 267 | is acceptable. Use the <code>AuthOrder</code> directive to accomplish this, |
| 268 | using: |
| 269 | <pre> |
| 270 | # It is important that mod_auth_pam appear before mod_auth_unix, and |
| 271 | # that the asterisk appear <i>after</i> the name, not before. |
| 272 | AuthOrder mod_auth_pam.c* mod_auth_unix.c |
| 273 | </pre> |
| 274 | The asterisk ("*") after a module name in the <code>AuthOrder</code> directive |
| 275 | is what tells <code>proftpd</code> to treat that module's results as |
| 276 | authoritative. |
| 277 | |
| 278 | <p> |
| 279 | <hr> |
| 280 | <font size=2><b><i> |
| 281 | © Copyright 2017-2020 The ProFTPD Project<br> |
| 282 | All Rights Reserved<br> |
| 283 | </i></b></font> |
| 284 | <hr> |
| 285 | |
| 286 | </body> |
| 287 | </html> |