How to Manage File Permissions in Ubuntu Using Command?

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

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.Understanding permission mode for the owner, the group, and the other users.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
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
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.

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.Permission mode of the file.txt file and all contents inside the current directory is displayed using ubuntu command.

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
Explanation
  • 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
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.

➎ 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
Explanation
  • 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 executing permission to the owner for the file1.txt file is set using ubuntu file permissions command.The above image shows that I have given the executing permission to the owner for the file1.txt file.



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”.Current location and permission status of the file2.txt file is shown using ubuntu command. 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
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
  • 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 writing permission of the file2.txt file for the group has been removed for the sam user.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.The file4.txt file is on the desktop.➋ Then, click on the Properties option.Few options appeared after right-clicking on the file4.txt file.➌ Now, click on the Permissions ribbon.The properties window of file4.txt appeared after clicking on the properties option.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.The permission status for the owner, the group, and the other users of the file4.txt file.



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.The file3.txt file is on the ubuntu desktop.➋ Then, click on Properties.Few options appeared after right-clicking on the file3.txt file.➌ Now, click on the Permissions ribbon.The properties window of file3.txt appeared after clicking on the properties option.➍ Then, click on Access under Others.The permission status for the owner, the group, and the other users of the file3.txt file.➎ Now, select Read and Write from the options.Few options have appeared after clicking on Access under Others.The below image shows that I have changed the permission of the file3.txt file and given others users to read and write access.Reading and writing permission for other users has been set after selecting Read and Write from the option.

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?

The “chmod 777” command means reading, writing, and executing permission is permitted for the owner, group, and other users.

How to check file permissions in Linux command?

To find 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.

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 sodoers files in the “/etc/sodoers” 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/sodoers” 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. And with this access, they can run commands which they can not run as a regular user.

Related Articles

Rate this post
Susmit Das Gupta

Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo