Linux Permissions
Linux Permissions
Permissions : Read, Write, Execute
r (Read) Permission:
with r permission user can:
- View the content of a file
- List the contents of a directory
w (Write) Permission:
with w permission user can:
- Modify a file
- Create, rename, delete file or dir within a directory
x (Execute) permission:
with x permission user can :
- Execute a file as script
- Can enter in a directory
Permission Category : User, Group, Others
u for User
The files owner
g for Group
The group associated with the file or
o for Others
Everyone Else on the planet.
Interpreting Permission String
When you list files with ls -l, you’ll see something like this:
-rwxr-xr-- 1 alice developers 4096 Apr 4 14:00 script.sh
Let’s dissect it:
-– Regular file (other values includedfor directory,lfor symbolic link, etc.)rwx– Owner (alice) has read, write, and execute permissionsr-x– Group (developers) has read and execute permissionsr--– Others can only read the file1– Number of hard linksalice– Ownerdevelopers– Group4096– File size in bytesApr 4 14:00– Last modification datescript.sh– File name
File Ownership : User & Group
Files in linux associated with a
- an owner of the file
- a group _By default:
- Who (user) create a file is the owner of the file
- The file is assigned to the primary group of the user (who created the file)
Changing Permissions
Linux has a command for changing permissions & it is chmod.
Symbolic Mode
Uses Symbols (letter & symbols) as permissions & permission Category
Permissions
r: readw: writex: Execute
Permission Category
u: userg: groupo: Othersa: All
Permission Operator
+: Add Permission-: Remove Permission=: Assign Exact Permission
Numeric Mode
This mode uses octal values to represent permission bits:
| Permission | Octal | Binary | Description |
|---|---|---|---|
--- | 0 | 000 | No Permissions |
--x | 1 | 001 | Execute Only |
--w | 2 | 010 | Write Only |
-wx | 3 | 011 | Write & Execute |
r-- | 4 | 100 | Read Only |
r-x | 5 | 101 | Read & Execute |
rw- | 6 | 110 | Read & Write |
rwx | 7 | 111 | Read, Write & Execute |
You sum these for each category:
7=rwx6=rw-5=r-x4=r--
Commands
chmod ugo+rwx filename
chmod 777 filenameChanging Ownership & Group
Using chown & chgrp
Ownership
Changing ownership
chown newuser filenameGroup
Changing Group
chgrp newgroup filename Ownership & Group
Changing both ownership & group
chown newuser:newgroup filenameLast updated on
