Monday, May 13, 2013

LINUX File Permission


Permission Groups
Each file and directory has three user based permission groups:
  • owner - The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
  • group - The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
  • all users - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.
Permission Types
Each file or directory has three basic permission types:
  • read - The Read permission refers to a user's capability to read the contents of the file.
  • write - The Write permissions refer to a user's capability to write or modify a file or directory.
  • execute - The Execute permission affects a user's capability to execute a file or view the contents of a directory.

You can view the access permissions of a file by doing the long directory listing with the ls -l command


                 What does the output of ls -l mean? The very first column, the one that looks like a bunch of shows the file type and permissions. The second column shows the number of links (directory entries that refer to the file), the third one shows the owner of the file, and the fourth one shows the group the file belongs to. The other columns show the file's size in bytes, date and time of last modification, and the filename.
  

The first column is organized into four separate groups, although it certainly doesn't look very organized.

The first group consists of only one character and it can be any of these:



d = directory
- = regular file
l = symbolic link
s = Unix domain socket
p = named pipe
c = character device file
b = block device file



                         The next nine characters show the file's permissions, divided into three groups, each consisting of three characters. 



  • The first group of three characters shows the read, write, and execute permissions for user, the owner of the file.
  • The next group shows the read, write, and execute permissions for the group of the file.
  • Similarly, the last group of three characters shows the permissions for other, everyone else.

In each group, the first character means the read permission, the second one write permission, and the third one execute permission.


The characters are pretty easy to remember.
r = read permission
w = write permission
x = execute permission
- = no permission





 As you already noticed, dir is a directory, because the first column begins with a d.

The owner of this directory is user fabien and the group owner is users.

The first three characters, rwx, indicate the directory's owner, fabien in this case, has full access to the directory. The user fabien is able to access, view, and modify the files in that directory.

The next three characters, r-x, indicate that all users belonging to group users have read and execute permissions to the directory. They can change into the directory, execute files, and view its contents. However, because they don't have write permissions, they can't make any changes to the directory content.

Finally, the last three characters, r-x, indicate that all the users who are not fabien or don't belong into group users, have read and execute permissions in the directory.


How to set file permissions - numeric mode
       
                   You can set file permissions with the chmod command. Both the root user and the file's owner can set file permissions. Chmod
                    In the numeric mode, the file permissions aren't represented by characters. Instead, they are represented by a three-digit octal number.

4 = read (r)
2 = write (w)
1 = execute (x)
0 = no permission (-)



Let's have an example.


The highlight line you can see the file have full access to the owner,group and others.

when command # chmod 754 test1 entered 

The permission has been changed and now the owner have ull read, write, and execute permissions (4+2+1 = 7 ) ----- 7

The group would have read and execute permissions (4+0+1=5) -----5

The others would have only read permissions as well(4+0+0=4) -----4


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

No comments:

Post a Comment