Skills / Linux administration / Users, groups and file permissions
Users, groups and file permissions
Linux was designed for many users sharing one machine, so every file has an owner, a group, and permissions saying who may do what. Understanding them is essential for running servers safely.
Run ls -l and you will see lines like:
-rw-r----- 1 asha devs 2048 Nov 3 report.txt
The first block is the permissions. After the first character (- for a file, d for a directory), there are three groups of three:
- Owner (asha):
rw-, so read and write - Group (devs):
r--, so read only - Everyone else:
---, so nothing
r means read, w means write, and x means execute (run a program; for a directory, it means you may enter it).
Numbers instead of letters. Each permission has a value: r = 4, w = 2, x = 1. Add them for each group:
rw-= 6,r--= 4,---= 0, so the file above is 640755isrwxr-xr-x: the owner can do everything, others can read and run (common for programs and folders)600isrw-------: private to the owner (right for private keys)
Changing them: chmod 640 report.txt sets permissions; chown asha:devs report.txt sets owner and group.
root is the all-powerful administrator. Do daily work as a normal user and use sudo for single commands that need admin rights. Never fix a permission problem with chmod 777, which lets anyone change the file; give the right user or group access instead.
The tutor gives hints, not finished answers. Log in to use it.