Permissions
Tarih: 2026-06-15 | Kategori: Linux
Etiketler: Linux
Just like in other operating systems, multiple user accounts can be created on Linux, and these users can share the same system. However, when different users share the same system, privacy issues can easily arise. For instance, one user may not want others to view, edit, or delete their files.
We can address this issue with permissions that can be defined at the file and directory level.
To view the permissions for a file or directory, we can use the `-l` parameter of the `ls` command, as discussed in previous sections.
root@hackerbox:~$ ls -l notes.txt
-rwxr--r-- 2 john development 4096 Jul 29 12:34 notes.txt
The columns in the output obtained with the `-l` parameter of the `ls` command are as follows:
Understanding Permissions
[Image of Linux file permissions structure rwxrwxrwx explained]
The file permissions (`rwxr--r--`) given in the example above can be thought of as three different sets of permissions consisting of 9 characters in total. Each set of three characters represents the user, group, and others permission sets.
--- --- ---
rwx rwx rwx
user group others
`r`, `w`, `x`, and `-` Characters
User, Group, and Others
Reading Permissions
First, let's divide the given permissions (`rwxr--r--`) into three distinct groups.
rwx r-- r--
user group others
It is seen that all permissions (read, write, and execute) are granted for the owner user (`rwx`). In other words, the owner of the file (the user named john) can read, modify, and execute this file. However, since this file is a text file, as indicated by its name, it will not execute even though it has execute permission (unless it's a script).
For group permissions, only read permission is granted to the group assigned to the file (`r--`). Write and execute permissions are not granted, as indicated by the `-` character. Members of the `development` group, to which the file is assigned, have only read permission for this file.
As for the permissions of other users and groups, it is also seen that only read permission is granted (`r--`). Again, write and execute permissions are not granted, as indicated by the `-` character. This means that all other users and groups on the system have only read permission for this file.
Changing File and Directory Permissions
To change file and directory permissions, use the `chmod` command. The first argument given to the `chmod` command indicates which permission set you want to change. You can specify the permission set with the `u`, `g`, or `o` options.
After specifying the first argument, you need to indicate whether you want to add or remove a permission. You can use the `+` or `-` options.
Lastly, you need to specify which permission you want to change (`r`, `w`, or `x`).
Let's Do an Example to Understand It Better
For instance, if we want to grant write permission to others for the file `notes.txt`, we start the command by indicating the permission set (`o` for others):
root@hackerbox:~$ chmod o
Then, we indicate whether we want to add or remove the permission. Since we want to add the permission, we use the `+` character.
root@hackerbox:~$ chmod o+
Lastly, we specify the permission (`w` for write).
root@hackerbox:~$ chmod o+w
Finally, we specify the file we want to modify, `notes.txt`, and execute the command. We then verify the changes with `ls -l`.
root@hackerbox:~$ chmod o+w notes.txt
root@hackerbox:~$ ls -l notes.txt
-rwxr--rw- 2 john development 4096 Jul 29 12:34 notes.txt
As we can see, the permission set for others has been changed to `rw-`. Now, other users on the system can read and write to the file.
Another Example (Bulk Assignment)
You can also update multiple permissions and groups in a single command. For example, to grant all permissions (`rwx`) to all sets (`user`, `group`, `others`) for the file `notes.txt`, run the following command:
root@hackerbox:~$ chmod ugo+rwx notes.txt
root@hackerbox:~$ ls -l notes.txt
-rwxrwxrwx 2 john development 4096 Jul 29 12:34 notes.txt