Have you ever encountered an issue while attempting to access a directory, and received an error message that you do not have permission to make changes to the file or directory? This comes when you don’t have the necessary access permissions to execute or modify any components within the file.
In the Linux platform, multiple users are allowed to access the same server when working as a team. This is good but also increases the security risk as this could affect the owner’s privacy. Individually accessing the files or directory can also raise the chance of losing data or important files.
Linux is a user-friendly platform that always ensures the user’s privacy and enhances the best user experience. So, there’s no need to worry if your system is accessed by several users; we can limit access to the files or directories by changing the permissions. Here’s to changing the file or directory permissions, we have a powerful chmod Linux command that is used to allow or restrict directory access.
- Linux Change Permissions of Directory
- Change Permission of Directory in Linux Using the GUI
- Change Permission of File/Directory in Linux Using the Terminal
Before coming to this command tool, first, we must have the following information:
Typically, Linux has three types of users:
|The user who created the file or directory
|Number of multiple users; permission access to all of the members of a group
|Other Users (o)
|Any other user who’s not the owner of the file nor a member of any group
Define Permission Types
There are three types of file or directory permissions we can give access to users:
|(r) 🡪 read
|user can only view the file or directory
|(w) 🡪 write
|user can view and edit the file or directory
|(e) 🡪 execute
|user can read, write, or execute the file or directory
While changing the directory permission, there are two possibilities, either to allow or remove the access. In such cases, the following operators will be used to assign or remove permissions:
|indicates to add the permissions (read, write, or execute) to access the file/directory
|Indicates to no permission or remove the permissions ((read, write, or execute) to access the file/directory
Also, you can identify the assigned permission to a file or directory using the numeric characters, the following table displays the number and their meaning in the Linux change directory:
|Write + Execute
|Read + Execute
|Read + Write
|Read + Write + Execute
Now, let’s run some examples while keeping in mind the information mentioned above; fortunately, we have two approaches to modifying the directory permission:
The simplest way to change directory permission is through the GUI approach; let’s create a new directory named sample_dir for a better understanding:
Right-click on it to get its popup menu and click on the Properties option:
Move to the Permissions tab and there you will see different sections i-e, owner, group, and others:
In the above screenshot, you can see, that the access is assigned against the owner, group, and other users; navigate to the “Change Permission for Enclosed files” button and click it to see other permission options as well:
In the sample_dir directory, both the owner and group have complete access to the files and folders; this includes the ability to read, write, edit, delete, or execute any data within it. However, other users are only allowed to access the files and cannot make any modifications.
You can modify the permission access to the Owner (the one who made the directory), Group (from where the owner belongs to including other users), and Others (all other users) according to the requirement.
If you’re good at using the terminal to perform certain tasks on a Linux machine, then this section is for you.
Make a new directory and let’s name it test_dir by typing the following mkdir command in the terminal:
Change the default directory location to the test_dir directory using the cd command:
Create some raw files in the test_dir directory by executing the mentioned touch command:
Now, run the ls along with the -l parameter to list down the files with their default access permissions:
In the above screenshot:
You can change the permissions with the chmod command by using the mentioned syntax:
Let’s suppose, I want to assign the following permission to the Linux groups:
owner→ read, write, and execute
group→ read and write
others→ read and write
So, the command would be the following to allocate these permission against file1:
Confirm using the ls command if the permission is successfully modified against file1:
You can also assign the permission using numerical characters, like the command for the file2 having the same permissions would be:
In the above command:
7 is for the Owner having read (4), write (2), or execute (1) permission, 6 for the Group read (4) and write (2), and next 6 is for the Other users read (4) and write (2) permission.
Confirm now using the ls command to check the permission settings:
Similarly, we can change the directory permission using the same approach we followed above with files.
Move to the home directory and run the ls command to show directory permissions:
In the above screenshot, d represents the directory; let’s take any directory as an example and change its permission i.e., sample_dir:
The current permissions assigned to the sample_dir directory are, that the owner and group can read, write, or execute this directory, whereas other users have access to read and execute the directory.
To modify this, run the mentioned chmod command and change directory permission according to the requirement:
Execute the ls command to confirm the access modifications we have made in the sample_dir directory:
You can also change the directory permission along with its sub-files and content by using the -R parameter:
Change the directory location to the sample_dir and run the ls command to list its files permission:
Changing the file or directory permission is necessary when multiple users are working on the same server. There are three types of Linus, owners, groups, and others; the owner is the one who makes files or directories, the group consists of multiple users, and others are the local users working on the same system. Linux allows its users to set permission on the files and directories to avoid any loss and harmful acts by other users.
This guide has mentioned a brief guide about how to change the directory or file permission using the command-line prompt and GUI. We have also mentioned all the symbolic representations with their explanation that are used while modifying the file/directory access. Also, we have discussed how the chmod command works as a powerful tool when we need to change directory permissions.