Home > Articles

  • Print
  • + Share This
This chapter is from the book

Managing File Ownership and Permissions

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.9Figure 3.9 Viewing ownership.

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.10Figure 3.10 Permissions.

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.11Figure 3.11 Permissions in numeric form.

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

NOTE

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:

0

=

Permission

6


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

 

Read:

4

+

Write:

0

+

Execute:

0

=

Permission

4


The same applies to the value of the Others digit:

 

Read:

4

+

Write:

0

+

Execute:

0

=

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:

0

+

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:

0

+

Write:

0

+

Execute:

0

=

Permission

0


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.

NOTE

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.12Figure 3.12 Output from ls.

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

Figure 3.13Figure 3.13 Output from the ls –l command.

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.14Figure 3.14 Interpreting output from the ls –l command.

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.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020