Introduction
This lesson is about who can read, write, or execute files.
The main question is:
How does Linux decide which user can do what with a file or directory?
What you should be able to do after this lesson:
- Read normal permission strings.
- Use
chmod,chown, andchgrp. - Understand
umask. - Recognize
suid,sgid, and the sticky bit.
Note About Lesson Numbering
This lesson starts at 104.5 on purpose.
Reminder: objective 104.4 was removed from the current LPIC-1 Objectives V5.0, so there is no missing lesson file between 104.3 and 104.5.
The Basic Permission Model
Linux permissions are usually described for:
- owner
- group
- others
Each can have:
r= readw= writex= execute
Example:
-rwxr-xr--
Read it as:
- owner:
rwx - group:
r-x - others:
r--
Files vs Directories
Permissions mean slightly different things on directories.
On files
r= read file contentw= change file contentx= execute file as a program/script
On directories
r= list names insidew= create/delete/rename entriesx= enter the directory and access items by name
chmod
Symbolic mode
chmod u+x script.sh
chmod g-w shared.txt
chmod o-r private.txt
Numeric mode
chmod 644 file.txt
chmod 755 script.sh
Sanitized example output from ls -l before and after chmod:
-rw-r--r-- 1 <user> <group> 0 Mar 23 22:53 /tmp/lpic-perm-XXXXXX/file.txt
-rwxr-xr-x 1 <user> <group> 0 Mar 23 22:53 /tmp/lpic-perm-XXXXXX/file.txt
What this shows:
644gives read/write to owner and read-only to others755adds execute permission and is common for scripts
Common beginner meanings:
644= owner can read/write, others read only755= owner full, others read and execute
Ownership
Change owner
sudo chown alice file.txt
Change owner and group
sudo chown alice:devs file.txt
Change group only
chgrp devs file.txt
umask
umask affects default permissions for new files and directories.
Check it:
umask
Example output:
0022
What this shows:
0022is a common default umask- it removes write permission for group and others from default creation modes
Simple idea:
umaskremoves permission bits from defaults
Special Modes
suid
File runs with the file owner's effective privileges.
sgid
On files, similar special execution behavior. On directories, new files often inherit the directory group.
sticky bit
Common on shared directories such as /tmp.
It helps stop users from deleting each other's files there.
What the special bits look like
You may see these in permission strings:
sin the execute field for suid or sgidtin the execute field for the sticky bit
This is useful when reading ls -l output in the exam.
Practice Step by Step
1) Make a script executable
- Run:
chmod 755 script.sh - Or symbolically:
chmod u+x script.sh
2) Give a group access to a shared file
- Change group:
chgrp devs notes.txt - Allow group write:
chmod g+w notes.txt
Cheat Sheet
- owner, group, others = three permission scopes
r,w,x= read, write, executechmod= change modechown= change ownerchgrp= change groupumask= default permission mask644= common regular file mode755= common executable modesuid,sgid, sticky bit = special modes to recognize
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
