Chapter 1 · Lesson 5
Beginner
2 min read
File Permissions and Ownership
Overview
Every file and directory has an owner, a group and a permission set. The basic permissions are read, write and execute. Execute means run a file or enter a directory; it does not mean execute every file inside it.
Detailed Notes
Read permission notation
bash
ls -l ~/linux-practice
Example:
text
-rw-r--r-- 1 learner learner 120 Nov 28 notes.txt
drwxr-xr-x 2 learner learner 4096 Nov 28 files
The first character is the type:
-is a regular file.dis a directory.lis a symbolic link.
The next nine characters are three sets:
text
rwx r-x r--
user group others
For a file, r reads, w changes and x runs. For a directory, r lists names, w creates/removes entries and x enters it.
Change modes
bash
chmod u+x deploy.sh
chmod 755 deploy.sh
chmod 640 secrets.txt
Symbolic mode:
uownerggroupoothersaall+add-remove
Octal mode:
| Digit | Permissions |
|---|---|
| 0 | --- |
| 1 | --x |
| 2 | -w- |
| 3 | -wx |
| 4 | r-- |
| 5 | r-x |
| 6 | rw- |
| 7 | rwx |
755 means owner rwx, group r-x and others r-x. 640 means owner rw-, group r-- and others none.
Change ownership
bash
sudo chown learner:developers app.log
sudo chown -R learner:developers project/
chown USER:GROUP FILEchanges owner and group.-Rapplies recursively.
Never fix an application permission error by changing the whole system to 777. First identify the service user and expected directory ownership.
Common Interview Questions
Finished this lesson?
0 of 25 lessons done · 0% of the course

