← Linux and the Command Line
Lesson 34 of 51 · 10 XP
chmod — file permissions
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
ls -l shows the permissions in the first column:
-rwxr-xr-- 1 kai dev 4096 Nov 4 12:00 deploy.sh
│└┬┘└┬┘└┬┘
│ │ │ └── others: r-- — read only
│ │ └───── group: r-x — read and execute
│ └──────── user: rwx — everything
└────────── the type: - a file, d a folder, l a link
r — read, w — change, x — execute (for a folder, x is the right to enter it).
The letter notation:
chmod +x deploy.sh # allow everyone to execute it
chmod u+x deploy.sh # only the owner (u — user, g — group, o — others, a — all)
chmod go-w file.txt # forbid writing for the group and others
chmod u=rw,go=r file # set it exactly
The octal notation — each triple of permissions as a number: r = 4, w = 2, x = 1.
| number | permissions | typical for |
|---|---|---|
755 |
rwxr-xr-x |
scripts, programs, folders |
644 |
rw-r--r-- |
ordinary files |
600 |
rw------- |
secrets: ssh keys, .env |
700 |
rwx------ |
a private folder, ~/.ssh |
chmod 755 deploy.sh
chmod 600 ~/.ssh/id_ed25519 # ssh refuses to work with a key if the permissions are wider
chmod -R 755 public/ # recursively
chmod 777 ("everything for everyone") is almost always a security mistake. If something "doesn't work" without it, look for the real cause.
Task. Make run.sh executable only for the owner and read-only for everyone else (744), and make secret.key readable and writable only by the owner (600). The check lines will print the permissions.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.