Managing File Ownership and Permissions

 <  Day Day Up  >  

Test Objective Covered:

1. Manage the Linux file system.

To this point, we have discussed two elements of the Linux security system: users and groups. Now you'll be introduced to two more elements: file ownership and file permissions.

File Ownership

In a Linux system, every file and directory has an owner. By default, the user who initially creates a file or directory is automatically assigned as its owner.

To see who owns a particular file or directory, you can browse to and right-click it in the GNOME file management utility. Then select Properties , Permissions . The screen shown in Figure 3.9 appears.

Figure 3.9. Viewing ownership.

graphics/03fig09.jpg


In this figure, you can see that the owner of Documents is the rtracy user. The owner of a file or directory can be changed, but only the root user has the ability to do this.

This can be done in the GNOME file management interface shown in Figure 3.9 or from the shell prompt using the chown command.

Tip

To learn how to use chown , enter man chown at the shell prompt .


File Permissions

I've already alluded to the concept of permissions earlier in this chapter. Simply speaking, permissions determine the level of access a user or group has to a file or directory. Linux uses three different basic permissions:

  • Read

  • Write

  • Execute

You need to remember that these permissions can be assigned to a directory or file. The functionality provided by a particular permission varies depending on whether it is assigned to an individual file or to a directory.

The Read permission allows a user to see a file in the file system, open it, and view its contents. For a directory, it allows the user to see the directory in the file system, open it, and view the files or subdirectories it contains.

The Write permission allows the user to modify the contents of a file and save the changes. For a directory, it allows the user to create, delete, or modify a file or subdirectory within the directory.

The Execute permission allows a user to run a file. This is particularly useful when creating script files, which you will do in this chapter's lab exercises.

Permissions to a file or directory are assigned to three different entities:

  • To the file or directory owner

  • To the group assigned to the file or directory

  • To other users

The permissions assigned to the file or directory owner define the level of access the file owner has. The permissions assigned to the group define the level of access granted to users who are members of the group assigned to the file or directory.

Permissions assigned to Others define the level of access granted to users who have successfully authenticated to the system, but who are not the owner of the file or directory and are not members of the group assigned to the file or directory.

You'll see these three permissions referred to simply as Owner , Group , and Other .

Consider the permissions assigned to the example.txt file in Figure 3.10.

Figure 3.10. Permissions.

graphics/03fig10.jpg


The user rtracy created this file and, therefore, is its owner. Notice that Owner is assigned Read and Write permissions to the file. Because of this, user rtracy can open this file, read its contents, modify its contents, and save the changes. The rtracy user can also delete this file.

Notice that the users group has been assigned to the file. This assignment was made because the file owner, rtracy, is a member of the users group. Users who are members of the users group are granted the Read permission to the file. That allows them to open the file and read its contents. However, they can't save any changes to the file. They also aren't allowed to delete the file.

Notice that Others has also been assigned the Read permission. That means any user who logs in to the system but is not a member of the users group also can open the file and read its contents. Likewise, the user is not allowed to save any modifications to the file, nor can he or she delete it.

Let's examine Figure 3.10 a little more closely. Notice underneath the permission assignments the two lines Text view and Number view .

In our graphical computing world, we're a little spoiled with easy-to-read dialogs such as that shown in Figure 3.10. Prior to the X Windows System and GNOME, Linux administrators still had to manage permissions. They did it (and you still can) with Linux command-line utilities. Key among these is the chmod utility.

Every file or directory in the Linux file system has a number assigned to it that represents its permissions.

The chmod utility doesn't accept arguments such as "Read"," "Write"," or "Execute"." Instead, it expects to receive permission assignments in numeric form. In Figure 3.10, you'll notice that the permission assignments made to example.txt are shown as 644. The number 644 is a summary of all permission assignments made.

If you're new to Linux, this may be a little confusing. How does 644 equate to Read and Write to Owner, Read to Group, and Read to Others?

Each digit represents the permissions assigned to each entity. The first digit represents the permissions assigned to the file or directory's owner. The second digit represents the permissions assigned to Group. The last digit represents the permissions assigned to Others. This relationship is shown in Figure 3.11.

Figure 3.11. Permissions in numeric form.

graphics/03fig11.gif


Now that we've identified what the individual digits represent, we need to discuss what the value of each digit represents. You need to understand that each digit is the sum of three values for each permission assigned:

  • Read permission: 4

  • Write permission: 2

  • Execute permission: 1

  • No permissions assigned: 0

Real World

If you've ever used jumpers on the back of a SCSI device to configure its SCSI ID number, this will be familiar to you. With a SCSI device, such as a CD-ROM drive, the ID is the sum of the values assigned to three or four jumpers on the device. Jumper 1 is assigned the value 1, jumper 2 is assigned the value 2, and jumper 3 is assigned the value 4. If you put a shunt on jumpers 2 and 3, the SCSI ID is set to 6. If you put a shunt only on jumper 1, the SCSI ID is set to 1. If you don't put shunts on any jumpers , the SCSI ID is set to 0. Representing permissions in Linux numerically works in the same way.


If a permission is assigned, its value is added to the value of the respective digit. If it isn't assigned, a null value (0) is added to the value of the digit.

This can be a hard concept to understand for many Linux users. Let's look at a few examples.

Notice in Figure 3.11 that Owner has been assigned Read and Write permissions. Execute has not been assigned. The first digit in 644 represents Owner's permissions. The first digit is the sum of the values for the Read and Write permissions:

 

Read:

4

+

Write:

2

+

Execute:

   

_____

=

Permission

6


Also, notice that Group has been assigned only the Read permission. Therefore, the value of the second digit is

 

Read:

4

+

Write:

+

Execute:

   

_____

=

Permission

4


The same applies to the value of the Others digit:

 

Read:

4

+

Write:

+

Execute:

   

_____

=

Permission

4


The result is the permission 644. Let's work through another example. Suppose a file has a permission of 750. What permission has been assigned to each entity?

Let's look at the first permission, 7. The only way to get the value 7 is to assign all permissions, as shown here:

 

Read:

4

+

Write:

2

+

Execute:

1

   

_____

=

Permission

7


We know that the file owner has been granted all permissions to the file in question. The second digit has the value 5. The only way to arrive at 5 is to assign Read and Execute permissions, as shown here:

 

Read:

4

+

Write:

+

Execute:

1

   

______

=

Permission

5


Any user who is a member of the group assigned to the file has Read and Execute permissions to the file. The last digit has the value 0. The only way to arrive at this value is to assign no permissions:

 

Read:

+

Write:

+

Execute:

   

______

=

Permission


Any authenticated user who is not the file owner and who is not a member of the group assigned to the file has no rights at all to the file.

If you were to use the chmod command, you could assign permissions to a file or directory using this numeric permission representation.

For example, if you wanted to assign the owner of example.txt full permissions to the file, but deny everyone else any permissions, you would change to the directory where the file resides and enter chmod 700 ./example.txt .

Earlier, I mentioned that there were two extra lines shown in Figure 3.10. We've examined the Number view line. We now need to turn our attention to the Text view line.

If you're working in a text-based Linux environment, you won't have a fancy tool such as the GNOME file manager to view file and directory permissions. Instead, you can use the ls or dir command.

Real World

Many organizations don't use the X Windows system on their Linux servers. Using a graphical user interface (GUI) on any operating system requires taking time from the CPU. The graphical screen must be periodically refreshed (redrawn). Each time this happens, the CPU's attention is diverted from its current work to service the GUI's requests .


If you enter ls , the contents of the current directory are displayed, as shown in Figure 3.12.

Figure 3.12. Output from ls .

graphics/03fig12.jpg


However, if you use the dir command or the ls -1 command, you will be presented with the current directory contents and the permissions assigned to them, as shown in Figure 3.13.

Figure 3.13. Output from the ls -l command.

graphics/03fig13.jpg


The first column displays the permissions assigned to the particular file or directory. The second column lists the file or directory owner. The third column displays the group assigned to the file or directory.

For example, locate the Documents directory in Figure 3.13. Notice that its permissions are drwxr-xr-x . The owner of Documents is the rtracy user. The group assigned to Documents is users .

Let's focus on the first column. The first character is either d or - . The first character simply identifies whether the item is a directory (d) or a file (-).

The second, third, and fourth characters list the permissions assigned to Owner, as shown in Figure 3.14.

Figure 3.14. Interpreting output from the ls -l command.

graphics/03fig14.gif


In this example, the owner of the public_html directory has Read (r), Write (w), and Execute (x) permissions.

The fifth, sixth , and seventh characters identify the permissions assigned to Group. In this example, Group is assigned the Read (r) and Execute (x) permissions. Permissions not assigned are identified by the - character.

Tip

If you want to change the group assigned to a file or directory, you can use the chgrp command. To learn how to use this command, enter man chgrp at your Linux shell prompt. You can also do this with the GNOME file management utility in the X Windows system interface .


Finally, the eighth , ninth, and tenth characters specify the rights assigned to Others. In Figure 3.14, Other has been assigned the Read (r) and Execute (x) permissions.

 <  Day Day Up  >  


Novell Certified Linux Engineer (CLE) Study Guide
Novell Certified Linux Engineer (Novell CLE) Study Guide (Novell Press)
ISBN: 0789732033
EAN: 2147483647
Year: 2004
Pages: 128
Authors: Robb H. Tracy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net