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.
What are Permissions in Ubuntu?
In Ubuntu, different users possess different permissions. 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:
- 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
EXPLANATION- 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
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.
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:
- 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
- Now, press the ENTER button.
- Then, type the following command in the terminal to give the owner executing permission for the file1.txt file and press ENTER:
chmod u+x file1.txt
EXPLANATION- 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.
- Then, copy the following command into the terminal to see the details of the contents of the current directory and hit the ENTER button:
ls -l
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:
- 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
EXPLANATION- 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
EXPLANATION- /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.
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:
-
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:
- 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 file’s permission whenever necessary.
People Also Ask
What is permission in Linux?
Permission in Linux is the access granted to users, groups, and others regarding files and directories. It specifies who can read, write, or even execute a file. Permissions are represented by 3 sets of characters and displayed as “r” for read, “w” for write, and “x” for execute.
How can I change a file permission in Ubuntu?
To change file permission in Ubuntu, use the chmod command followed by the standard permission symbol and the file name. For example, the Linux command chmod u+x script.sh
grants all the users the execute permission of the file script.sh.
How to change the file owner in Ubuntu?
To change a file ownership, use the chown command followed by the new owner name and the file name afterward. For instance, sudo chown new_owner file_name
grants the ownership of file_name to new_owner.
What is the difference between user permission and user ownership in Linux?
User permission in Linux refers to the access rights of individual users or groups regarding files and folders to read, write, and execute files. On the other hand, user ownership defines who has full control over a file or directory. The owner can modify permission, change ownership, and maintain the overall file and folder attributes.
How to check file permissions in Linux command?
To check the file permission in Linux, type the ls -l
command in the terminal then press the ENTER button. It will list all the contents of the current directory with the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time.
What does the chmod 777 command mean in Ubuntu?
The chmod 777
command means reading, writing, and executing permission is permitted for the owner, group, and other users.
How do I find files with 777 permissions?
To find the files with 777 permission which means reading, writing, and executing permission for the owner, group, and other users you have to type the find /home/ -perm 777 -type f
command in the terminal and then press ENTER button. It will list all the files inside the home directory with 777 permissions.
How to check sudo permissions?
To know whether a particular user has sudo permission type sudo -l -U user_name
into the terminal then press the ENTER button.
How to list sudo permissions in Linux?
You can find all of the sudoers files in the “/etc/sudoers” directory. To list everything in that directory with the reading, writing, and executing permission information, number of hard links, owner, group, size, and last modification time, type ls -l /etc/sudoers
in the command prompt then press the ENTER button.
What are sudo permissions?
The sudo is a command line utility in Unix and Unix-based OS like Linux. It grants users privileged access to the system resources. With this access, they can run commands which is not possible to run as a regular user.
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
FUNDAMENTALS A Complete Guide for Beginners