| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Umask</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b><i>Umask</i></b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | ProFTPD's <a href="../modules/mod_core.html#Umask"><code>Umask</code></a> |
| 15 | configuration directive is used to set the file permission bits on newly |
| 16 | created files and directories. However, the way in which <code>Umask</code> |
| 17 | is to be used is not entirely straightforward. |
| 18 | |
| 19 | <p> |
| 20 | <code>Umask</code> is used to set the value that <code>proftpd</code> will |
| 21 | use when calling <code>umask(2)</code>. The <code>umask(2)</code> function |
| 22 | works something like this: |
| 23 | <pre> |
| 24 | new file mode = <i>base-mode</i> - <i>umask</i> |
| 25 | </pre> |
| 26 | (Technically, the operation is <code><i>base-mode & ~umask</i></code>). |
| 27 | Thus, with a <i>base-mode</i> of <code>0666</code>, and a <i>umask</i> of |
| 28 | <code>0022</code>, the permissions on the newly created file will be |
| 29 | <code>0644</code> (<i>e.g.</i> <code>rw-r--r--</code>). |
| 30 | |
| 31 | <p> |
| 32 | A quick review of permission bits: |
| 33 | <pre> |
| 34 | 4 <i>is</i> read permission (<i>r</i>) |
| 35 | 2 <i>is</i> write permission (<i>w</i>) |
| 36 | 1 <i>is</i> execute permission (<i>x</i>) |
| 37 | </pre> |
| 38 | The first digit of a <i>mode</i> (<code>0750</code>, for example) is used to |
| 39 | specify some special bits (<i>e.g.</i> set-user-ID, set-group-ID, and the |
| 40 | "sticky bit"). The second digit, the <code>7</code> in this |
| 41 | example, specifies the user owner permissions, and is a sum of the above |
| 42 | permission bits: <code>7 = 4 + 2 + 1</code> (<i>e.g.</i> <code>rwx</code>). |
| 43 | Group owner permissions are specified by the third bit, <code>5</code>: |
| 44 | <code>5 = 4 + 1</code> (<i>e.g.</i> <code>r-x</code>). And finally, other |
| 45 | or world permissions are specified using the last bit, which in the |
| 46 | example is <code>0</code> (no permissions, <i>e.g.</i> <code>---</code>). |
| 47 | |
| 48 | <p> |
| 49 | Here are some concrete examples to help illustrate things: |
| 50 | <p> |
| 51 | <table border=1 summary="Umask Examples"> |
| 52 | <tr> |
| 53 | <td><b>Mode</b></td> |
| 54 | <td><b>Label</b></td> |
| 55 | <td><b>Description</b></td> |
| 56 | </tr> |
| 57 | |
| 58 | <tr> |
| 59 | <td> <code>0777</code> </td> |
| 60 | <td> <code>rwxrwxrwx</code> </td> |
| 61 | <td>read/write/execute permissions for user owner, group owner, and other</td> |
| 62 | </tr> |
| 63 | |
| 64 | <tr> |
| 65 | <td> <code>0666</code> </td> |
| 66 | <td> <code>rw-rw-rw-</code> </td> |
| 67 | <td>read/write permissions for user owner, group owner, and other</td> |
| 68 | </tr> |
| 69 | |
| 70 | <tr> |
| 71 | <td> <code>0755</code> </td> |
| 72 | <td> <code>rwxr-xr-x</code> </td> |
| 73 | <td>read/write/execute permissions for user owner, read/execute permissions for group owner and other</td> |
| 74 | </tr> |
| 75 | |
| 76 | <tr> |
| 77 | <td> <code>0750</code> </td> |
| 78 | <td> <code>rwxr-x---</code> </td> |
| 79 | <td>read/write/execute permissions for user owner, read permission for group owner, no permissions for other</td> |
| 80 | </tr> |
| 81 | |
| 82 | <tr> |
| 83 | <td> <code>0644</code> </td> |
| 84 | <td> <code>rw-r--r--</code> </td> |
| 85 | <td>read/write permissions for user owner, read permission for group owner and other</td> |
| 86 | </tr> |
| 87 | |
| 88 | <tr> |
| 89 | <td> <code>0511</code> </td> |
| 90 | <td> <code>r-x--x--x</code> </td> |
| 91 | <td>read/execute permissions for user owner, execute permission for group owner and other</td> |
| 92 | </tr> |
| 93 | </table> |
| 94 | |
| 95 | <p> |
| 96 | The <code>proftpd</code> daemon always starts with a <i>base-mode</i> of |
| 97 | <code>0666</code> when creating files. Note that <code>Umask</code> can only |
| 98 | be used to "take away" permissions granted by the <i>base-mode</i>; |
| 99 | it cannot be used to add permissions that are not there. This means that |
| 100 | files uploaded to a <code>proftpd</code> server will never have the execute |
| 101 | permission enabled by default, since the <code>0666</code> <i>base-mode</i> |
| 102 | does not have any execute bits enabled). This is a conscious security design |
| 103 | decision. For directories, a different <i>base-mode</i> of <code>0777</code> |
| 104 | is used. The <i>umask</i> used for directories can be configured using the |
| 105 | optional second parameter to the <code>Umask</code> directive; if this second |
| 106 | parameter is not used, the <i>umask</i> used for created directories will |
| 107 | default to the same <i>umask</i> as used for files. |
| 108 | |
| 109 | <p> |
| 110 | If it is necessary to make uploaded files executable, the |
| 111 | <code>SITE CHMOD</code> FTP command can be used: |
| 112 | <pre> |
| 113 | SITE CHMOD <i>mode</i> <i>file</i> |
| 114 | </pre> |
| 115 | Use of this command can be restricted using a "command" of |
| 116 | <code>SITE_CHMOD</code> in a <code><Limit></code> section. For |
| 117 | example, this section of a <code>proftpd.conf</code> file: |
| 118 | <pre> |
| 119 | <Limit SITE_CHMOD> |
| 120 | AllowUser ftpadmin |
| 121 | DenyAll |
| 122 | </Limit> |
| 123 | </pre> |
| 124 | will deny everyone except user <code>ftpadmin</code> from being able to |
| 125 | use the <code>SITE CHMOD</code> command to change the permissions on files |
| 126 | via FTP. Note that this construction is recommended instead of using the |
| 127 | deprecated (as of <code>proftpd-1.2.2rc2</code>) <code>AllowChmod</code> |
| 128 | configuration directive. |
| 129 | |
| 130 | <p> |
| 131 | <b>Examples of Using the <code>Umask</code> Directive</b><br> |
| 132 | You have just installed <code>proftpd</code>, and now need to figure out what |
| 133 | permissions file/directories created on your FTP server should have. As |
| 134 | a conscientious FTP server administrator, you want files/directories to |
| 135 | have the minimum necessary permissions (rather than letting users have access |
| 136 | to files/directories that they do not need). |
| 137 | |
| 138 | <p> |
| 139 | If only the user who creates the files and directories should have full |
| 140 | access, <i>e.g.</i> so they can read and write their own files, then you might |
| 141 | use: |
| 142 | <pre> |
| 143 | # Only the user can see their own files/directories |
| 144 | Umask 0066 0077 |
| 145 | </pre> |
| 146 | With this configuration, a newly uploaded file would have <code>0600</code> |
| 147 | (<code>rw-------</code>) permissions: |
| 148 | <pre> |
| 149 | 0600 = 0666 - 0066 |
| 150 | </pre> |
| 151 | and a newly created directory would have <code>0700</code> |
| 152 | (<code>rwx------</code>) permissions: |
| 153 | <pre> |
| 154 | 0700 = 0777 - 0077 |
| 155 | </pre> |
| 156 | |
| 157 | <p> |
| 158 | Another common case is where you have many users who are uploading files |
| 159 | for sharing with other users. So you want the files to be readable by |
| 160 | everyone, but only the user who uploaded the file should have permission for |
| 161 | writing/changing the file. For this, you might use: |
| 162 | <pre> |
| 163 | # Only the user can change their own files |
| 164 | Umask 0022 |
| 165 | </pre> |
| 166 | With this configuration, a newly uploaded file would have <code>0644</code> |
| 167 | (<code>rw-r--r--</code>) permissions: |
| 168 | <pre> |
| 169 | 0644 = 0666 - 0022 |
| 170 | </pre> |
| 171 | and a newly created directory would have <code>0755</code> |
| 172 | (<code>rwxr-xr-x</code>) permissions: |
| 173 | <pre> |
| 174 | 0755 = 0777 - 0022 |
| 175 | </pre> |
| 176 | |
| 177 | <p><a name="FAQ"></a> |
| 178 | <b>Frequently Asked Questions</b><br> |
| 179 | |
| 180 | <p><a name="UmaskExecutePermission"> |
| 181 | <font color=red>Question</font>: How can I configure <code>proftpd</code> so |
| 182 | that I can upload a file with <code>770</code> permissions?<br> |
| 183 | <font color=blue>Answer</font>: Short answer: you can't. Too many FTP servers, |
| 184 | in the past, would allow users to upload executable files. Hackers would |
| 185 | use this capability, and then exploit a flaw in one of the servers on that |
| 186 | machine to execute the crafted file they just uploaded. Thus ProFTPD does |
| 187 | not allow uploading of files with execute permissions. |
| 188 | |
| 189 | <p> |
| 190 | The workaround, as mentioned above, is to allow the client to use the |
| 191 | <code>SITE CHMOD</code> command to change the permissions on the file to |
| 192 | have the execute permissions. |
| 193 | |
| 194 | <p><a name="UmaskDeletePermission"> |
| 195 | <font color=red>Question</font>: I have a <code>Umask</code> value of |
| 196 | <code>0066</code>, so that only I have read/write permissions on my files. But other users can delete my files! Is this a <code>proftpd</code> bug?<br> |
| 197 | <font color=blue>Answer</font>: No. The permission for deleting a file is |
| 198 | <b>not</b> governed by the write permission on the deleted file; it is |
| 199 | controlled by the write permission <i>on the directory containing the file</i>. |
| 200 | |
| 201 | <p> |
| 202 | If you think of a directory as a "table of contents", with entries for each |
| 203 | of the files in that directory, then deleting a file means deleting the entry |
| 204 | for that file from the "table of contents", which is a write on the directory |
| 205 | (not on the deleted file). |
| 206 | |
| 207 | <p> |
| 208 | Let's assume that your files were in a directory whose permissions were |
| 209 | <code>0777</code> (<code>rwxrwxrwx</code>). This means that everyone has |
| 210 | write permissions in that directory. It also means that everyone can |
| 211 | delete files from that directory. |
| 212 | |
| 213 | <p> |
| 214 | Now let's assume that your files instead were in a directory whose permissions |
| 215 | where <code>0755</code> (<code>rwxr-xr-x</code>). This means that only the |
| 216 | user owner of the directory can delete files from that directory, and no one |
| 217 | else. |
| 218 | |
| 219 | <p> |
| 220 | For directories which contain files from different users, one of the |
| 221 | little-known (and very useful) permissions to have for the directory is |
| 222 | <code>1777</code> (<code>rwxrwxrwt</code>). The leading 1 (and <code>t</code>) |
| 223 | indicates the "sticky bit". This obscure bit is little used these days, |
| 224 | <i>except</i> in this useful configuration. When the sticky bit is set on |
| 225 | a directory (making it a "sticky directory"), normal users may not delete or |
| 226 | rename files of other users in that directory. Because of this property, |
| 227 | "sticky directories" are quite useful as shared directories (<i>e.g.</i> |
| 228 | <code>/tmp</code>). |
| 229 | |
| 230 | <p> |
| 231 | <hr> |
| 232 | <font size=2><b><i> |
| 233 | © Copyright 2017 The ProFTPD Project<br> |
| 234 | All Rights Reserved<br> |
| 235 | </i></b></font> |
| 236 | <hr> |
| 237 | |
| 238 | </body> |
| 239 | </html> |