File Permissions

File Permissions

 

Describe File Permissions in linux ?

File permissions are assigned to:

  1. the owner of a file
  2. the members of the group the file is assigned to
  3. all other users
  4. Permissions under Linux are configured for each file and directory.

 

There are three levels of permissions:

  1. The permissions that apply to the owner of the file. The owner of a

file is by default the user that created the file1.

  1. The permissions that apply to all members of the group that is

associated with the file.

  1. The permissions that apply to all other users on the system.
  2. Permissions can only be changed by the owner, and root of course.

 

For a file, these permissions mean the following:

Read – allow the user to read the contents of the file, for instance

with cat or less.

Write – allow the user to modify the contents of the file,for instance

with vi.

Execute –  allow the user to execute the file as a program, provided that

the file is indeed an executable program (such as a shell script).

 

For a directory, these permissions have a slightly different meaning:

Read – allow the user to view the contents of the directory, for

instance with ls.

Write – allow the user to modify the contents of the directory. In other

words: allow the user to create and delete files, and to modify the names

of the files. Note: Having write permissions on a directory thus allows

you to delete files, even if you have no write permissions on that file!

execute  –  allow the user to use this directory as its current working

directory. In other words: allow the user to cd into it.

 

r – read

w – write

x – execute

 

u -> for owner (user) of the file

g -> for group assigned to the file

o -> for other users

a -> for (owner+group+others)

 

  • + to add permissions
  • – to delete permissions
  • = to clear all permissions and set to the permissions specified

For Example

Symbolic way

$ useradd ram

$ passwd ram

$ useradd shyam

$ passwd shyam

$ groupadd market;usermod –G market shyam

$ useradd kiran

$ passwd kiran

$ groupadd market;usermod –G market kiran

$ mkdir /opt/perm/;touch /opt/perm/file{1..6}

$ mkdir /opt/perm/{data1,data2}

$ cd /opt/perm

$ ll –d data1

drwxr-xr-x 2 root root 4096 Jul 29 20:15 data1

$ chown ram data1

$ ll –d data1

$ chgrp market data1

$ ll –d data1

$ chmod u-w data1

$ ll –d data1

$ chmod g+w data1

$ ll –d data1

$ chmod o+w,o-rx data1

$ ll –d data1

$ ll –d data2

drwxr-xr-x 2 root root 4096 Jul 29 20:15 data2

$ chown –Rv ram.market data2

$ ll –d data2

$ chmod u-rwx data2

$ ll –d data2

$ chmod g+w,g-x data2

$ ll –d data2

$ chmod –Rv o+w,o-r data2

$ ll –d data2

Octal way

$ ll file1

-rw-r–r—- 1 root root 0 Jul 29 20:15 file1

$ chmod 777 file1

$ ll file1

$ chmod 666 file2

$ ll file1

$ chmod 467 file3

$ ll file1

$ chmod 541 file4

$ ll file1

$ chmod 724 file5

$ ll file1

$ chmod 000 file6

$ chmod 0 file6

 

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s