CHAPTER 6 · 6 lessons · 78 exercises

Permissions

How to read `Permission denied`, and how to fix it.

This is the first place at the terminal where people lose heart. Permission denied.

This chapter is about reading the -rw-r--r-- sitting to the left in ls -l, and changing it with chmod.

It looks like a mysterious row of symbols, but what is inside is very simple. Can read (r), can write (w), can execute (x) — those three, laid out in order for the owner, the group and everyone else. Read the nine characters three at a time.

There are two ways of changing them.

  • write it in symbolschmod u+x run.sh (give the owner execute)
  • write it in numberschmod 640 secret.txt (three digits, each the sum of r=4, w=2, x=1)

Both do the same thing, so learn to read both. Numbers are what you meet more often in the field.

Once the mechanism makes sense, you need never go around putting 777 on things and hoping. That one means "anyone in the world may rewrite this", and it is far too strong a medicine for 99% of what you want to fix.

A directory's x does not mean "execute" but "can pass through". That is the one exception, so it comes at the end of the chapter.

Lessons in this chapter

The read, write and execute marks

  1. 28Read the nine characters of `ls -l`How to read a string like rw-r--r--. The one character for the kind, and three sets of rwx.Go to the exercises
  2. 29Change permissions with symbols (`chmod u+x`)Hand chmod three things: who, what to do, and to what. The u g o a and + - = combinations.Go to the exercises
  3. 30Change permissions with numbers (`chmod 755`)Add up r=4, w=2 and x=1 into three digits. What 644 and 755 mean, and why 777 is too strong.Go to the exercises
  4. 31The default for new things (`umask`)Why touch gives you 644. Read the number being taken off a base of 666.Go to the exercises

Owners, and permissions on folders

  1. 32Owners and groupsWho the nine characters apply to. How only one of the three is chosen, and why you cannot change the owner.Go to the exercises
  2. 33The permissions of a directoryA box's x means "pass through". Whether something can be removed is decided by the box, not the file.Go to the exercises

Next up is “Users and groups”. Who you are logged in as. And what it actually means to become the administrator.