Give one user permissions linux

How to Give a User Permission to a Folder in Linux?

In Linux, you will find several remarkable security features that allow it to be on the list of the most secure operating systems. One is file or directory permissions granted to users to read, write, or create the files/directories on the system. This is used widely in organizations because there are so many employees and not all have permission to alter, read, create, or delete important files. How can you give a user permission to a folder in Linux? This is the question for today.

This guide is about user permissions on a folder in Linux, and after going through it, users will understand the following aspects.

Let’s get started with the permissions!

What are User Permissions, and How do you Check them in Linux?

While accessing the files, you must have noticed the error “Access Denied,” which means that you don’t have permission to view the contents of it. This is because the owner of that file or directory did not share or permit you to view them. To check the permissions associated with a folder, use the “ls -ld” command in this format.

Here’s a folder named “Test” whose permissions are to be checked.

How to Give Permission to Directory Using the setfacl Command?

To change the user permissions of a directory or a file, the ‘setfacl’ command is used in this format.

$ sudo setfacl -m u:username:rwx myfolder

Here, “-m” stands for modification, followed by “u,” which means username. The “rwx” are permissions (read, write, and execute), and “myfolder” is the name of the directory. Here’s an example of it.

$ sudo setfacl -m u:newuser:r Test

The above command allows the “newuser” to have read access to the folder “Test.” To confirm this, execute this command.

The above command displays the information regarding the permissions, and “newuser” now has the read permissions.

You can also grant permissions to a group that is a collection of users with the same access permissions. Groups manage access to resources such as files, directories, and devices. Here’s how the users can do it using the setfacl command.

In the above command, the “g” mentions the group, and “dev” is the group’s name, while the “rwx” are the permissions, and “folder” is the name of the directory. It can be confirmed using this command.

As seen above, the dev group now has the read, write and execute permissions.

If you use the “-R” flag, such as below, you can also change permissions for directories and their subdirectories.

$ setfacl -R -m u:newuser:rx Music

After executing the above command, “newuser” now has the read & execute (rx) permissions on “Music” directory and all its sub-directories. For confirmation, use this command.

Читайте также:  Командная строка linux справочник

iTunes is a subdirectory of Music on which the “newuser” has permission to read and execute (r&x).

How to Give Permission for Directory Using the chmod Command?

The chmod comes up with two variants, i.e., one is the symbolic representation, and the other is the octal. For better understanding, we will elaborate on both methods.

Using the Symbolic Notation

The symbolic notation specifies file permissions using characters instead of numbers. Using symbolic notation, you can select the permissions you want to set for the owner (u), group (g), others (o), or all (a) of a file or directory. You can also use the + or – signs to add or remove permissions and r, w, and x to represent the read, write, and execute permissions, respectively.

Syntax:

$ chmod symbolic_notation file

Example:

This syntax is used to give a user permission to a folder using the symbolic notation of the chmod command.

This will give the user read, write, and execute permissions (+rwx), read and execute permissions to the user’s group (+rx), and no permissions (-rwx) to others which can be confirmed using this command.

The above command, when executed, the user reads, writes, and executes permissions (+rwx), reads and executes permissions to the user’s group (+rx), and no permissions (-rwx) to others.

Using Octal Notation

The octal notation is based on the combination of three numbers used to represent the permissions for the owner, group, and others. Each digit corresponds to the read, write, and execute permissions in that order as shown below:

The chmod 755 commands will set the permissions on the “testfolder” directory to allow the owner to have all permissions, including read, write, and execute the directory, and let everyone else read and execute the directory.

Here’s what the numbers mean.

Note: Only the chmod command can be used by the owner of the file or folder or by a user with superuser privileges.

Conclusion

The permissions that can be set on a folder/directory can be set, and other users can also read, write, or execute. There are two methods you can use, and we’d recommend using the setfacl command because it allows the owner to set permissions for a group or specific users.

Источник

How I Give a User Permission to a Folder in Linux

Privacy is an essential part of someone’s life, whether social media or the workplace. It helps protect the personal and professional data that we don’t want to share with everybody. Sometimes, people work on sensitive data that couldn’t be shared inside or outside the firm.

Similarly, when multiple users are connected with the system, they may need some private access to the specific resources. If we talk about files or folders/directories permission, it means you allow them to read, write, or modify the files or directories. It is essential to revert the ownership of files/folders from the users who are not part of your current account but can own them.

It is assumed as challenging for a Linux user to access permission to a file or folder because they are a bit aware of it. Setting the permission to the specific folder is quite simple and can be done via command-line or GUI (we will later discuss how we can do it).

Читайте также:  Alt linux epm repack

There are two levels in the Linux system for authorization that you must need to understand:

Let’s explain both of them to understand what categories they are further divided into:

Ownership:

If we talk about ownership of files or folders in the Linux operating system, they are split into 3 types:

The user-created the folder, and that’s why sometimes we claimed it as an owner. It is represented as “u” in the command line when giving access through commands.

A group contains several Linux users connected to a system having the same permission access. It is helpful when many users use the system and give them folder permission to access it. You can make a group to add all of them instead of allowing them individually. In this case, people other than the group couldn’t be able to access the folder. The representative form of group members in the Linux command-line is “g.”

The other category includes public users that are not part of group members or ownership. If you are permitting the others, we can say you are allowing everybody in the world to access the files/folders. Sometimes, it could be dangerous, so think twice before doing it. The public users are represented by “o”:

Permission:

There are 3 types of permission you can give to the owners we have mentioned below:

In the read (r) mode, a user can open a file/folder and read it, whereas the write (w) mode allows making changes in the file/folder. You have the authority to add content, remove or rename it.

Without executing (x) permission, you can only read and write to the file, but you can’t run it. To make the file executable, set the execute permission.

How to give the user permission to a folder in Linux:

You can give permission access to the user using a couple of approaches, via terminal and GUI.

Before directly jumping into it, note the specific commands to change permission and ownership.

  • chmod command is used to modify permission
  • chown command is used to modify ownership

How to give the user permission to a folder via command-line:

You can set permissions like read, write, or execute the folder through the “chmod” command in a terminal.

You can use the “chmod” command to modify permission settings in two different ways:

The difference between Absolute mode and symbolic mode is that in the Absolute mode, you can set permissions for all the owners (user, group, others) using the three-digit octal number instead of characters. Whereas in the symbolic mode, you can set permission through mathematical symbols and only for the specific owner.

Let’s demonstrate both of them:

Give user access to a folder through absolute mode:

To understand how we can give permission access to a folder through absolute mode, we need to understand the given table in which numbers are mentioned for all the permission types.

Numbers Permission Types Symbols for Permission
0 No Permission
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read + Write rw-
7 Read + Write + Execute Rwx

Let’s run an example to check how it is working:

To display the current permission settings of the folder “Testing_folder,” run the following command:

Читайте также:  Linux use tar file

  • First rw– represents🡪 a user (owner) who can read or write/edit the file but couldn’t be able to execute it since execute mode is set to “-.”
  • The second rw– represents 🡪 a group (all the users added to the group) that can read or write/edit the file.
  • The third r— represents 🡪 others (public) who can only read the file

Now execute the chmod command to change permission access:

(760 🡪 owners can read, write or execute the file, the group can read and write, and there is no access for the public users)

Run the “ls” command to check the modification:

Give user access to a folder through symbolic mode:

Three operators are used in symbolic mode to set permission:

Operator Function
+ Add permission
Remove permission
= Set the permission and override the previous permission settings

As we have mentioned in the introductory part that how to represents owners. So, let’s start with an example:

Check the current permission setting of “Testing_folder” using the mentioned “ls” command:

To set permission to the user (owner), the command would be:

Now, execute the “ls” command to get the output:

To remove read permission from the user, run the command:

Now, execute the “ls” command to get results:

How to give a user permission to a folder via GUI:

Changing the file permission using the GUI is the simplest approach. Follow the listed steps:

Open the home directory, and navigate towards the targeted folder.

For example, to change the permission access to a folder “testing,” firstly, select it:

Right-click on the “testing” folder and select “Properties”:

The “Properties” window will appear with 3 tabs:

Navigate to the “Permissions” tab and select it:

From this tab, you can make changes according to the requirement.

Click on the “Change Permission for Enclosed Files,” and you will get a window that allows the user to modify the permission mode, i-e read and write mode for the owners:

Suppose the current permissions status of the “testing” folder is given below:

Let’s open the “change permissions” window and modify the entries as:

Navigate to the “change” button and click it.

Now, confirm using the “ls” command again in the terminal if changes have been made successfully.

Conclusion:

Set permission access to the files or folders is compulsory nowadays for security reasons because someone who is no longer a part of your system may also have folder access. To get control the security issues and keep the files safe, you can set permissions.

There are three categories of ownership i-e user, group, and others. And also, we have 3 types for permission settings such as read, write and execute.

You can give a user permission to the folder in two ways; via command-line and GUI. The GUI approach is better, in my opinion, as it is a pretty straightforward and simple way to set permissions.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.

Источник

Оцените статью
Adblock
detector