Types of Permissions

TYPES OF PERMISSIONS

Depending upon owner, group and others, a file or folder can have three types of permission, namely –READ (r or 4) , WRITE (w or 2) and EXECUTE (x or 1).

Interpretation of permissions for files

Permission
read

(User can look at the contents of the file

User can create new files and remove existing files in the directory

write

User can modify the contents of the file

User can create new files and remove existing files in the directory

Execute

User can change into the directory, but cannot list the files unless (s)he has read permission. User can read files if (s)he has read permission on them.

 

Note :

For folders the concept of read and write is slightly different.

Use this command $ls –l filename

Understanding and Using File Permissions

Type and

Permission field

Links

Of

file

Files's

Owner

File's

Group

Size in bytes Date of

last

modification

Filename
drwxrwxrwx 4 george team1 122 Dec 25 11:02 Projects

 

If the owner read & execute bit are on, then the permissions are:

-r-x------

There are three types of access restrictions:

Permission Action chmod option
read (view) r or 4
write (edit) w or 2
execute (execute) x or 1

 

There are also three types of user restrictions:

User ls output
owner -rwx------
group ----rwx---
other -------rwx

 

(1st letter + 9= 3*3 letters representing the permissions of owner, his group and other anonymous above in order)

1st letter significance: -

  • d = directory
  • l = symbolic link
  • s = socket
  • p = named pipe
  • - = regular file
  • c= character (unbuffered) device file special
  • b=block (buffered) device file special

 

Another way of representing permission is by the use of numbers 0-7

As mentioned earlier we know that numerical value for read write and execute are “Read :: 4 ,Write :: 2 , Execute ::1”.

Thus to give any particular permission we simply add the values corresponding to each permission.

For instance a permission of 5 refers to 4+1 i.e. Read +Execute

Number Permission
0 ---
1 --x
2 -w-
3 -wx
4 r--
5 r-x
6 rw-
7 rwx

 

Thus to specify a full set of permissions we use a triplet , with one digit for each use

For instance 741 implies 7 for owner , 4 for group members and 1 for others

Thus to specify a full set of permission we use a triplet , with one digit for each user.

Changing Permissions of file/directory

chmod command

To change the permissions of a file use chmod command

Syntax:

$chmod new_permissons filename

Example:

$chmod 741 [filename]

Another way of using chmod

To change the permissions for only a specific type of user we use the following syntax

Syntax

$chmod who=permissions filename

This gives “who” the specified permissions for a given filename.

Who

The “who” is a list of letters that specifies whom are you going to give permissions to. Permissions can be specified in any order.

Letter Meaning
u owner
g group
o others
a all

Example:

$chmod +rx [filename]

# this gives everyone read execute permission

$chmod u+rx [filename]

# this give owner read + execute permission

$chmod–r-x------ [filename]

Changing file owner or group: chown, chgrp

You can change the owner and group of the file, by using the commands "chown" and "chgrp" respectively. "chown" allows you to change the owner of the file, and "chgrp" allows you to change its group category.

For instance, if George decides to give ownership of myfile to Robert, he can simply type:

$chown robert myfile

Also, if Robert later on decides to make the file only available to members of the group "SeniorAdmin" group rather than to those of the group "Administrators", he can type:

$chgrp senioradmin myfile