rwx & chmod with numbers
Read and set permissions
Lesson 15 of 20 · 10 min · Module 5: Permissions and the system
Linux decides who may read, change, or run every file. Understanding permissions prevents both security problems and confusing "Permission denied" errors.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Read permission strings
- Convert rwx to numbers
- Set permissions with chmod
The idea
In -rwxr-x---, the three groups after the type are for the owner, the group, and others. r = read (4), w = write (2), x = execute (1). Add them per group: rwx = 7, r-x = 5, --- = 0. chmod 750 file sets rwxr-x---.
ls -l projects/scripts
chmod 640 notes.txt
ls -l notes.txt
01Three audiences, three rights
Each file has an owner, a group, and everyone else. For each of them, the permission string shows r, w, and x, or a dash when the right is missing.
02Numbers are sums
Read is 4, write is 2, execute is 1. rw- is 4 + 2 = 6. r-x is 4 + 1 = 5. So 644 means the owner can read and write, and everyone else can only read.
chmod 644 notes.txt
ls -l notes.txt-rw-r--r-- 1 learner learner 52 Oct 19 09:00 notes.txt03Choose the smallest permission that works
Secrets like keys and passwords should be 600. Scripts that only you run can be 700. Web pages that a web server must read are usually 644.
Your turn
private.txt in your home folder containing my secret plan and make it readable and writable only by you (600). Then set projects/scripts/hello.sh to 700 so only you can read, change, or run it.What the checks look for
- private.txt contains the plan
- private.txt is 600 (rw-------)
- hello.sh is 700 (rwx------)
Take this with you
Permissions are three digits: owner, group, others, each a sum of 4, 2, and 1.
Go a little further
Check a few files in /etc with ls -l and decode their permissions.