Use this file to discover all available pages before exploring further.
In this article, you will learn how to list, set, and change standard file permissions in Linux. Mastering file and directory ownership along with permission settings is essential for effective access management on any Linux system.
Every file and directory has an associated owner. To view detailed information—including owner details and permission settings—use the following command:
$ ls -l-rw-r----- aaron family 49 Oct 27 14:41 family_dog.jpg
In the example above, the file “family_dog.jpg” is owned by the user “aaron”. Only the owner (or a root user) can modify the file’s permissions.The second field in the output indicates the file’s group; here, it is the “family” group.
To change the owner of a file or directory, use the chown command with the following syntax:
$ sudo chown new_owner file/directory
For example, to change the file’s owner from “aaron” to “jane” (which requires root privileges):
$ sudo chown jane family_dog.jpg
The change is reflected with:
$ ls -l-rw-r----- 1 jane family 49 Oct 27 14:41 family_dog.jpg
You can also change both the owner and the group simultaneously by specifying them separated by a colon. For example, to revert the file’s ownership back to “aaron” with the group “family”:
$ sudo chown aaron:family family_dog.jpg
Verifying with:
$ ls -l-rw-r----- 1 aaron family 49 Oct 27 14:41 family_dog.jpg
The first character of the output produced by ls -l indicates the file type:
A dash (-) for a regular file
“d” for a directory
“l” for a symbolic link
Following this, the next nine characters represent permissions divided into three distinct groups:
User (owner) permissions
Group permissions
Others (everyone else)
For regular files, permissions are represented as:
“r” for read
“w” for write
“x” for execute
In the case of directories:
“r” allows listing of the directory’s contents,
“w” permits creating or deleting files,
“x” enables entering the directory (via the cd command).
The diagram below visually explains how file and directory permissions work:
Consider the following example where the file “family_dog.jpg” has permissions set to read-only for the owner, read-write for the group, and no permissions for others:
$ ls -l-r--rw---- 1 aaron family 49 family_dog.jpg
Even though user “aaron” is part of the “family” group (which has write permissions), the system applies the owner’s permissions first. Since the owner is limited to read-only, write operations are denied. For instance, attempting to append text as the owner results in:
(aaron)$ echo "Add this content to file" >> family_dog.jpgbash: family_dog.jpg: Permission denied
If another user, such as “jane” (also a member of the “family” group), accesses the file, group permissions are applied:
(aaron)$ su jane(jane)$ echo "Add this content to file" >> family_dog.jpg
After this operation, verifying the file contents shows that Jane was able to write to it:
(jane)$ cat family_dog.jpgPicture of Milo the dog
For users who are neither the owner nor members of the file’s group, the “others” permissions will determine the level of access.
To specify multiple permission changes, separate them with commas. For example:
$ chmod u+rw,g=r,o= family_dog.jpg
Alternatively, if you want to ensure that the user has exactly read and write permissions and remove write permission from the group without altering other group settings:
In this output, the octal value “640” corresponds to:
6 (4+2) for the user (read and write)
4 for the group (read-only)
0 for others (no permissions)
To calculate these values:
Read (r) = 4
Write (w) = 2
Execute (x) = 1
For example:
rw- equals 4+2 = 6
r— equals 4
--- equals 0
Other common permission sets include 755 (rwx, r-x, r-x) and 777 (full permissions for everyone).Once the desired octal value is determined, set the permissions with:
$ chmod 640 family_dog.jpg
Now, “family_dog.jpg” is set to:
Owner: rw-
Group: r—
Others: no permissions
The diagram below illustrates how read, write, and execute permissions translate to their corresponding octal values:
This article covered the fundamentals of listing file details, changing ownership, and modifying file permissions using both symbolic and octal notations. Understanding the Linux permission model is key to maintaining secure file management practices.Well done, and see you in the next article!