Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Setting File Permissions with umask
7 May 2004 @ 18:07 BST
by Nomad

To set file default permissions on your system, umask is the tool. To understand how it works though, you need to understand [Octal File Permissions]. Read that? Good.

On most systems umask is set in /etc/profile, although it can also be set by each user. When files are created the argument of umask is used to turn off bits on 0666, which creates the file permissions.

So for example, one common umask in /etc/profile is:

umask 022

This is how it works. Octal 022 is 000 010 010 in binary. The default option for creating files is octal 666 or 110 110 110 in binary. Turning off those bits as set by umask leaves us with binary 110 100 100, which is octal 644 and corresponds to rw-r--r-- file permissions, the owner can read and write whereas group and others can only read.

A more restrictive umask may be 026, or binary 000 010 110, when 'masked' with 0666 we get 0640 which corresponds to file permissions rw-r-----. So, while group members may read the file, the rest of the world may not.

Be careful though, if you make a mistake with the umask value you can get some funny results. A umask of 024, gives you file permissions rw-r---w-. This means that although the author can read and write the file and the group members can read it. The rest of the world can write to it if they want. That's not normally what you

Tags: files



Leave a comment:

Are you human?