Understanding Linux permissions
File permissions on Linux, as well as distributions like Ubuntu and Fedora, determine who can access files and directories. This is crucial for the security of your operating system. You can view these permissions using a terminal, so it’s important to understand what these permissions mean. In this guide, we’ll cover the basics for you.
The Basics of File Ownership
Before discussing permissions, let’s talk about ownership on Linux. This is particularly important for multi-user systems. There are three key aspects to know:
- User: The person who created and owns the file (ownership can be changed).
- Group: Assigned to several users by system admins to manage file permissions more easily. By default, the group might be the same as the user.
- Other: Refers to anyone with access to the system or all users on the system.
What Are File Permissions?
Files and directories on Linux have different permissions: read, write, and execute. These permissions have different implications for files and directories, as shown in the table below:
File Permission | Meaning |
---|---|
Read | Permission to view or copy |
Write | Permission to modify |
Execute | Permission to run the file |
Directory Permission | Meaning |
---|---|
Read | Permission to list all files and copy files |
Write | Permission to add or delete files |
Execute | Permission to enter the directory |
Viewing File Permissions and Ownership in the GUI
For most users, the easiest way to check permissions on Linux is through the graphical user interface. Right-click the file and select “Properties.” Then, go to the “Permissions” tab to see more details. If you own the file, you can change its permissions using the dropdown menu.
Viewing File Permissions and Ownership in the Terminal
The terminal is the core of Linux, making it the best way to check permissions. Use the ls
command to list file and directory information. The ls -l
command will provide a detailed list view, which is recommended.
For example, using ls -l
displays a readout like this:
drwxr-xr-x 2 arif arif 4096 Oct 31 12:40
Key elements to note include the file type, permissions, hard link count, user owner, group owner, file size, time stamp, and file name.
File Type
Letter | File Type |
---|---|
d | Directory |
– | Regular file |
l | Symbolic link |
The first character indicates the file type (e.g., d
for directory).
Permissions
Letter | Permission Meaning |
---|---|
r | Read permission |
w | Write permission |
x | Execute permission |
– | No permission |
Permissions are divided into three sets: user owner, group owner, and other (everyone else). For example, rwxr-xr-x
breaks down as follows:
Set | Meaning |
---|---|
rwx | User can read, write, and execute |
r-x | Group can read and execute |
r-x | Others can read and execute |
User Owner and Group Owner
In the example arif arif
, the user and group owner are both named “arif.” This is common on single-user systems, but on multi-user systems, the group name might differ.
File Size, Time Stamp, and File Name
These fields are straightforward and provide basic file information.
How to Read File Permissions: Symbolic Mode
Permissions represented by letters are known as symbolic mode. For example, rwxr-xr-x
represents three levels of permission:
rwx
: User can read, write, and execute.r-x
: Group can read and execute.r-x
: Others can read and execute.
To grant execute permission to the user group, use:
chmod g+x <filename>
How to Read File Permissions: Numerical Mode
The chmod
command sets file permissions numerically. Each permission has a value:
- Read (r): 4
- Write (w): 2
- Execute (x): 1
In chmod ###
, the first number represents the user, the second the group, and the third others. For example, to match rwxr-xr-x
, use chmod 755 <filename>
:
- User: rwx = 4+2+1 = 7
- Group: r-x = 4+1 = 5
- Others: r-x = 4+1 = 5
To give full access to everyone, use chmod 777 <filename>
.
Setting File Permissions on Linux
You can set file permissions through the GUI or Terminal. To set permissions in the Terminal, use either symbolic or octal (numerical) mode.
Setting a User Group
First, ensure the file’s group is correct. Use the chown
command to match the file group to the appropriate user group:
chown arif <filename>
Symbolic Mode
To grant read, write, and execute access to the user owner and group, use:
chmod ug+rwx file
This leaves the “other” group unchanged.
Numerical Mode
To allow the owner to read, write, and execute, but others to only read, use:
chmod 744 <filename>
This sets permissions to rwxr--r--
.
Diving Deeper into Linux
This guide covers the basics of Linux permissions. Advanced users and system administrators may need more complex configurations, but this should cover most power users.