LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-08-2013, 11:15 PM   #1
amanpreet
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Rep: Reputation: Disabled
Understanding Files and Directories Permissions in Linux.


When we create any file or directory in Linux it has by default permissions, file 644 and for directory 755. These are the by default permissions and we can also modify these permissions as per our requirements. Very frequently an interviewer also ask questions about the files and directories permissions. Because its concerned with security of files and directories and server. If we will discuss about the file permissions then there are different type of permissions like default permissions and special permissions. Special permissions mostly known as StickyBit , SUID & SGID Bits. We can see default permissions of files and directories in directory listing command as below

Code:
ll
or
Code:
ls -l
and output will be as below
Code:
-rw-r--r--.  1  root  root     0  Jun  28  18:06  file
drwxr-xr-x.  2  root  root  4096  May  23  20:01  jk2d
Here the first digit indicates that its a file or directory if its file then first field will '-' and if directory then 'd'.

Four symbols are used when displaying permissions

r: Permissions to read a file and list the content of a directory.
w: Permissions to write a file or create and remove files from directory.
x: Permissions to execute a program or change into a directory and do long listing of directory.
-: No permissions.

Permissions display in three digits mode as

For a file: rw- r-- r--
For a direcory: rwx r-x r-x

The first three digits set specifies owner's permissions.
Second three digits set specifies group permissions.
Third three digits set specifies other's permissions.

To change all permissions on a file at once, it is often easier and quicker to use the numeric method and we uses chmod command to change permissions. Numeric permissions are calculated as below

4: for read
2: for write
1: for execute

So the full permissions are 7 for a user if we will set full permissions for all owner, group and others then these will be 777 and it will look like as below

Code:
drwxrwxrwx. 1 root root    0 Jun 28 18:06 dir
These are the basic file permissions but if we will discuss about the special permissions StickyBit , SUID & SGID then file permissions will displays as

SUID or Set User ID

Code:
-rwsr--r--. 1 root root    0 Jun 28 18:06 file
The ‘s’ in user feild, in place of ‘x’ indicates that SUID bit is set.

SGID or Set Group ID

Code:
-rwxr-sr--. 1 root root    0 Jun 28 18:06 file
The ‘s’ in group, in place of ‘x’ indicates that SGID bit is set.

Sticky Bit

Code:
drwxrwxrwt 4 root root 4096 Aug 19 02:29 /tmp/
For more details of special permissions you should read in brief or go through examples of StickyBit , SUID & GUID to differentiate.

Last edited by amanpreet; 07-10-2013 at 09:32 PM.
 
Old 07-09-2013, 12:41 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 627

Rep: Reputation: 137Reputation: 137
Good... Thanks for sharing with all Linux users.
Why don't you add this in your blog entry? It will be visible there forever.
Here it will be crushed down by the uncountable number of threads.
 
Old 07-09-2013, 12:50 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Nice.

There's a typo in "StickBit" for "Sticky Bit". The linked page's title also has StickBit -- and "GUID Bit" for SGID bit. In the body of the text the linked page correctly uses "Sticky Bit" and SGID.

For completeness the meaning of S and T is sticky bit set and the execute bit not set.
 
Old 07-09-2013, 08:59 PM   #4
amanpreet
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks Eklavya and Catkin, I have corrected the typo.


Quote:
Originally Posted by catkin View Post
Nice.

There's a typo in "StickBit" for "Sticky Bit". The linked page's title also has StickBit -- and "GUID Bit" for SGID bit. In the body of the text the linked page correctly uses "Sticky Bit" and SGID.

For completeness the meaning of S and T is sticky bit set and the execute bit not set.
 
  


Reply

Tags
permissions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ACLs, default permissions, directories and files hydraMax Linux - Security 11 01-12-2011 06:19 AM
OpenSolaris and permissions on sensitive files / directories uncle-c Solaris / OpenSolaris 1 03-22-2009 10:20 AM
Search for files only in directories you have sufficient permissions tepez Linux - Software 1 04-08-2007 10:07 AM
user permissions to create files and directories ringding Linux - Security 3 09-07-2006 04:34 PM
How do I change permissions of files/directories? Okashira Linux - Newbie 5 01-12-2004 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration