How to Give Permission to User in Linux? [4 Methods]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The Linux operating system offers several ways to give users access permissions to its file system. Hence, you can give permission to as many users as you like. For this purpose, there are multiple commands that will help you achieve this task. In this article, I will demonstrate the possible methods in order to give permission to a user in Linux from the Command Line Interface(CLI).

Key Takeaways

  • Giving permissions to a specific user.
  • Giving permissions to a specific group.
  • Changing permission modes.

Requirements

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSFlowchart of how to give permission to user in Linux.

Watch 4 Methods to Give Permission to a User in Linux

4 Methods to Give Permission to a User in Linux

The best approach for giving permission to a user in Linux is to use the CLI since Linux distributions provide four basic commands. These commands are as follows: the chown command, the chgrp command, the chmod command, and the setfalc command for altering user permissions. Furthermore, for your convenience, I have divided the application of these commands into four main Methods.

You can read our Comparative Analysis of Methods to distinguish between these four methods and best pick one for your need.

Method 01: Give Direct Permission to a User in Linux

You can directly give file/folder access permissions to a user by specifying the desired username. To specify the user, you can use either the chown command which will change the ownership of a file in Linux. The new owner will have all the access permissions as the previous owner. However, you must be a sudo user or have sudo privileges to apply such changes. File permission denied in Linux. You can see in the following image, the user “anonnya” does not have permission to access the “file1.txt”. In this example, I will give the user “anonnya” permission to run this file by changing the owner. Follow the steps below to do the same.

Steps to Follow >

➊ At first, press CTRL+ALT+T to open the Ubuntu Terminal.

➋ After that, copy the following command:

sudo chown anonnya file1.txt
EXPLANATION
  • sudo: Grants administrative privileges.
  • chown: Changes file ownership.
  • anonnya: Name of the new owner.
  • file1.txt: Name of the file.

➌ Then, press the ENTER button.

➍ Moreover, to check the updated permission run the command below:

cat file1.txt
EXPLANATION
  • cat: Displays file contents on the terminal.
  • file1.txt: Name of the file.

➎ Finally, hit ENTER. Giving user permission with chown command in Linux.In the image above, you can see that I gave permission to the user “anonnya” to access the desired file using chown command.

Method 02: Changing Group to Give Permission to a User in Linux

Apart from giving direct access, you can also give permission to a user through its group. When you allow some group to access the files and folders of your system every member of the group will have the exact access. The chgrp command in Linux can be used to change the group ownership of a file/directory. Moreover, you have to be a sudo user or have sudo privileges to change ownership. File permission denied in Linux. In the above image, you can see the user “anonnya” does not have permission to access the “file1.txt”. I will give the file access to the group “anonnya” so that the user “anonnya” can have permission to run it. Follow the process below to give permission to a user with the help of chgrp command.

Steps to Follow >

➊ At first, go to the Ubuntu Terminal.

➋ After that, copy the following command:

sudo chgrp anonnya file1.txt
EXPLANATION
  • sudo: Grants administrative privileges.
  • chgrp: Changes group ownership.
  • anonnya: Name of the new group.
  • file1.txt: Name of the file.

➌ Then, press the ENTER button.

➍ Furthermore, to check the updated permission run the command below:

cat file1.txt
EXPLANATION
  • cat: Displays file contents on the terminal.
  • file1.txt: Name of the file.

➎ Finally, hit ENTER.Giving user permission with chgrpcommand in Linux. In the above image, you can see that I gave permission to the user “anonnya” to access the desired file through the group “anonnya”.

Method 03: Changing Permission Modes to Give Permission to a User in Linux

You can change Linux file/folder permissions by simply running the chmod command. It does not matter which user or group is the owner of the file/folder. If you give read/write/execute permissions to the other user class using this command, you are giving permission to any user on your system. You may use either the symbolic mode or the absolute mode of permissions to achieve this task.File permission denied in Linux. In the above you can that the user “anonnya” does not have permission to access the “file2.txt”.  I will change this permission to give read, write, and execute access to everyone so the user “anonnya” also has permission.

Steps to Follow >

➊ At first, press CTRL+ALT+T to open the Ubuntu Terminal.

➋ After that, copy any of the following commands:

sudo chmod 777 file2.txt
EXPLANATION
  • chmod: Changes folder permissions.
  • 777: Sets read, write and execute permissions to all user classes.
  • file1.txt: Name of the file.

➌ Then, press the ENTER button.

➍ Additionally, to check the updated permission run the command below:

cat file2.txt
EXPLANATION
  • cat: Displays file contents on the terminal.
  • file1.txt: Name of the file.

➎ Furthermore, view the updated permission modes with the following command:

ls -l
EXPLANATION
  • ls -l: Shows a detailed list along with permissions of the files and folders in the current directory.

Giving user permission with chmod command in Linux.In the above image, you can see that I have given permission to read, write and execute the “file2.txt” file to the user “anonnya” by giving the same access permission to every other user.



Method 04: Modifying ACL to Give Permission to a User in Linux

You can give permission to a user with the setfalc command. In brief, this command is used to modify Access Control Lists (ACLs) for files and directories. While giving permission to a specific user with this command you will need to mention the read/write/execute permissions as well.File permission denied in Linux.In the above image, you can see the user “anonnya” does not have permission to access the “file1.txt”. In this example, I will give my “anonnya” user all the permissions for the “file1.txt” file through ACL. To do the same you can follow the steps below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Then, type the following command:

sudo setfacl -m u:anonnya:rwx file1.txt
EXPLANATION
  • setfacl -m: Sets the file’s Access Control List (ACL).
  • u: Indicates username to add to ACL.
  • anonnya: Name of the new owner.
  • rwx: Adds read, write, and execute.
  • file1.txt: Name of the file.

➌ Now, press the ENTER button.

➍ Additionally, to check the updated permission run the command below:

cat file1.txt
EXPLANATION
  • cat: Displays file contents on the terminal.
  • file1.txt: Name of the file.

Giving user permission with setfalccommand in Linux.In the image above, you can see that I successfully gave permission to the user “anonnya” for accessing the “file1.txt” file by modifying the ACL.

Comparative Analysis of Methods

Since this article introduces multiple methods for a single task, you might get confused about which one to pick. Therefore, in this section, I am presenting a comparative analysis of the three different approaches for your convenience. You can learn the advantages and disadvantages of the available methods and choose which is the best for you.

Methods Pros Cons
Give Direct Permission (Method 1)
  • You can give permission to a specified user.
  • Cannot alter existing permission modes.
  • Use of the chown command on file/folder overwrites the original owner.
  • The chown command cannot change the existing permission mode.
Change Group (Method 2)
  • Permission can be given to a specified user if the user is the only member of some group.
  • Multiple users will have permission if the group contains multiple users.
  • Cannot alter existing permission modes.
  • Use of the chgrp command on file/folder overwrites the original group.
  • The chgrp command cannot change existing permission modes.
Change Permission Modes (Method 3)
  • All the users will have the changed access permission.
  • Permission modes can be updated for any user.
  • Permission to a specific user cannot be given unless the user is the owner or in the owner group.
Modify ACL (Method 4)
  • Preserves previous user permissions.
  • Permission modes can be updated for a specified user
  • May not work on every type of filesystem.

To sum up, it can be said that all methods come with their own pros and cons. Therefore, the suitable method varies from user to user. However, If you want to keep the permission modes unchanged but want to change the owner or the group user then you can adopt Method 1 or, Method 2 as per your requirement.

On the other hand, if you wish to change the permission modes only, then you can go for Method 3. Furthermore, if you are willing to change both the permission modes and the user access then you must choose Method 4.

Complementary Information

While learning about how to give permission to a user in Linux, you will find the below information helpful.

Permission Modes in Linux

From the Linux CLI, changes in folder permissions are achieved by using the chmod command. Moreover, the altered permissions can be represented either in symbolic mode or in absolute mode.

Applying Symbolic mode you can change permissions for any desired user class. Whereas with Absolute mode you have to set permissions for all types of user classes separately. In the section below, you will find detailed information on each of the modes.

A. Symbolic Mode

Using symbolic mode, you can add, remove or set access permissions for a particular user class with logical operators. Since, chmod takes multiple sets of symbols as arguments, changing permissions of multiple user classes requires comma (,) separated logical expressions.

User Class Operator Access Type
u (user) + (add access) r (read)
g (group) – (remove access) w (write)
o (other) = (set exact access) x (execute)
a (all classes: u, g, and o)


B. Absolute Mode

On the other hand, in absolute mode, to remove all permissions you can assign a “0” (zero) or, to give permissions you must assign one of the following octal values for each user class.

Permissions Read

(r)

Write

(w)

Execute

(x)

Read

&

Write

(r+w)

Read

&

Execute

(r+x)

Write

&

Execute

(w+x)

ALL

( r+w+x)

Octal value 4 2 1 6

(= 4+2)

5

(= 4+1)

3

(= 2+1)

7

(= 4+2+1)

Conclusion

To conclude, this article presents you with the possible ways to give permissions to users in Linux. In summary, it includes feasible approaches from CLI with a total of four different commands. Furthermore, I have also illustrated the extensive permission modes in Linux. I hope following this guide will help you through your journey with the command line and make you a power user of Linux.

People Also Ask

How does Linux handle user permissions?
The Linux distribution offers permissions to three types of user classes:  user ( u ), group ( g ), or others ( o ). Therefore, you can give or remove permissions for any of the user classes using the chmod command.
How do I set user permissions?
To set the user permissions for files and folders in Linux you will have to use the chmod command with specific permissions. You can either use symbolic permissions which is a combination of r,w, and x letters. On the other hand, you can use absolute permissions which are octal values from 0 to 7.
What is chmod in Linux?
The “chmod” is command in Linux. Since the word chmod is the short form of Change Mode and is used for changing the access permission modes of files/folders in Linux.
What are the 3 types of permissions?
The 3 types of file permissions in Linux are as follows: read, write, and execute access. Moreover, you will need to use the chmod command for applying permission changes.
How do I check user permissions in Linux?
To check the user permissions for files and folders in Linux you can use the ls command with the option -l. Because it will list all the files and folders in your current directory along with their access permissions for user(u), group (g), or others(o).

Related Articles

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment