Questions tagged [umask]

umask is a Unix command to specify default permissions for the new files, created by the current user. umask is inverted ( umask 0 = world readable, writeable and executable).

umask is a Unix command to specify default permissions for the new files, created by the current user. umask is inverted ( umask 0 = world readable, writeable and executable).

It is used when multiple users produce some shared data but any user must be capable of overwriting this data.

The default umask is often selected so to 022 (only owner can modify the file but the group and the world can read) or to 002 (owner and group can modify the file, the world can read).

umask accepts the same bitwise mask as chmod command, but it is inverted: it specifies bits that must not be set. For instance

 umask 555
 touch t.tmp
 ls -l t.tmp

will result

 --w--w--w- 1 me 0 2013-01-25 09:11 z.tmp

(444 is the "write only" flag). By concept, the mask serves for removal of permissions (000 - nothing is removed, 777 - all removed).

Regardless of umask, the newly created files may not be executable, for instance on Ubuntu 10.04:

 umask 0
 touch x.tmp
 ls -l x.tmp

will anyway result

 -rw-rw-rw- me 0 2013-01-25 09:36 x.txt

even if the lowest (execute) bit is 0 in umask.

151 questions
11
votes
4 answers

When is umask() useful?

umask(0); fd = open("/dev/null", O_RDWR); Here's man 2 umask: umask() sets the calling process’s file mode creation mask (umask) to mask & 0777. But it doesn't make sense for me,as when we call open ,we will also provide a mode parameter. So…
cpuer
  • 7,413
  • 14
  • 35
  • 39
11
votes
3 answers

Making new files automatically executable?

Is it possible to make all newly created files have the execute permission when they are created? Why can't I grant it by default?
Jurgen Malinao
  • 149
  • 1
  • 1
  • 5
10
votes
3 answers

Setting the umask of the jenkins process

Our jenkins CI server (v1.499) runs tests that call URLs on the CI machine. The applications behind those URLs change the same temporary files as the unit test processes change, so those files need to be group writable. I fixed that for apache…
cweiske
  • 30,033
  • 14
  • 133
  • 194
9
votes
3 answers

How to create directory with right permissions using C on Posix

I am trying to write a simple C program that creates directories (a mkdir clone.). This is what I have so far: #include #include // mkdir #include // perror mode_t getumask() { mode_t mask = umask(0); umask…
yasar
  • 13,158
  • 28
  • 95
  • 160
7
votes
1 answer

linux umask for sudo and apache

I want to make 002 the system-wide umask for all users (in Ubuntu). I managed to do so for all regular users using the instructions provided by @ephemient (From this post, thanks for that!). However I got 2 more problems. Firstly, when sudoing, the…
user1834095
  • 5,332
  • 2
  • 20
  • 38
5
votes
2 answers

PHP mkdir() and fopen() does not work - permissions problem? umask problem?

The following PHP script fails to create the directory. It will also fail to create the file (when the directory already exists). ini_set('error_reporting', E_ALL); define('ABSPATH', $_SERVER['DOCUMENT_ROOT']); echo ABSPATH . '
matthewpavkov
  • 2,918
  • 4
  • 21
  • 37
5
votes
3 answers

error cannot find module 'umask'

I just installed nodejs x64 on my Windows 10 computer. I keep all default config, I open cmd and type: npm -v Then i got following error: module.js:457 throw err; ^ Error: Cannot find module 'umask' at Function.Module._resolveFilename…
5
votes
1 answer

Midnight commander does not respect umask

When I create new file in Midnight commander and save it (Shift+F4, write something, F2, name the file), it is created with 640 pemissions even thought my umask is set to 0007 so it should be created with permissions 660. Is there any secret place…
gorn
  • 5,042
  • 7
  • 31
  • 46
5
votes
2 answers

Why is UMASK setting in /etc/login.defs not honoured?

I have the UMASK setting in /etc/login.defs set to 077, but when I log in and query it, I get this: $ umask 0007
Alastair Irvine
  • 1,166
  • 12
  • 16
5
votes
1 answer

Reading default FileMode when using os.O_CREATE

I'm new to Go, have a bit of a problem with reading default file permissions / system mask. Of course I can specify fixed permissions: f, err := os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY, 0600) But I would like the program to behave nicely and…
LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93
5
votes
2 answers

How to set default permissions for new files created with php

Hi I am running a centos server and I want to know how I can set the default chmod of a newly created file that is created by php like fopen. At the moment it is doing 644 but I want 666 so where can I specify this setting?
user550
  • 328
  • 1
  • 5
  • 11
5
votes
3 answers

Set Different Umask For Files And Folders

I am writing a bash script to update some files/directories and I want to run umask in the script to set default permissions for files/directories created by the script. I know I can umask to set the permissions for both files and directories…
kittycat
  • 14,983
  • 9
  • 55
  • 80
5
votes
2 answers

umask setting changes after cd

I've got something odd to report. On my newly configured RHEL5 server my shell is set to /bin/bash I have umask set to 002 in .bashrc. When I first log in, umask appears to work correctly: $ touch a $ ls -l a -rw-rw-r-- etc..... if I create…
cshehadi
  • 111
  • 5
4
votes
2 answers

apache and sftp permissions for wordpress automatic update in ubuntu

It's my first time trying to set up Wordpress or any website on a cloud hosting. I am on Ubuntu server, and Wordpress is located in var/www/mydomain/public folder. What I want to achieve is this: Both Wordpress (PHP) and SFTP users can access and…
ragulka
  • 4,312
  • 7
  • 48
  • 73
4
votes
1 answer

File creation mode mask

I'm struggling to understand why would a Unix daemon set the file creation mode mask to 0. I'll be thankful if someone can demystify the umask function.
mrk
  • 3,061
  • 1
  • 29
  • 34
1
2
3
10 11