Questions tagged [umask]

Mask that controls which file permissions are set for files and directories when they are created. It also refers to a function that sets the mask, and to the mask itself, which is formally known as the file mode creation mask.

Introduction

When a user creates a file or a directory under GNU/Linux or another Unix-like operating system, the default set of permissions are set by the umask command.

Set up the default umask

Usually the umask is set in the file:

 /etc/profile

or for bash shell:

~/.bashrc 
~/.bash_profile

for ksh/bash:

 ~/.profile 

for csh:

~/.cshrc 

for defining the user's environment at login:

~/.login

and it set with adding something like in the files:

umask 022

How is the umask calculated ?

The umask command uses octal values for determining the permissions of the files and directories. The default permissions for a file are calculated by subtracting the value of 666 like:

666 - 022 = 644  

This means the file permissions would be (rw-r--r--)

For directories the default permissions are calculated as follows:

777 - 022 = 755

This translates to base directory permissions (drwx-rw-rw-)

For more information on umask type in shell:

$ man umask

Reference

Wikipedia entry about umask

181 questions
171
votes
3 answers

Make all new files in a directory accessible to a group

Suppose I have two users Alice and Bob and a group GROUPNAME and a folder foo, both users are members of GROUPNAME (using Linux and ext3). If I save as user Alice a file under foo, the permissions are: -rw-r--r-- Alice Alice. However, is it…
student
  • 17,875
  • 31
  • 103
  • 169
30
votes
3 answers

Why doesn't umask change execute permissions on files?

If I change the umask to 0000, I'd expect a text file to be created with rwxrwxrwx permissions (based on my understanding of the umask, as described in the "possible duplicate" question) However, when I try this, I get the following $ umask 0000 $…
Alana Storm
  • 1,413
  • 3
  • 14
  • 17
23
votes
3 answers

How can I change the umask for one command only?

How can I interactively execute a command in Linux (zsh, if it matters) with a different umask from the default, for one command only? Perhaps a combination of commands combined in a single line? The new umask should apply only to that command and…
Andrew Ferrier
  • 1,061
  • 2
  • 11
  • 21
20
votes
1 answer

How is umask calculated in Linux?

So I know umask can restrict privileged users, using this format umask ugo. I understand that the read = 4, write = 2, and exec = 1. However, when I type umask, it returns 4 digits which is 0022 or 0073. I have no understanding of how does this work…
Braiam
  • 35,380
  • 25
  • 108
  • 167
20
votes
2 answers

How to check umask for all users under Linux?

Under AIX I can check the umask for all users with: cut -d : -f 1 /etc/passwd | while read ONELINE; do lsuser -a umask "$ONELINE"; done But how can I check the umask setting for all users under Linux? (su to every user and then umask command? Are…
gasko peter
  • 5,434
  • 22
  • 83
  • 145
20
votes
6 answers

Downsides of umask 077?

What are the cons, for having a restrictive umask of 077? A lot of distros (I believe all, except Red Hat? ) have a default umask of 022, configured in /etc/profile. This seems way too insecure for a non-desktop system, which multiple users are…
K. Norbert
  • 303
  • 1
  • 2
  • 6
17
votes
1 answer

Set umask for systemd unit

I am running rsync daemon with a specific user on Ubuntu machine. The problem is that since daemon users don't login, the umask set for the user is the default one. How do I set umask for the user in the daemon process?
CuriousGuy
  • 635
  • 2
  • 7
  • 15
16
votes
3 answers

How to set umask for a system-user?

Is it possible to set the umask for a system-user (created with useradd --system username)?
sid_com
  • 1,531
  • 3
  • 16
  • 20
15
votes
2 answers

What is the first digit in umask value?

If I understand correctly file permissions have an associated 3 digit number which specify read/write/execute permission. The umask value is a default 'mask' which is subtracted from the default value. So for a umask value of 0022 the default value…
Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167
14
votes
10 answers

How to set `umask` for the entire gnome session?

Using Gnome 3.18. I share files between other family members, but the default umask on my distro (archlinux) is 0022. So every file/directory created is not writable for our common group. I tried to put umask 0002 in /etc/profile but the gnome…
Christophe Drevet
  • 4,047
  • 1
  • 16
  • 16
11
votes
3 answers

Why are files in my home dir being created as world-writable despite a more-restrictive umask?

I've realized that the permissions for new files and directories behave a bit strangely. First of all, umask seems to return the right answer: $ umask 0002 This means full access for my user and my group, no write access for the rest of the world,…
rsuarez
  • 902
  • 1
  • 7
  • 24
11
votes
2 answers

Why do some umask values not take effect?

I'm trying to understand permissions better, so I'm doing some "exercises". Here's a sequence of commands that I'm using with their respective output: $ umask 0022 $ touch file1 $ ls -l file1 -rw-r--r-- 1 user group 0 Mar 16 12:55 file1 $ mkdir…
ikeDiM
  • 137
  • 1
  • 9
9
votes
3 answers

Permissions on Files:

I would like to give 755 permissions to a directory, so I use: # chmod -R 755 /my/folder/ It works for all files inside my folder, but the problem is that I use scripts that create new files in this folder, and by default the permissions are…
klaypez
  • 303
  • 1
  • 2
  • 9
9
votes
1 answer

Why is the default umask 002 or 022 in many Unix systems? Seems insecure by default

I have been using Linux & Unix for a long time. The first time I learned Unix is in a computer classroom with many students, where the instructor told us that you can use ssh to log in to remote workstations provided by the university I was studying…
Bossliaw
  • 199
  • 1
  • 5
9
votes
3 answers

Historically why is umask the way it is?

umask has always tripped me up. Logically I would prefer to have a 'setmask' instead that takes chmod-style arguments. Anyone know why it is the way it is?
ojblass
  • 343
  • 2
  • 10
1
2 3
12 13