appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Permissions and users

Lesson 3 of 510 minBeginner

Read the permission string, change it with chmod and understand sudo and root.

Reading ls -l

-rw-r--r-- 1 ana staff 1204 Oct  4 10:12 notes.txt
drwxr-xr-x 2 ana staff 4096 Oct  4 10:15 projects

The first character is the type: - for a file and d for a directory. The next nine are three groups of three: permissions for the owner, the group and others, each as read (r), write (w) and execute (x). After them come the owner and the group.

Numbers

Each group is a sum: read is 4, write is 2 and execute is 1. So rw- is 6, r-- is 4, rwx is 7. rw-r--r-- is therefore 644 and rwxr-xr-x is 755.

Changing permissions

chmod 600 id_ed25519      # only the owner can read and write
chmod 755 script.sh       # owner everything, others read and run
chmod +x script.sh        # add execute for everyone
chmod u+w,go-w file       # symbolic: owner may write, group and others may not
chown ana:staff file      # change owner and group (needs root)

Directories need execute

On a directory, r lets you list names, w lets you create and delete entries, and x lets you enter it and reach what is inside. A directory without x is unusable even if you can read it.

root and sudo

root can do anything, including destroying the system. Instead of logging in as root, use sudo command to run a single command with root rights. It asks for your password, and the action is logged.

CarefulNever run a command with sudo that you copied without understanding it, especially anything that pipes a download into a shell.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What does the permission string rw-r--r-- correspond to in numbers?
HintUse the numeric mode that means rw- for the owner and nothing for the rest.
HintUse the symbolic form with a plus sign.
4. What is sudo for?

Key terms