RSS

Permission in Linux

30 Dec

Linux is the operation system that is multitasking and multiusers. System allows many users that login and using. Two things : permission for own file, data in partition and sharing system resources such as memory, CPU, RAM. Question is how to grant permission for these users

Files and folders in Linux have own and permission and change information. Permission allows us permit using, type of file. Type command to see it in folder:

$ ls -la

clip_image001

 

Linux have four type of own:

Type

Symbol

The owner

u

The group owner

g

Other users or everyone else

O

All

A

 

Three type of permission:

Type

Symbol

Code

Detail

Read permission

r

4

Allow view info of file. With folders, it allows user move in there and show info

Write permission

w

2

Allow change info and remove files. With folders, With folders, it allows create, remove, rename the files in there and don’t depend permission of that files.

Execute permission

x

1

Allow users load app on memory and run it. User just only run command cd if have execute permission

 

Structure of permission string:

Example: -rw-r–r– or drwxr-x–x

String splits 10 octets:

The first

Type of file

Octet 2,3,4

Permission for Owner

Octet 5,6,7

Permission for Grouper

Octet 8,9,10

Permission for other users

 

In the first octet, it explained for type of file. If it’s "-" that is file, "d" that is directory.

Three octets for the users. It list permission for that users.

 

Summary:

Structure

Type of file

Read

Write

Exec

Read

Write

Exec

Read

Write

Exec

 

Commands for grant permission:

CHMOD:

Grant permission for files and folders. Just the owner and superuser have run command for that files and folders.

Syntax:

$ chmod [user or group] [action] [permission] <file/folder>

User

Action

Permission

u – user

+ : adding

r : read

g – group

    • : removing

w :write

o – others

= : setting

x : execute

a – all

   

 

Beside, we have special for folder. It’s permission that all users do anything but don’t remove file in folders. Just owner do that thing. Doing it, we need turn on sticky bit.

Syntax:

$ chmod 1???????? myfile

 

Sticky bit

permission

1

don’t allow other user delete file

    • or null

allow other user delete file

 

Example:

Adding write permission for group :

$ chmod g+w myfile

Removing read permission for group and others :

$ chmod go+w myfile

Permission

Command

-wrxr-xr-x

$ chmod 755 myfile

-r-xr–r —

$ chmod 522 myfile

-rwxrwxrwx

$ chmod 777 myfile

 

CHOWN:

CHOWN is short string change owner. to change owner of file

Syntax:

$ chown [user:group] <file>

We can adding option -R (recuisive) to change all file and subdirectories.

Example:

Change ower to root and keep grouper :

$ chown root: myfile

Change owner to root and grouper to root :

$ chown root:root myfile

Change owner to root and grouper to root  and subdirectories:

$ chown -R root:root myfolder

written by hotdream1990

 
 

Tags:

One response to “Permission in Linux

  1. 泳鏡

    January 14, 2011 at 8:02 pm

    It is certainly a lovely post. An information something like this demonstrates just how steeply the concept is actually thought of by creator.

     

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