Skip to content
BENIBIX Learn

Linux File Permissions

Level 2 · Files, users and permissions

How to read rw-r--r-- and 644. Who the owner, group and others are. How chmod and chown change who may read, write or run a file.

Course contentsLesson 6 of 10

After this lesson you can

  • Read a permission line like rwxr-x---
  • Set permissions with chmod numbers
  • Change a file's owner with chown

13 mincovers 4 glossary entries

Worth reading first: Root User and sudo

How to read rw-r--r-- and 644

Every file on Linux has an owner, a group and three sets of rights. The owner, the group and everyone else can each be allowed to read, write or run the file. ls -l shows the rights as nine letters, such as rw-r--r--. The same rights are often written as a number, such as 644. chmod changes the rights, and chown changes the owner.

Read the nine letters in three groups of three. The first three are the owner's, the next three are the group's, and the last three are for everyone else. r means read, w means write and x means run. A dash means that right is missing. So rw-r--r-- lets the owner read and write, and everyone else only read.

Each letter has a value. r is 4, w is 2 and x is 1. Add them up for each group of three, and you get one digit. rw- is 6, r-- is 4 and rwx is 7. So rw-r--r-- is 644, and rwxr-xr-x is 755.

A group is a named set of users who share the same rights. A team can share a folder by giving it to their group and letting the group write. Add a user to a group, and they get the group's rights on every file it owns.

chmod sets the rights. chmod 600 key.txt lets only the owner read and write it. chmod +x run.sh adds the right to run it. chown sets the owner and group, as in sudo chown emma:devs report.txt. Only root may give a file away to another user.

Three numbers cover most needs. 644 is a normal file anyone may read. 755 is a program or a folder anyone may enter. 600 is a private file only you may see, such as a key.

A common mistake is chmod 777, to make an error go away. It lets every user on the machine change the file. Any program that breaks in can rewrite it too. If a program cannot read a file, give the right user or group access. Leave the rest shut.

console
$ ls -l key.txt
-rw-r--r-- 1 emma devs 3381 Nov 16 14:02 key.txt
$ chmod 600 key.txt
$ ls -l key.txt
-rw------- 1 emma devs 3381 Nov 16 14:02 key.txt
Before, anyone could read the key. After chmod 600, only its owner, emma, can.

The three numbers you will use most

NumberLettersWho may do whatUse it for
644rw-r--r--Owner writes, all readNormal files and web pages
755rwxr-xr-xOwner writes, all read and runPrograms and folders
600rw-------Only the owner reads and writesKeys and passwords
Three groups of three letters, and each group adds up to one digit: rwxr-x--- is 750.

Worked example

A team shares a folder

Jack and Lucy both edit files in /srv/reports. Jack owns them, so Lucy gets permission denied.

Jack makes a group called reports, adds both of them, runs sudo chown -R jack:reports /srv/reports, then sets the folder to 770. Both can now write, and nobody else can look in.

The words for this lesson4

Check yourself

What does chmod 600 do to a file?

Finished this lesson?

Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.