LAB-SEC-04 - Hardening with chattr
SEC Security & Firewalls
Hardening with chattr
Use chattr and lsattr on disposable files so you understand immutable and append-only attributes without risking important data.
20 min INTERMEDIATE LINUX Curriculum-reviewed
Prerequisites
Success criteria
- Use chattr and lsattr on disposable files so you understand immutable and append-only attributes without risking important data.
- Repeat the workflow without copy-paste or step-by-step prompting.
Safety notes
- Practice only on disposable files or folders. Immutable attributes can interfere with real updates and edits if used carelessly.
Part A: The Field Guide
What This Lab Is Really About
This lab introduces filesystem attributes that go beyond normal read and write permissions.
The goal is not to make everything immutable. The goal is to understand:
- what the immutable flag does
- how to verify it
- how to remove it before legitimate maintenance
Practice on disposable files only.
Command Reference
sudo chattr +i important_config.txt lsattr important_config.txt sudo chattr -i important_config.txt
Part B: The Drill Deck
Terminal required: use a disposable file or folder in your home directory.
G Guided Step by step - type exactly this and compare the result >
Exercise G1: Make a File Immutable
- Create a practice file:
touch important_config.txt- Apply the immutable flag:
sudo chattr +i important_config.txt- Try to modify or remove the file.
- Observe that the filesystem attribute blocks the change.
Exercise G2: Verify the Attribute
- Run:
lsattr important_config.txt- Confirm that the immutable flag appears in the output.
Exercise G3: Remove the Attribute
- Remove the flag:
sudo chattr -i important_config.txt- Verify with
lsattr. - Confirm that the file can now be changed or removed normally.
S Solo Task described, hints available - figure it out >
Exercise S1: Try Append-Only
- Create a new file:
touch bank_ledger.txt- Apply append-only mode:
sudo chattr +a bank_ledger.txt- Append text with
>>. - Then try overwriting with
>. - Observe how the behavior differs.
Exercise S2: Clean Up Safely
- Remove the append-only flag:
sudo chattr -a bank_ledger.txt- Delete the file afterward.
M Mission Real scenario - no hints, combine multiple skills >
Mission M1: Protect and Unprotect a Practice Directory
Create a small practice directory with two files inside it. Then:
- find the recursive option for
chattr - apply the immutable flag to the whole directory tree
- verify the result
- remove the flag recursively so you can clean up afterward
The learning goal is not the dramatic rm -rf moment. It is understanding the full attribute lifecycle safely.