Linux permissions control who can access files and directories and what they can do with them. This system is based on three entities (User, Group, Other) and three permission types (Read, Write, Execute).
Changes the file owner and/or group
Syntax: chown [user][:group] [file/directory]
chown [user][:group] [file/directory]
-r option: Apply changes recursively (to directories and all contents)
-r
Examples:
chown clark file.txt - Changes only the owner
chown clark file.txt
chown clark:dev2 file.txt - Changes owner to clark AND group to dev2
chown clark:dev2 file.txt
chown -r clark:dev2 /directory/ - Changes owner/group recursively
chown -r clark:dev2 /directory/
Changes only the group ownership (leaves user owner unchanged)
Syntax: chgrp [groupname] [file/directory]
chgrp [groupname] [file/directory]
-r option: Apply changes recursively
Example: chgrp dev2 /tmp/ops_team
chgrp dev2 /tmp/ops_team
Changes permission bits (what users can do with the file)
Can use symbolic mode OR octal mode
Syntax: chmod [permissions] [file/directory]
chmod [permissions] [file/directory]
Linux divides permissions into three categories:
User (u): The owner of the file
Group (g): Users who are members of the file's group
Other (o): Everyone else (not owner, not in group)
Read (r)
Files: View/read file contents
Directories: List contents of directory
Symbolic: r
r
Octal: 4
4
Write (w)
Files: Modify/edit file contents
Directories: Create/delete files within directory
Symbolic: w
w
Octal: 2
2
Execute (x)
Files: Run file as a program/script
Directories: Enter directory (cd into it)
Symbolic: x
x
Octal: 1
1
Uses letters: r (read), w (write), x (execute)
Format: [who][operation][permission]
[who][operation][permission]
Who: u (user), g (group), o (other), a (all)
Operation: + (add), - (remove), = (set exactly)
Permission: r, w, x
chmod g+w file - Add write permission for group
chmod g+w file
chmod o-r file - Remove read permission for other
chmod o-r file
chmod u+x,g+x file - Add execute for user and group
chmod u+x,g+x file
Uses numbers 0-7 (sum of permission values)
Each permission has a value:
Read = 4
Write = 2
Execute = 1
No permission = 0
Calculate by adding values:
7 = rwx (4+2+1) - Full permissions
6 = rw- (4+2+0) - Read and write
5 = r-x (4+0+1) - Read and execute
4 = r-- (4+0+0) - Read only
3 = -wx (0+2+1) - Write and execute
2 = -w- (0+2+0) - Write only
1 = --x (0+0+1) - Execute only
0 = --- (0+0+0) - No permissions
Three digits represent: [User][Group][Other]
chmod 755 file - rwxr-xr-x (User: full, Group: read+execute, Other: read+execute)
chmod 755 file
chmod 644 file - rw-r--r-- (User: read+write, Group: read, Other: read)
chmod 644 file
chmod 600 file - rw------- (User: read+write, Group: none, Other: none)
chmod 600 file
chmod 777 file - rwxrwxrwx (Everyone: full permissions)
chmod 777 file
When you run ls -l, you see something like:
ls -l
-rw-r--r-- 1 barry ops 0 Jan 1 12:00 test1
drwxr-xr-x 2 barry ops 4096 Jan 1 12:00 ops_team
Breaking down -rw-r--r--:
-rw-r--r--
Position 1: File type
- = regular file
-
d = directory
d
l = symbolic link
l
Positions 2-4: User permissions (rw- = read, write, no execute)
Positions 5-7: Group permissions (r-- = read only)
Positions 8-10: Other permissions (r-- = read only)
This equals octal: 644
Breaking down drwxr-xr-x:
drwxr-xr-x
rwx = User has read, write, execute (7)
rwx
r-x = Group has read, execute (5)
r-x
r-x = Other has read, execute (5)
This equals octal: 755
Critical: Without execute (x) permission on a directory, you cannot cd into it
Even with read permission, you can't list contents without execute
Write permission allows creating/deleting files inside directory
Directories: Typically 755 (rwxr-xr-x)
Files: Typically 644 (rw-r--r--)
The -r flag applies changes to directory and ALL contents beneath it
Example: chown -r clark:dev2 /directory/ changes ownership of directory and everything inside
Only file owner or root can change permissions
Need sudo for changes if you don't own the file
Root can change ANY file's permissions/ownership
chmod o-r test2
# Result: -rw-r----- (640)
chmod 664 test1
# Result: -rw-rw-r-- (User: rw, Group: rw, Other: r)
chmod g+w,o-x ops_team
# Adds write to group, removes execute from other
chown -r clark:dev2 /tmp/ops_team
# Changes owner to clark and group to dev2 for directory and all contents
Three commands: chown (owner/group), chgrp (group only), chmod (permissions)
Three permission groups: User, Group, Other (UGO)
Three permission types: Read (4), Write (2), Execute (1)
Two notation systems: Symbolic (rwx) and Octal (0-7)
Permissions work differently on files vs directories
Execute on directories = ability to cd into them
Write on directories = ability to create/delete files inside
Use -r for recursive operations on directories
What are the three main commands for managing file permissions and ownership?
chown - Changes file owner and group
chown
chgrp - Changes only group ownership
chgrp
chmod - Changes file permission bits (what users can do)
chmod
Example: chown clark:dev file.txt, chgrp ops file.txt, chmod 755 file.txt
chown clark:dev file.txt
chgrp ops file.txt
chmod 755 file.txt
What are the three permission groups in Linux and what do they represent?
User (u) - The owner of the file
Group (g) - Users who are members of the file's group
Other (o) - Everyone else (not owner, not in group)
Together abbreviated as UGO. Every file has permissions for all three.
What are the three types of permissions and what do they allow?
Read (r) - View/read file contents; list directory contents
Write (w) - Modify files; create/delete files in directories
Execute (x) - Run files as programs; cd into directories
Key: Execute on directories allows you to enter them!
What are the octal (numeric) values for each permission type?
You add these values together:
7 = rwx (4+2+1)
6 = rw- (4+2)
5 = r-x (4+1)
4 = r-- (4)
How do you interpret the permission string -rw-r--r--?
Breaking it down:
- = Regular file (d would mean directory)
rw- = User has read+write (6)
rw-
r-- = Group has read only (4)
r--
r-- = Other has read only (4)
Octal representation: 644 Meaning: Owner can read/write, everyone else can only read
What does chmod 755 mean in terms of permissions?
chmod 755
7 (User) = rwx = read, write, execute (4+2+1)
5 (Group) = r-x = read, execute (4+1)
5 (Other) = r-x = read, execute (4+1)
Result: -rwxr-xr-x Common use: Default for directories - owner has full control, others can read and enter
-rwxr-xr-x
What does chmod 644 mean in terms of permissions?
chmod 644
6 (User) = rw- = read, write (4+2)
4 (Group) = r-- = read only (4)
4 (Other) = r-- = read only (4)
Result: -rw-r--r-- Common use: Default for files - owner can edit, others can only read
What is the difference between symbolic and octal mode in chmod?
Symbolic Mode: Uses letters (r, w, x) and operators (+, -, =)
Example: chmod g+w file (add write to group)
Example: chmod o-r file (remove read from other)
Octal Mode: Uses numbers 0-7
Example: chmod 755 file (set exact permissions)
Both change the same thing, just different notation!
How do you add write permission for the group using symbolic mode?
chmod g+w [filename]
g = group
+ = add permission
w = write
Example: chmod g+w test1 You can combine: chmod g+w,o-r test1 (add write to group, remove read from other)
chmod g+w test1
chmod g+w,o-r test1
How do you remove execute permission from others using symbolic mode?
chmod o-x [filename]
o = other (everyone else)
- = remove permission
x = execute
Example: chmod o-x ops_team/ Important for directories - prevents others from cd-ing into it!
chmod o-x ops_team/
What does the -r option do with chown, chgrp, and chmod?
The -r (recursive) option applies the change to:
The specified directory
ALL files and subdirectories inside it
chmod -r 755 /directory/ - Changes permissions recursively
chmod -r 755 /directory/
chown -r user:group /directory/ - Changes ownership recursively
chown -r user:group /directory/
chgrp -r groupname /directory/ - Changes group recursively
chgrp -r groupname /directory/
Critical for directories with many files!
What is the syntax for chown to change both owner and group?
chown [user]:[group] [file/directory]
Key: Use a colon (:) between user and group with NO SPACES
:
chown clark:dev2 file.txt - Changes owner to clark, group to dev2
chown clark file.txt - Changes only owner to clark
chown :dev2 file.txt - Changes only group to dev2
chown :dev2 file.txt
chown -r clark:dev2 /directory/ - Recursive change
What is the difference between chown and chgrp?
chown (Change Owner):
Can change both user owner AND group
Can change only user owner
Can change only group (with :group syntax)
:group
More versatile
chgrp (Change Group):
Changes only the group ownership
Simpler when you only need to change group
Cannot change user owner
Example: chgrp dev2 file.txt vs chown :dev2 file.txt (same result)
chgrp dev2 file.txt
Why is execute (x) permission important on directories?
Execute permission on directories controls whether you can:
cd (change directory) into it - Most important!
Access files inside (even if you have read permission on files)
Without execute: Cannot enter the directory or access contents Example: Directory with rw- (no x) = You can see it exists but cannot cd into it
Remember: Execute doesn't mean "run" for directories, it means "enter"!
What does write (w) permission allow on directories vs files?
On Files:
Modify/edit the file contents
Cannot delete the file itself (that's controlled by directory permissions)
On Directories:
Create new files inside
Delete files inside
Rename files inside
Key insight: To delete a file, you need write permission on the directory, not the file!
What does read (r) permission allow on directories vs files?
View/read the file contents
Example: cat file.txt
cat file.txt
List the contents (filenames)
See what files exist inside
Example: ls directory/
ls directory/
Important: Read alone isn't enough for directories - you also need execute (x) to access the contents!
If a file shows drwxr-xr-x, what does each part mean?
d = This is a directory (not a file)
rwx = User: read, write, execute (7) - full control
r-x = Group: read, execute (5) - can list and enter
r-x = Other: read, execute (5) - can list and enter
Octal: 755 Meaning: Owner can do everything, others can browse and enter but not modify
How do you calculate octal permissions from symbolic?
Add up the values for each group (User, Group, Other):
r (read) = 4
w (write) = 2
x (execute) = 1
rwx = 4+2+1 = 7
rw- = 4+2+0 = 6
r-x = 4+0+1 = 5
r-- = 4+0+0 = 4
--- = 0+0+0 = 0
---
So rwxr-xr-- = 754 (7,5,4)
rwxr-xr--
What permission number gives full access to everyone?
777 (or rwxrwxrwx)
777
rwxrwxrwx
User: rwx (7)
Group: rwx (7)
Other: rwx (7)
Command: chmod 777 file
Warning: Generally considered insecure! Gives everyone full control. Use with caution!
What permission number gives owner full access, but no access to anyone else?
700 (or rwx------)
700
rwx------
Group: --- (0)
Other: --- (0)
Command: chmod 700 file
chmod 700 file
Use case: Private files/directories only the owner should access
If you get "Permission denied" when trying to cd into a directory, what permission is missing?
cd
Execute (x) permission is missing for your permission group (user, group, or other).
Without execute on a directory, you cannot:
cd into it
Access files inside it (even if you have permissions on the files)
Solution: chmod +x directory/ or chmod 755 directory/
chmod +x directory/
chmod 755 directory/
What does chmod g+w,o-x ops_team do?
Makes TWO changes to ops_team directory:
g+w - Adds write permission for group
g+w
o-x - Removes execute permission from other
o-x
Result: Group can now create/delete files inside; Others can no longer cd into directory
Key: Multiple changes separated by commas, no spaces!
Can you delete a group that is the primary group of an existing user?
NO! You cannot delete a group if it's currently the primary group of any user.
Solution:
First delete the user (or change their primary group)
Then delete the group
Note: You CAN delete supplemental groups without issue
What command shows the current permissions of a file or directory?
ls -l [filename] or ls -ld [directory]
ls -l [filename]
ls -ld [directory]
ls -l - Long listing (shows permissions, owner, group)
ls -ld - Long listing for directory itself (not its contents)
ls -ld
Output example: -rw-r--r-- 1 barry ops 0 Jan 1 file.txt Shows: permissions, owner (barry), group (ops)
-rw-r--r-- 1 barry ops 0 Jan 1 file.txt
Who can change the permissions or ownership of a file?
The file owner - Can change permissions (chmod) but not ownership
Root user (superuser) - Can change ANYTHING (permissions and ownership)
Users with sudo privileges - Can use sudo to act as root
Regular user: chmod 644 myfile.txt (only if they own it)
chmod 644 myfile.txt
With sudo: sudo chown root:root anyfile.txt (can change any file)
sudo chown root:root anyfile.txt
What's the difference between chmod 644 file and chmod u=rw,g=r,o=r file?
chmod u=rw,g=r,o=r file
NO DIFFERENCE - They do the exact same thing!
chmod 644 file - Octal mode
6 = rw- (user)
4 = r-- (group)
4 = r-- (other)
chmod u=rw,g=r,o=r file - Symbolic mode
u=rw (user gets read+write)
g=r (group gets read)
o=r (other gets read)
Both result in: -rw-r--r--
What does the first character in a permission string indicate?
The file type:
- = Regular file
d = Directory
l = Symbolic link (shortcut)
c = Character device file
c
b = Block device file
b
-rw-r--r-- = Regular file
drwxr-xr-x = Directory
lrwxrwxrwx = Symbolic link
lrwxrwxrwx
How do you give a file read and execute permissions for everyone, but write only for owner?
Method 1 (Octal): chmod 755 file
7 (rwx) for user
5 (r-x) for group
5 (r-x) for other
Method 2 (Symbolic): chmod u=rwx,go=rx file
chmod u=rwx,go=rx file
u=rwx (user gets all)
go=rx (group and other get read+execute)
Result: -rwxr-xr-x
What is the typical default permission for newly created files and directories?
Files: Usually 644 (rw-r--r--)
rw-r--r--
Owner can read/write
Group and others can only read
Directories: Usually 755 (rwxr-xr-x)
rwxr-xr-x
Owner has full control
Group and others can read and enter
These defaults are controlled by the umask setting
If a file has 640 permissions, what does each group have access to?
640 breaks down to:
6 (User) = rw- = Read and write (4+2)
4 (Group) = r-- = Read only (4)
0 (Other) = --- = No permissions
String representation: -rw-r-----
-rw-r-----
Meaning: Owner can edit, group can view, others have no access
What happens if you try to modify a file you don't have write permission for?
You'll get a "read-only file" warning or "Permission denied" error.
In vim/text editors: Shows "[read-only]" and won't let you save changes With commands: Error message like "Permission denied"
Change permissions: chmod u+w file (if you own it)
chmod u+w file
Use sudo: sudo vim file (if you have sudo rights)
sudo vim file
Why would you use chown -r clark:dev2 /directory/ instead of just chown clark:dev2 /directory/?
chown clark:dev2 /directory/
Without -r: Only changes the directory itself With -r (recursive): Changes the directory AND everything inside it (all files and subdirectories)
Example scenario:
Directory has 100 files owned by barry:ops
chown -r clark:dev2 /directory/ changes ownership of all 100 files + the directory in one command
Without -r, you'd only change the directory, files stay owned by barry
Critical for mass ownership changes!
What symbolic chmod command adds execute permission for user and group, but not other?
chmod u+x,g+x file or chmod ug+x file
chmod ug+x file
u+x = Add execute for user
g+x = Add execute for group
Can combine as ug+x = Add execute for user AND group
Alternative: chmod +x file adds execute for EVERYONE (all three groups)
chmod +x file
What is the octal permission for a file that allows owner to read/write/execute, group to read/write, and others to read only?
764
Calculation:
User: rwx = 4+2+1 = 7
Group: rw- = 4+2+0 = 6
Other: r-- = 4+0+0 = 4
Command: chmod 764 file Result: -rwxrw-r--
chmod 764 file
-rwxrw-r--
What's the difference between chmod +x file and chmod u+x file?
chmod u+x file
chmod +x file: Adds execute for ALL (user, group, AND other)
Same as chmod a+x (a = all)
chmod a+x
chmod u+x file: Adds execute for user ONLY
Group and other permissions unchanged
Example:
Starting: -rw-r--r-- (644)
chmod +x: -rwxr-xr-x (755)
chmod +x
chmod u+x: -rwxr--r-- (744)
chmod u+x
-rwxr--r--
Zuletzt geändertvor einem Monat