Ubuntu is a multiuser system that enables multiple users to interact with the operating system simultaneously. Generally, it ensures restricted permission to the user, prevents unauthorized access to the system, and makes the whole system more secure. In this article, I have shown some utilities of the Ubuntu file permissions command.
Key Takeaways
- Getting familiar with the process of checking file permission from the terminal and GUI.
- Getting familiar with the process of changing the permission of your file from the terminal.
- Getting familiar with the process of changing the permission of a file owned by another user from GUI and terminal.
- Getting acquainted with some complementary information associated with the Ubuntu file.
Requirements
- To change the permission of a file or folder owned by another user, you need to be a root user or have root/sudo privileges.
What are Permissions in Ubuntu?
In Ubuntu, different users possess different permission. Usually, three types of permission are read, write and execute.
- Read permission(r) allows viewing the contents of a file or folder.
- Write permission(w) allows the deletion or modification of a file or folder.
- Execute permission(x) allows to execution of a script file.
In the case of a directory, execute permission means accessing contents or subdirectories within that directory. Here, the below image eases us to understand about permission type of a file or folder.Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Check File Permissions in Ubuntu Using ls Command
You can easily check file permission in Ubuntu using the ls command. To check the permission mode of a specific file or the permission mode of all files under a directory, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, type the following command in the terminal and then press the ENTER button to check the permission status of a file.
ls -l file.txt
- ls: Prints the contents of the current directory.
- -l: Prints the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time of all contents of the current directory.
- file.txt: This is the file of which I want to print the details.
➌ Alternatively, if you want to know the permission status of all files under a directory type the following command in the terminal and then press the ENTER button.
ls -l
- ls: Prints the contents of the current directory.
- -l: Prints the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time of all contents of the current directory.
The below image shows the permission states of a file named file.txt and all files under the same directory with the help of the terminal.
Watch How to Manage File Permissions in Ubuntu Using Command
Change File Permissions Using chmod Command in Ubuntu
As a multiuser system, it is necessary to change the permission of the file or folder. Here, the chmod command serves the purpose of changing the permission of any file or folder.
Some types of symbolic modes are given below.
User Class | Operator | Access Type |
---|---|---|
User | +(add permission) | r(read) |
Group | -(remove permission) | w(write) |
Other | =(set access ) | x(execute) |
a (all class: u, g, o) | – (no permission for read, write or execute) |
For the absolute mode, you have to use an octal number system. Some types of absolute modes are given below.
Permission Mode | 4(Read) | 2(Write) | 1(Execute) | Command |
---|---|---|---|---|
No reading, Writing or Executing permission | No | No | No | 0 |
Only Execute | No | No | Yes | 1 |
Only Write | No | Yes | No | 2 |
Only Write and Execute | No | Yes | Yes | 3 |
Only Read | Yes | No | No | 4 |
Only Read and Execute | Yes | No | Yes | 5 |
Only Read and Write | Yes | Yes | No | 6 |
Read Write and Execute | Yes | Yes | Yes | 7 |
Some real-life scenarios of changing file permission using the chmod command in Ubuntu are given below.
Case A: Use the chmod Command to Modify the Permissions of Your Own File
You can easily give permission for a file to a user using the chmod command. Here I will set the executing permission for the owner of the file1.txt file. To do so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Then, copy the following command into the terminal to see the details of the contents of the current directory.
ls -l
- ls: Prints the contents of the current directory.
- -l: This option prints the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time of all contents of the current directory.
➌ Now, press the ENTER button.
➍ Then, type the following command in the terminal to give the owner executing permission for the file1.txt file.
chmod u+x file1.txt
- chmod: Changes the permission settings of the folder.
- u+x: This option sets the executing permission for owner.
- txt: This is the file I want to set executing permission for the owner.
➎ Now, press the ENTER button.
➏ Then, copy the following command into the terminal to see the details of the contents of the current directory.
ls -l
- ls: Prints the contents of the current directory.
- -l: This option prints the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time of all contents of the current directory.
➐ Now, press the ENTER button.The above image shows that I have given the executing permission to the owner for the file1.txt file.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User in Linux
Case B: Use the chmod Command to Change Permissions of Other’s File
You can easily change the permission for a file owned by another user. Here I have a file named file2.txt owned by another user named “sam”. In this example, I will omit the writing permission of the file2.txt file for the group. To achieve so, follow the below procedures.
Steps to Follow >
➊ At first, open the Ubuntu terminal.
➋ Now, type the following command in the terminal then press the ENTER button.
sudo chmod g-w /home/sam/Desktop/file2.txt
- sudo: Grants root permission.
- chmod: Changes the permission settings of the folder.
- g-w: Omits the writing permission for the group.
- /home/sam/Desktop/file2.txt: This is the absolute path of the file I want to omit the writing permission for the group.
➌ Now, type the following command in the terminal then press the ENTER button.
sudo ls -l /home/sam/Desktop/file2.txt
- sudo: Grants root permission.
- ls: Prints the contents of the current directory.
- -l: Prints the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time of all contents of the current directory.
- /home/sam/Desktop/file2.txt: The absolute path of the file I want to print the details.
The above image shows that the writing permission of the file2.txt file for the group has been omitted for the user named sam.
Complementary Information
Besides, knowing about file permission commands in Ubuntu, you will find the below information helpful.
Check File Permissions in Ubuntu from GUI
You can easily check file permission from GUI (Graphical User Interface). Here. I will check the file permission of the file4.txt file. To do so, follow the below procedures.
Steps to Follow >
➊ At first, right-click on the file4.txt file.➋ Then, click on the Properties option.
➌ Now, click on the Permissions ribbon.
The below image shows the permission states of the file4.txt file. Here, The owner has reading and writing permission, the group has reading and writing permission., and the other users have only read permission.
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
Change File Permissions in Ubuntu from GUI
You can easily change the permission of a file from GUI (Graphical User Interface). Here, I have a file named file3.txt and only writing permission is allowed for other users for this file. Now, I will give writing permission for file3.txt to other users. To achieve so, follow the below procedures.
Steps to Follow >
➊ At first, right-click on the file3.txt file.➋ Then, click on Properties.
➌ Now, click on the Permissions ribbon.
➍ Then, click on Access under Others.
➎ Now, select Read and Write from the options.
The below image shows that I have changed the permission of the file3.txt file and given others users to read and write access.
Conclusion
In this article, I have shown you the full process of using the Ubuntu file permissions command. By going through this article, you will be productive enough to change the permission of the file whenever necessary.
People Also Ask
What does the chmod 777 command mean in Ubuntu?
How to check file permissions in Linux command?
How do I find files with 777 permissions?
How to check sudo permissions?
How to list sudo permissions in Linux?
What are sudo permissions?
Related Articles
- How to Change Permissions of All Files in a Folder in Linux?
- Change Folder Permissions in Linux? [2 Methods]
- ow to Change File Permissions in Linux with 6 Examples
- 2 Cases to Give User Permission to Folder and Subfolders in Ubuntu
- How to Change Directories and Files Recursively with “chmod”
- Change Permissions on Mounted Drive in Linux