MFH Labs : Manage Linux permissions for users, groups, and others

How do I manage ownership and groups?

In the playground directory, display the current owner and group associated with the Resources directory and the files.

How do I display permission, owners, and groups?

# ls -l

The ls -l command displays directory contents in long format. The long format contains both permissions and ownership. You can see that the user account that created the resources also owns those resources. The group association is also that user’s primary group.

How do I change the user/owner associated with file1?

# chown user02 file1

How do I change the group associated with file1?

# chown :groupA file1

How do I change the owner and group at the same time for file2?

# chown user02:groupA file2

There is a specific chgrp command, but I prefer only to memorize one command (chown) and apply it to both functions (user and group associations) rather than chown for the user and then have to recall chgrp for the group.

So how do I use chgrp?

# chgrp groupB file1

How do I change the user/group for a directory and all of its contents?

# chown -R user01:groupA Resources

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 Resources directory and everything in it. Without the -R option, you would only affect the Resources directory itself, but not its contents.

How do I manage permissions?

The change mode or chmod command sets permissions. The syntax is straight-forward:

chmod permissions resource-name

Here are two examples of manipulating permissions for file2:

# chmod 740 file2
# chmod u=rwx,g=r,o-rwx file2

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:

Access levelOctal value
Read4
Write2
Execute1

Each identity (user, group, others) has a position:

IdentityPosition
UserFirst or left-most
GroupMiddle
OthersLast or right-most

More Linux resources

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 file2 by using absolute mode?

# chmod 740 file2

The three permissions values are associated with identities:
    ugo
    740

  • The 7 is assigned to the user and is the sum of 4+2+1 or read+write+execute (full access)
  • The 4 is assigned to the group and is the sum of 4+0+0 (read-only)
  • The 0 is assigned to others and is the sum of 0+0+0 (no access)

In this example, the user has rwx, the group has r only, and all others have no access to file2.

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 file2?

# chmod 644 file2
  • The user has 6 (read and write)
  • The group has 4 (read-only)
  • All others have 4 (read-only)

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.

How do I set permissions for the Resources directory and all of its contents by using absolute mode?

# chmod -R 744 Resources

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:

Access levelSymbol
Readr
Writew
Executex

Each identity has a symbol:

IdentitySymbol
Useru
Groupg
Otherso

There are also operators to manipulate the permissions:

TaskOperator
Grant a level of access+
Remove a level of access
Set a level of access=

The general chmod command syntax is the same:

command permissions directory/file

Here is an example:

How do I remove the read permissions from others for file2 by using symbolic mode?

# chmod o-r file2

This example removes (-) the read (r) permission from others (o) for file2.

Here’s another simple example:

How do I grant the read and write permissions to the group for file2?

# chmod g+rw file2

This one gives (+) read and write (rw) to the group (g) for file2.

How do I set permissions for a directory and all of its contents by using symbolic mode?

# chmod -R o=rwx,g+rw,o-rwx Resources

Special permissions and Access Control Lists

Download now

The 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.

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, user01 can be granted rw- to file1, while user02 can be granted r– to file1.