Managing access to resources is a fundamental task for sysadmins. This responsibility consists of three components: identities, resources, and permissions. This article covers several user, group, and file management commands to control access to resources. The article uses a "How do I…?" format, and it assumes you have a few resources to work with. Specifically, I cover the following topics: Show
Setting up a playgroundI've been in IT for about 25 years, and most of that time was spent as a technical trainer. That means that the things that I write are usually structured as some sort of lab or other hands-on opportunity. It's just how I cover material. With that in mind, I'll assume you have a couple of identities and resources to experiment with as you read the rest of the article. You can use the following commands to set up a playground. It's best to do this on a virtual machine rather than your personal Linux box, but these tasks are relatively harmless. Create two new users and two new groups to work with. Note that you do not need to configure passwords for the users in this exercise, as you won't log on with those accounts.
Note: You would use the [ Want to test your sysadmin skills? Take a skills assessment today. ] In your home directory, create a new directory named
Change into the When you've completed the article and learned the techniques I've covered, delete the two user accounts, the groups, and
the playground directory. Use How do I create directories and files?Use the How do I create a directory named
How do I create a directory path (a series of directories that don't yet exist)?
Note: The goal here is to create the How do I create a file named
How do I create several files at once?
How do I manage ownership and groups?In the playground directory, display the current owner and group associated with the How do I display permission, owners, and groups?
The [ Free download: Advanced Linux commands cheat sheet. ] How do I change the user/owner associated with
How do I change the group associated with
How do I change the owner and group at the same time for
There is a specific So how do I use
How do I change the user/group for a directory and all of its contents?
The above task provides a recursive configuration. Technically, recursive commands are repeated on each specified object. Effectively, recursive means "this and everything in it." In the above example, you are configuring the related user/group for the [ Readers also liked: An introduction to Linux Access Control Lists (ACLs) ] How do I manage permissions?The change mode or
Here are two examples of manipulating permissions for
But wait! Those appear to be radically different examples (they're not, actually). What are all those letters and numbers? We need to discuss absolute mode and symbolic mode. How do I use absolute mode?Absolute mode is one of two ways of specifying permissions. I've seen this mode referred to as octal or numeric mode, but the term I learned was absolute. That term also makes the most sense to me because it's an absolute statement of the desired permissions. I always told my students that this seemed like the most complex of the two modes but is actually the simplest. Usually, they agreed. Each access level (read, write, execute) has an octal value:
Each identity (user, group, others) has a position:
The absolute mode syntax states the desired permissions from left to right. How do I grant the user (owner) read, write, and execute, the group read-only, and all others no access to
The three permissions values are associated with identities:
In this example, the user has rwx, the group has r only, and all others have no access to Let's look at one more example. How do I grant the user (owner) read and write, the group read-only, and all
others read-only to
I find this easier because there are no calculations involved. I'm not concerned with adding or subtracting specific permissions based on the current settings. Instead, I say, "set the permissions to be this," and that's the end result I get. It's an absolute statement. [ Free cheat sheet: Get a list of Linux utilities and commands for managing servers and networks. ] How do I set permissions for the
How do I use symbolic mode?Symbolic mode uses more symbols, but the symbols are simpler to understand. That's attractive to sysadmins that are new to standard Linux permissions. Each access level has a symbol:
Each identity has a symbol:
There are also operators to manipulate the permissions:
The general
Here is an example: How do I remove the read permissions from others for
This example removes ( Here's another simple example: How do I grant the read and write permissions to the group for
This one gives ( How do I set permissions for a directory and all of its contents by using symbolic mode?
Special permissions and Access Control ListsThe above discussion covers standard Linux permissions—applying rwx to the user, group, and all others. Linux has far more flexibility, however. Special permissions permit users to run applications with other credentials, control the inheritance of group associations, and keep files from being changed accidentally. Check out this great article on special permissions. Linux also has a way of enforcing different permissions for different users and groups. Access Control Lists (ACLs) permit sysadmins to define permissions for more than just one user and one group, which adds a great deal more flexibility to standard permissions. For example, [ Free course: Red Hat Satellite Technical Overview. ] Wrap upCreating resources, managing users, and setting permissions are fundamental tasks for Linux users. My goal was to provide a quick and easy guide based on common questions or tasks that we must all accomplish regularly. If you're new to Linux, having a solid grasp of the eight commands discussed above will make your sysadmin life much easier. Which of the following commands is used to change the ownership and primary group assigned to a file or directory?Changing group ownership of a file or directory - chgrp
Use chgrp as shown here to change ownership of a file or directory to a different group. To change group ownership of a directory and all of the files and subdirectories in that directory, use chgrp recursively.
What is the command for change ownership and permissions?Use the chown command to change file owner and group information. we run the chmod command command to change file access permissions such as read, write, and access.
Which command you will use to change the owner and group of test?chown command is used to change the file Owner or group. Whenever you want to change ownership you can use chown command. Syntax: chown [OPTION]…
Which of the following commands can be used to change both the owner and group settings of a file?The chown command changes the owner of a file, and the chgrp command changes the group. On Linux, only root can use chown for changing ownership of a file, but any user can change the group to another group he belongs to. The plus sign means “add a permission,” and the x indicates which permission to add.
|