About this post
In the world of Unix operating systems, where users share resources on the same server, it is crucial to have a solid foundation and understanding of Linux user privileges, file and directory ownership, and access levels.
In this post, we'll learn about Linux permissions and how to configure privileges to secure our system.
Β
Table of Contents
- Linux Files and Directories
- User Groups on Linux
- File Ownership
- Linux Permissions
- Viewing Permissions, Ownership and Groups
Linux Files and Directories
In Linux (like other Unix operating systems) everything is a file. Directories, files, and even devices are files (like the way that almost everything in Python is an object if you've experience in that).
Linux organizes these files in a hierarchical structure. In this tree-like structure, the highest file system level is for the root directory (the /
directory). All other files and directories will be inside (under) the root directory.
βββ / βββ bin βββ boot βββ cdrom βββ dev βββ etc βββ home β βββ hosein β β βββ Desktop β β βββ Documents β β βββ Download β β ... β βββ guest β βββ ... β ... βββ lib ...
User Groups on Linux
In real life, if you gather people together based on similarities or other purposes you are creating groups. Just like that, a collection of users can make a group on Linux.
Back to our library example, we can have student group with the purpose of studying, employees with the purpose of providing services and managers with the purpose of supervising the processes.
File Ownership
File ownership as the name suggests, determine who is the file owner and how they can treat to the file. It may sound corny but as soon as you use something in a shared space, there will be generic rules about that, these rules may not only apply to you, but also to the group you are in or even for others.
Think about a librarian who buy a new book, they are the owner of the book (file) and has full access to that.
Linux Permissions
File permissions are a set of rules that allows or disallows (or prevent) others from viewing, editing (or modifying) and executing (or running) them.
The mentioned actions are actually permission types that can be applied to a user or their user group or others.
Note that the root user or superuser can access any file one the system.
β Permission Types
Permission type at the first place determine the access or denial of access to a file or a directory. Also it indicates what exactly can you do if you have access to the file or directory.
It can be helpful if you memorise the symbolic (using letters) and octal (using numbers) notation for the permissions.
β― Read (r)
The read permission indicates that the user can open a file or can see the directory contents.
The symbol of this permission is r
, the first letter of the word read. Also in octal notation the number 4
represent the read access.
β― Write (w)
The write permission indicates that the user can create, modify or delete a file or can create, modify or delete a directory. Here by modifying the directory I mean the user can change the directory name as an example.
The symbol of this permission is w
, the first letter of the word write, and the octal notation is 2
.
β― Execute (x)
The execute permission indicates that the user can can run executable files as a program or the user can enter into a directory.
The symbol of this permission is x
, the second letter of the word execute
. The octal notation is 1
Sometimes the user can only have the permission to execute the file, but no reading or writing permission. So in simple words, if you have execution permission for an executable file, no matter if you don't have read or write access, you can run that file. The linux kernel will open it on its own and then execute that.
β― No Permission (-)
No permission will be indicated with three dashs (---
) or the number 0. When there is no permission, the user isn't able to read, write or execute anything.
β― Permission Types Table
Up to this point, you know the different types of permission and their symbolic and ocatl notations. You can see them in one place in the following table:
Permission | Symbol (Complete form) | Octal (How it formed) |
---|---|---|
No Permission | - (---) | 0 |
Execute | x (--x) | 1 |
Write | w (-w-) | 2 |
Write + Execute | wx (-wx) | 3 (2+ 1) |
Read | r (r--) | 4 |
Read + Execute | rx (r-x) | 5 (4 + 1) |
Read + Write | rw (-rw) | 6 |
Read + Write + Execute | rwx (rwx) | 7 (4 + 2 + 1) |
β Permission Levels
β― User (u)
β― Group (g)
β― Other (o)
Viewing Permissions, Ownership and Groups
β Command Line
directory d file -