Permissions and umask

by

you might have found that sometimes you can’t -for example- copy (or write) files into X directory when you’re using your user

but at the same time you can copy files into the same X directory using the “root” user

so how do i get the permission for writing in X using any user … not root only!!

well …

have you ever wrote “ls -l” command???

if you’ve done so, have you noticed the first column of the output?!

it may look like this:

-rwxrwxrwx

1) the first () represent the file type, so if it’s like that () you’ll know that this is a file

and if it is (d), it’s a Directory

and (l) stands for Link

there are more letters but these are the most important ones

2) then the next 9 letters represent 3 partitions, they are: OWNER (u), GROUP (g), OTHER (o) respectively

each of them consists of 3 letters: rwx

r=read (access to read files)

w=write (access to write into files)

x=execute (access to run files)

let me give a simple example for using permissions:

suppose that “boody“, “3abed“, “didooofidooo” are members in a group named “group1

and “Hunikal” & “noor” are in “group2

boody” created a file, then he found that the permission is -rw-rw-r–

ok what does this actually mean?!

1) this means that this is a normal file (this is why () is there)

2) and the owner of the file (boody) can read the file and also write into it

3) and the owner’s group (group1) can also read and write into the file, this means that “3abed” and “didooofidooo” can also read-write into this file, as they’re in the same group (group1)

3)then we’ll find that “Hunikal” and “noor” can only read the file but not write into it, as they are not the “OWNER” or in the “owner’s GROUP”, so they are from “OTHERS”

Changing Permissions

there are two ways for changing permissions

both can be done using “chmod” command

1)Char Method

if you want to change the permission of a file named “Perm” from -rwxr-xr-x to -rw-rw-r-x

we can see that we only have to change the owner’s permission (u) from rwx to rw- so we’ll use the following command

#chmod u-x Perm

then change the group’s permission (g) from r-x to rw- so we’ll use the follwing command

#chmod g-w+x Perm

actually we could change this in only one command

#chmod u-x,g-w+x Perm

2)Numeric Method

we have three primary numbers:

4, 2 and 1

4 adds r permission (read permission)

2 adds w permission (write permission)

1 adds x permission (execute permission)

so you can change a file’s permission from -rwxr-xr-x to -rw-rw-r-x using the following command

#chmod 665 file_name

6=4+2=rw-

5=4+1=r-x

so we can give a -rwxrwxrwx permission using the following command

#chmod 777 file_name

umask

from wikipedia:

umask (abbreviated from user mask) is a command and a function in POSIX environments which set the default permission modes for newly created files and directories of the current process

you can know your umask using “umask” command:

#umask

the most important thing you need to know about umask is that:

permission = 777 – umask

so if your umask equals 0022, your files’ permissions will be 777-022=755

and this means when you create a file you’ll find the file’s permission is -rwxr-xr-x (755)

changing umask

you can change the umask (for example: to 023) using “umask” command:

#umask 023

but when you restart your computer, you’ll find that the umask returned to it’s old value

so we have to edit /etc/bashrc file

#vi /etc/bashrc

and change the umask value then save the file

————————————————————-

that’s all

thanQ

bye

Advertisements

2 Responses to “Permissions and umask”

  1. erotyka Says:

    This blog was… how do I say it? Relevant!! Finally I have found something that helped me.

    Thank you!

  2. ruchanie Says:

    I think that what you published was actually very reasonable.

    But, what about this? suppose you added a little information?
    I ain’t suggesting your information is not solid., but what if you added something that makes people want more? I mean Permissions and umask | OsFreaks is a little vanilla. You should peek at Yahoo’s home page
    and see how they create post titles to grab viewers to
    open the links. You might try adding a video or a pic or two to get readers excited about everything’ve written. In my opinion, it might make your posts a little livelier.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: