In this tutorial, you’ll explore how to view and understand Linux permissions and ownership. Linux is, by definition, a multi-user operating system based on the Unix concepts of file ownership and permissions to provide security at the file system level. There are many intricacies in managing file ownership and permissions, but this tutorial will provide a good introduction.
Prerequisites
- A Linux operating system
- Access to a terminal/command line
- Basic Linux browsing and file management
About Users
Linux is a multi-user system. You should understand the fundamentals of Linux users and groups before ownership and permissions because these are the entities to which ownership and permissions apply.
In Linux, there are two types of users: system users and regular users. Traditionally, system users are used to running non-interactive or background processes on a system, while regular users are used to logging in and running processes interactively. When you first boot and log into a Linux system, you may notice that it boots up with a number of system users that have already been created to run OS-dependent services. It’s normal.
You can view all system users by viewing the contents of the /etc/passwd file. Each line of this file contains information about a user, starting with their username. You can print the contents of the passwd file with the cat command:
cat /etc/passwd
tlt@ubuntu:~$ cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin uuidd:x:107:115::/run/uuidd:/usr/sbin/nologin sssd:x:118:125:SSSD system user,,,:/var/lib/sss:/usr/sbin/nologin gnome-initial-setup:x:125:65534::/run/gnome-initial-setup/:/bin/false gdm:x:127:133:Gnome Display Manager:/var/lib/gdm3:/bin/false tlt:x:1000:1000:The Linux Tutorials,,,:/home/tlt:/bin/bash tlt@ubuntu:~$ /pre>
Superuser
Superuser, also known as the root, is the most privileged user in a Linux system. It has unrestricted access to all files and directories and can perform any action on the system. The superuser is also responsible for managing system resources and security.
About Groups
Groups are an important concept in Linux. A group is a collection of multiple users that share the same access privileges. This allows a system administrator to assign privileges to a single group, instead of having to assign them to each individual user. Groups are also used to easily manage large numbers of users, since a single command can be used to add or remove users from a group.
Viewing Ownership and Permissions
To view the ownership and permissions of a file or directory, use the ls -l command. This command will display the permissions, owner, and group owner of the file.
For example:
ls -l
This command will display the following output:
drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Desktop drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Documents drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Downloads drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Music drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Pictures drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Public drwx------ 3 tlt tlt 4096 Feb 5 09:26 snap drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Templates drwxr-xr-x 2 tlt tlt 4096 Feb 5 09:26 Videos
The first part of the output (“-rw-r–r–”) indicates the permissions of the file. The “r” indicates that the file is readable, the “w” indicates that the file is writable, and the “x” indicates that the file is executable.
The second part of the output (“tlt tlt”) indicates the ownership of the file. The “1” indicates that the file is owned by a single user, and the “tlt tlt” indicates that the user and group owner of the file are both tlt. The third part of the output (“4096 Feb 5 09:26”) indicates the last time modification.
Understanding Mode
In Linux, mode refers to the permissions associated with a file or directory. These permissions determine which users or groups can read, write, execute, or delete the file or directory. There are three types of permissions: read (r), write (w), and execute (x). Each permission can be set for the file or directory owner, the group, and all other users.
File Type
The two types of files in Linux are normal and special. The file type is indicated by the first character of the mode of a file, which is referred to as the “file type field”. This field can contain the following characters: – (dash), d (directory), l (symbolic link), b (block device), c (character device), s (socket), p (named pipe), and other characters that are uncommon.
Permissions Classes
A file in Linux is the user (owner), group, and other. Each class can have a different set of permissions associated with it. Permissions are indicated by the mode column of the file, which consists of three triads that contain symbols representing read, write, and execute permissions. The order of these symbols represents the ability to read, write, and execute the file.
Understanding Read, Write, Execute
Read (R): Read permission allows a user to view the contents of a file or directory, such as the text within a document.
Write (W): Write permission allows a user to change the contents of a file or directory, such as adding or modifying information within a document.
Execute (X): Execute permission allows a user to execute a file or directory, such as running a script or program.
Conclusion
You should now have a good understanding of how ownership and permissions work in Linux. To learn how to change these Linux permissions using chown, chgrp, and chmod.
If you have any questions please leave them in the comments below.