Skills / Linux administration / Users, groups and file permissions

Linux administration, lesson 2 of 8

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 640
  • 755 is rwxr-xr-x: the owner can do everything, others can read and run (common for programs and folders)
  • 600 is rw-------: 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.

Try it: Work out what these permissions mean in words: 644, 700 and 750. Then write the chmod command that makes a file readable and writable by its owner only.

Check yourself

1. In rw-r-----, what can the group do?

2. What numeric value is rwxr-xr-x?

3. Why is chmod 777 a bad fix for a permission problem?