SlideShare a Scribd company logo
Advanced File Permissions in Linux
Here we will discuss about the 3 special attributes other than the common read/write/execute.
Example:
drwxrwxrwt - Sticky Bits - chmod 1777
drwsrwxrwx - SUID set - chmod 4777
drwxrwsrwx - SGID set - chmod 2777
Sticky bit
Sticky bits are mainly set on directories.
If the sticky bit is set for a directory, only the owner of that directory or the owner of a file can delete or rename
a file within that directory.
Example:
Consider you have a directory " test ".
chmod it to " 777 ". This gives permissions for all the users to read, write and execute.
chmod +t test
Example: ls -al
drwxrwxrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 a1 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 b2 b2 0 Jun 11 22:52 2.txt
From the above example a1 is the owner of the test directory.
a1 can delete or rename the files 1.txt and 2.txt.
b2 can delete or rename the file 2.txt only.
SUID - [ Set User ID ]
SUID bit is set for files ( mainly for scripts ).
The SUID permission makes a script to run as the user who is the owner of the script, rather than the user who
started it.
Example:
If a1 is the owner of the script and b2 tries to run the same script, the script runs with the ownership of a1.
If the root user wants to give permissions for some scripts to run by different users, he can set the SUID bit for that
particular script.
So if any user on the system starts that script, it will run under the root ownership.
Note:
root user much be very carefull with this.
SGID - [ Set Group ID ]
If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person
running the program.
This permission set also can make a similar impact. Here the script runs under the groups ownership.
You can also set SGID for directories.
Consider you have given 2777 permission for a directory. Any files created by any users under this directory will
come as follows.
Example:
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
In the above example you can see that the owner of the file 1.txt is b2 and the group owner is a1.
So both b2 and a1 will have access to the file 1.txt.
Now lets make this more intresting and complicated.
Create a directory "test". Chmod it to 2777. Add sticky bit to it.
Example:
mkdir test
chmod 2777 test
chmod +t test
ls -al test
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 test
From the above permission set you can understand that SGID and sticky bit is set for the folder "test".
Now any user can create files under the test directory.
Example:
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 c3 a1 0 Jun 11 17:30 2.txt
-rw-rw-r-- 1 d4 a1 0 Jun 11 17:30 3.txt
So all the a1 user has access to all the files under the test directory. He can edit, rename or remove the file.
b2 user has access to 1.txt only, c3 has access to 2.txt only...
If sticky bit was not set for the test directory, any user can delete any files from the test directory, since the test
directory has 777 permissions.
But now it not possible.
Example:
If d4 tries to remove 1.txt
rm -f 1.txt
rm: cannot remove `1.txt': Operation not permitted

More Related Content

PPTX
File permission in linux
PDF
Linux Performance Profiling and Monitoring
PPT
Storage Management in Linux OS.ppt
PPTX
File permissions
PPT
Unix/Linux Basic Commands and Shell Script
PPTX
Access control list acl - permissions in linux
DOCX
Linux crontab
PDF
BPF: Tracing and more
File permission in linux
Linux Performance Profiling and Monitoring
Storage Management in Linux OS.ppt
File permissions
Unix/Linux Basic Commands and Shell Script
Access control list acl - permissions in linux
Linux crontab
BPF: Tracing and more

What's hot (20)

PPTX
Filepermissions in linux
PDF
File permission of linux
PDF
Course 102: Lecture 14: Users and Permissions
PDF
Shell scripting
PPTX
Iptables the Linux Firewall
PPTX
Github basics
PPTX
Linux basic commands
PPTX
Job Automation using Linux
PPTX
Backup using rsync
PPTX
Maria db 이중화구성_고민하기
PDF
Users and groups in Linux
PDF
LinuxCon 2015 Linux Kernel Networking Walkthrough
PDF
Linux Char Device Driver
PDF
Git real slides
PPT
Compression Commands in Linux
PPTX
Linux User Management
PDF
rsyncやシェルでバックアップするよりも簡単にOSSのBaculaでバックアップしてみよう
PPTX
Swap Administration in linux platform
ODP
Monitoring IO performance with iostat and pt-diskstats
PDF
netfilter and iptables
Filepermissions in linux
File permission of linux
Course 102: Lecture 14: Users and Permissions
Shell scripting
Iptables the Linux Firewall
Github basics
Linux basic commands
Job Automation using Linux
Backup using rsync
Maria db 이중화구성_고민하기
Users and groups in Linux
LinuxCon 2015 Linux Kernel Networking Walkthrough
Linux Char Device Driver
Git real slides
Compression Commands in Linux
Linux User Management
rsyncやシェルでバックアップするよりも簡単にOSSのBaculaでバックアップしてみよう
Swap Administration in linux platform
Monitoring IO performance with iostat and pt-diskstats
netfilter and iptables
Ad

Similar to Advanced file permissions in linux (20)

PDF
Sticky bit suid sgid
PPT
Basic Linux
PPT
Lession1 Linux Preview
PDF
Linux Security
PPTX
File permission in Linux
PDF
Special permission in linux.
PDF
Solaris basics
PDF
manage-directory-permissions-for-collaboration-slides.pdf
PDF
4_Users_and_File_Permission_and_Directory_Commands
PDF
Linux Commands CheatSheet - PDF.pdf for engineer
PDF
Command Line Tools
PPT
4.5 manage file permissions and ownership v3
PPT
101 4.5 manage file permissions and ownership v3
PPT
UNIX -File attributes and permissions; The Security Implications
PPTX
Introduction to linux day-3
PPTX
Linux Presentation
PPT
Unix Basics 04sp
DOC
Restricting unix users
PPTX
Linux day 2.ppt
Sticky bit suid sgid
Basic Linux
Lession1 Linux Preview
Linux Security
File permission in Linux
Special permission in linux.
Solaris basics
manage-directory-permissions-for-collaboration-slides.pdf
4_Users_and_File_Permission_and_Directory_Commands
Linux Commands CheatSheet - PDF.pdf for engineer
Command Line Tools
4.5 manage file permissions and ownership v3
101 4.5 manage file permissions and ownership v3
UNIX -File attributes and permissions; The Security Implications
Introduction to linux day-3
Linux Presentation
Unix Basics 04sp
Restricting unix users
Linux day 2.ppt
Ad

Advanced file permissions in linux

  • 1. Advanced File Permissions in Linux Here we will discuss about the 3 special attributes other than the common read/write/execute. Example: drwxrwxrwt - Sticky Bits - chmod 1777 drwsrwxrwx - SUID set - chmod 4777 drwxrwsrwx - SGID set - chmod 2777 Sticky bit Sticky bits are mainly set on directories. If the sticky bit is set for a directory, only the owner of that directory or the owner of a file can delete or rename a file within that directory. Example: Consider you have a directory " test ". chmod it to " 777 ". This gives permissions for all the users to read, write and execute. chmod +t test Example: ls -al drwxrwxrwt 2 a1 a1 4096 Jun 13 2008 . -rw-rw-r-- 1 a1 a1 0 Jun 11 17:30 1.txt -rw-rw-r-- 1 b2 b2 0 Jun 11 22:52 2.txt From the above example a1 is the owner of the test directory. a1 can delete or rename the files 1.txt and 2.txt. b2 can delete or rename the file 2.txt only. SUID - [ Set User ID ] SUID bit is set for files ( mainly for scripts ). The SUID permission makes a script to run as the user who is the owner of the script, rather than the user who started it. Example: If a1 is the owner of the script and b2 tries to run the same script, the script runs with the ownership of a1.
  • 2. If the root user wants to give permissions for some scripts to run by different users, he can set the SUID bit for that particular script. So if any user on the system starts that script, it will run under the root ownership. Note: root user much be very carefull with this. SGID - [ Set Group ID ] If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person running the program. This permission set also can make a similar impact. Here the script runs under the groups ownership. You can also set SGID for directories. Consider you have given 2777 permission for a directory. Any files created by any users under this directory will come as follows. Example: -rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt In the above example you can see that the owner of the file 1.txt is b2 and the group owner is a1. So both b2 and a1 will have access to the file 1.txt. Now lets make this more intresting and complicated. Create a directory "test". Chmod it to 2777. Add sticky bit to it. Example: mkdir test chmod 2777 test chmod +t test ls -al test drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 test From the above permission set you can understand that SGID and sticky bit is set for the folder "test". Now any user can create files under the test directory. Example: drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 . -rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
  • 3. -rw-rw-r-- 1 c3 a1 0 Jun 11 17:30 2.txt -rw-rw-r-- 1 d4 a1 0 Jun 11 17:30 3.txt So all the a1 user has access to all the files under the test directory. He can edit, rename or remove the file. b2 user has access to 1.txt only, c3 has access to 2.txt only... If sticky bit was not set for the test directory, any user can delete any files from the test directory, since the test directory has 777 permissions. But now it not possible. Example: If d4 tries to remove 1.txt rm -f 1.txt rm: cannot remove `1.txt': Operation not permitted