Skip to main content

Posts

Showing posts from August, 2015

Sticky Bit with example

Sticky Bit is used on folders in to avoid deletion of its content by users who are in same group with the owner of the file. Before understanding the sticky bit, I recommend reading SGID post which explains its disadvantage. From SGID we understood that the user E1 can delete the file of E2 and vice versa. So to avoid this, we use sticky bit. Command To set: chmod o+t <dir> To unset: chmod o-t <dir> eg: # chmod o+t /project/ # ls -ld /project/ drwxrws--T . 2 root teamA 84 Aug 31 09:03 /project/ You will notice T in others permission. Now the user E1 cannot delete file of E2 and E2 cannot delete of E1. Below example shows E1 user trying to delete file of E2 but sticky bit didnt allow the file to get deleted. $ rm e2_file.txt rm: remove write-protected regular empty file ‘e2_file.txt’? y rm: cannot remove ‘e2_file.txt’: Operation not permitted  

SGID with example

SGID is Set Group ID. When SGID is used? Eg: You are manger of teamA and teamA has 2 engineers E1, E2.  You will be assigning a project to teamA so that all two engineers should work on this project. You will create a folder /project. teamA group is created and E1,E2 users are assigned to the group. You will set group permission of the folder as below. ls -ld /project drwxrwx---. 2 root teamA 6 Aug 31 08:39 /project Now E1,E2 can create files inside the project folder as shown below. -rw-rw-r--. 1 E1 E1 0 Aug 31 08:45 e1_file.txt -- > file created by E1 user -rw-rw-r--. 1 E2 E2 0 Aug 31 08:46 e2_file.txt --> file created by E2 user. Here the problem is E2 cannot edit or change E1 file and vice versa since the file permission for group is assigned of the user. To fix this, the group permission of the files should be changed to teamA. In other words, when file gets created permission from the project folder should be automatically assigned to files inside th

SUID with example

SUID is Set owner User ID. When SUID is used? Eg: You are a Super administator and can run commands like "fdisk -l" from root user. But what if in your absence, you want this command to run by a normal user. "fdisk -l" will not give any output when run with normal user account. One option is to give sudors permission to the normal user and then user can run the command. But there is risk in this. Sudoers will allow normal user to run all the root commands. To prevent this and allow the normal user to run only one command, SUID is used. After setting SUID for /sbin/fdisk, then normal user will be get the result for "fdisk -l" SUID info: Permission Number : 4 To set SUID: # chmod u+s <filename> To remove SUID: # chmod u-s <filename> Eg: Before permission of /sbin/fdisk ls -l /sbin/fdisk - rwxr-xr-x 1 root root 267176 Aug  5 06:55 /sbin/fdisk Setting SUID for /sbin/fdisk #chmod u+s /sbin/fdisk Now permission of /sbi