ProFTPD's Umask
configuration directive is used to set the file permission bits on newly
created files and directories. However, the way in which Umask
is to be used is not entirely straightforward.
Umask
is used to set the value that proftpd
will
use when calling umask(2)
. The umask(2)
function
works something like this:
new file mode = base-mode - umask(Technically, the operation is
base-mode & ~umask
).
Thus, with a base-mode of 0666
, and a umask of
0022
, the permissions on the newly created file will be
0644
(e.g. rw-r--r--
).
A quick review of permission bits:
4 is read permission (r) 2 is write permission (w) 1 is execute permission (x)The first digit of a mode (
0750
, for example) is used to
specify some special bits (e.g. set-user-ID, set-group-ID, and the
"sticky bit"). The second digit, the 7
in this
example, specifies the user owner permissions, and is a sum of the above
permission bits: 7 = 4 + 2 + 1
(e.g. rwx
).
Group owner permissions are specified by the third bit, 5
:
5 = 4 + 1
(e.g. r-x
). And finally, other
or world permissions are specified using the last bit, which in the
example is 0
(no permissions, e.g. ---
).
Here are some concrete examples to help illustrate things:
Mode | Label | Description |
0777 |
rwxrwxrwx |
read/write/execute permissions for user owner, group owner, and other |
0666 |
rw-rw-rw- |
read/write permissions for user owner, group owner, and other |
0755 |
rwxr-xr-x |
read/write/execute permissions for user owner, read/execute permissions for group owner and other |
0750 |
rwxr-x--- |
read/write/execute permissions for user owner, read permission for group owner, no permissions for other |
0644 |
rw-r--r-- |
read/write permissions for user owner, read permission for group owner and other |
0511 |
r-x--x--x |
read/execute permissions for user owner, execute permission for group owner and other |
The proftpd
daemon always starts with a base-mode of
0666
when creating files. Note that Umask
can only
be used to "take away" permissions granted by the base-mode;
it cannot be used to add permissions that are not there. This means that
files uploaded to a proftpd
server will never have the execute
permission enabled by default, since the 0666
base-mode
does not have any execute bits enabled). This is a conscious security design
decision. For directories, a different base-mode of 0777
is used. The umask used for directories can be configured using the
optional second parameter to the Umask
directive; if this second
parameter is not used, the umask used for created directories will
default to the same umask as used for files.
If it is necessary to make uploaded files executable, the
SITE CHMOD
FTP command can be used:
SITE CHMOD mode fileUse of this command can be restricted using a "command" of
SITE_CHMOD
in a <Limit>
section. For
example, this section of a proftpd.conf
file:
<Limit SITE_CHMOD> AllowUser ftpadmin DenyAll </Limit>will deny everyone except user
ftpadmin
from being able to
use the SITE CHMOD
command to change the permissions on files
via FTP. Note that this construction is recommended instead of using the
deprecated (as of proftpd-1.2.2rc2
) AllowChmod
configuration directive.
Examples of Using the Umask
Directive
You have just installed proftpd
, and now need to figure out what
permissions file/directories created on your FTP server should have. As
a conscientious FTP server administrator, you want files/directories to
have the minimum necessary permissions (rather than letting users have access
to files/directories that they do not need).
If only the user who creates the files and directories should have full access, e.g. so they can read and write their own files, then you might use:
# Only the user can see their own files/directories Umask 0066 0077With this configuration, a newly uploaded file would have
0600
(rw-------
) permissions:
0600 = 0666 - 0066and a newly created directory would have
0700
(rwx------
) permissions:
0700 = 0777 - 0077
Another common case is where you have many users who are uploading files for sharing with other users. So you want the files to be readable by everyone, but only the user who uploaded the file should have permission for writing/changing the file. For this, you might use:
# Only the user can change their own files Umask 0022With this configuration, a newly uploaded file would have
0644
(rw-r--r--
) permissions:
0644 = 0666 - 0022and a newly created directory would have
0755
(rwxr-xr-x
) permissions:
0755 = 0777 - 0022