Reading Permissions with ls -l

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 shared

In 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:

PartExampleMeans
Type-- a normal file, d a directory, l a link
Owner (user)rw-What the owner may do
Groupr--What members of the file's group may do
Othersr--What everyone else may do
Owner namestudentThe user who owns the file
Group namestudentThe 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

LetterOn a fileOn a directory
r readRead the contentsList the names inside (ls)
w writeChange the contentsCreate, delete and rename files inside
x executeRun it as a programEnter it (cd) and reach the files inside

Think of it like this: Think of a directory as a room. x is the key to the door, r lets you read the list of things inside, and w lets you bring things in or throw them out.

Some real examples

ls -ld /root /tmp /etc/shadow
ls /root

In 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: stat shows the permissions in letters and in numbers (next lessons): stat -c '%A %a %U %G %n' diary.txt.

Remember: ls -l shows type + rwx for user, group and others, then owner and group. On a directory, x means you may enter.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…