Every file has an owner and permissions
Linux decides who may do what with each file. ls -l shows it in the first columns:
ls -l diary.txt hello.sh
ls -ld sharedIn the terminal
student@vulntech:~$ ls -l diary.txt hello.sh -rw-r--r-- 1 student student 35 Oct 17 06:29 diary.txt -rw-r--r-- 1 student student 40 Oct 17 06:29 hello.sh student@vulntech:~$ ls -ld shared drwxr-xr-x 2 student student 0 Oct 17 06:29 shared
Take -rw-r--r-- 1 student student ... diary.txt apart:
| Part | Example | Means |
|---|---|---|
| Type | - | - a normal file, d a directory, l a link |
| Owner (user) | rw- | What the owner may do |
| Group | r-- | What members of the file's group may do |
| Others | r-- | What everyone else may do |
| Owner name | student | The user who owns the file |
| Group name | student | The group the file belongs to |
Each set of three is always in the order r, w, x; a - means that permission is missing.
What r, w and x mean
| Letter | On a file | On a directory |
|---|---|---|
r read | Read the contents | List the names inside (ls) |
w write | Change the contents | Create, delete and rename files inside |
x execute | Run it as a program | Enter it (cd) and reach the files inside |
Think of it like this: Think of a directory as a room.
xis the key to the door,rlets you read the list of things inside, andwlets you bring things in or throw them out.
Some real examples
ls -ld /root /tmp /etc/shadow
ls /rootIn the terminal
student@vulntech:~$ ls -ld /root /tmp /etc/shadow -rw-r----- 1 root shadow 422 Oct 17 05:31 /etc/shadow drwx------ 2 root root 0 Oct 17 05:31 /root drwxrwxrwt 4 root root 0 Oct 17 05:31 /tmp student@vulntech:~$ ls /root ls: cannot open directory '/root': Permission denied
/root is rwx------: only its owner, root, can do anything there, so ls /root is refused. /etc/shadow holds password hashes and is unreadable for normal users. The t on /tmp is a special bit you'll meet at the end of this module.
Tip:
statshows the permissions in letters and in numbers (next lessons):stat -c '%A %a %U %G %n' diary.txt.
Remember:
ls -lshows type + rwx for user, group and others, then owner and group. On a directory,xmeans you may enter.