Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

This chapter is from the book

Managing Permissions via Command Line

Viewing and modifying file system permissions in the command line is both much richer and more complicated than in the Finder. The Finder has streamlined ownership, permissions, and ACLs, providing only the most common features that users require. However, the command line offers every conceivable ownership and permissions option. Further, the command line often provides more than one method for performing identical permissions tasks.

Viewing Traditional UNIX Permissions

Once again, the ls command is your primary tool for viewing file and folder information in the command line. The ls command has many options for viewing nearly any file or folder attribute. You can learn more about all the options available to ls from its manual entry page. Here, you will be presented with a few fundamental permissions viewing options.

The most basic ls option for viewing file and folder ownership and permissions is –l:

MyMac:~ michelle$ ls -l
total 0
drwx------+ 5 michelle staff 170 Aug 20 15:49 Desktop
drwx------+ 3 michelle staff 102 Aug 20 01:08 Documents
drwx------+ 3 michelle staff 102 Aug 20 01:08 Downloads
drwx------ 19 michelle staff 646 Aug 20 01:08 Library
drwx------+ 3 michelle staff 102 Aug 20 01:08 Movies
drwx------+ 3 michelle staff 102 Aug 20 01:08 Music
drwx------+ 4 michelle staff 136 Aug 20 01:08 Pictures
drwxr-xr-x+ 7 michelle staff 238 Aug 20 15:29 Public
drwxr-xr-x 5 michelle staff 170 Aug 20 01:08 Sites

The first string of characters at the beginning of each line is shorthand for the item type and permissions. The following information appears from left to right: the number of hard links associated with the item (for most users, this particular bit will be trivial information), the assigned owner, the assigned group, the last modification date, and finally the item’s name.

The syntax for the abbreviated information section is:

  • The first character is item type: - for file, d for folder, and l for symbolic link.
  • The next three characters indicate the owner’s permissions: - for no access, r for read access, w for write access, and x for file execute access or folder browsing access.
  • The middle set of three rwx or - characters indicate the group’s permissions.
  • The final set of three rwx or - characters indicate everyone else’s permissions.
  • Optionally, there may be a + at the end to indicate that the item has ACL rules applied to it, or an @ at the end to indicate that the item has extended attributes.

The execute privilege attribute x has not been introduced yet, but it is the third standard UNIX privilege attribute after read and write. The execute privilege is enabled on files that are commands and applications (or folders that contain application bundles), to indicate that the item contains executable software code. The execute privilege is also required on normal folders to access the contents of the folder. The Finder doesn’t show you when the execute privilege is used, but it will properly manage the execute privilege when you make permissions changes using the Get Info window.

Viewing Access Control Lists (ACLs)

The ACL technology is more advanced than traditional UNIX-style permissions because it allows for an arbitrary number of user and group permissions rules per item. Each permissions rule is known as an Access Control Entry (ACE). Every file and folder on the system can have an unlimited list of ACE rules, hence the “list” in ACLs.

From the command line, Mac OS X’s ACL implementation provides more than a dozen unique privilege attribute types and lets you define each as a specific allow or deny rule. In other words, you can assign an item an unlimited number of user or group rules, or ACEs, which can be used to allow or deny any of the following privilege attributes:

  • Administration—Administration attributes, which define a user’s or group’s ability to make permissions changes, include change privileges and change ownership.

  • Read—Read attributes define a user or group’s ability to read items and include read attributes, read extended attributes, read file data or list folder contents, execute file or traverse folder, and read permissions.

  • Write—Write attributes define a user’s or group’s ability to make changes and include write attributes, write extended attributes, read file data or create files in folder, append file data or create new subfolder inside folder, delete item, and delete subfolders and files.

Furthermore, each ACE for a folder can include a static inheritance rule that defines whether the folder’s permissions also apply to new items placed in the folder. Inheritance attributes include the following: no inheritance, apply to just new items in this folder, apply to any new child folders, apply to any new child files, and apply to all descendants of this folder.

To view an item’s ACLs alongside their permissions, simply add the -e option to the -l option:

MyMac:~ michelle$ ls -le
total 0
drwx------+ 5 michelle staff 170 Aug 20 15:49 Desktop
 0: group:everyone deny delete
drwx------+ 3 michelle staff 102 Aug 20 01:08 Documents
 0: group:everyone deny delete
drwx------+ 3 michelle staff 102 Aug 20 01:08 Downloads
 0: group:everyone deny delete
drwx------ 19 michelle staff 646 Aug 20 01:08 Library
drwx------+ 3 michelle staff 102 Aug 20 01:08 Movies
 0: group:everyone deny delete
drwx------+ 3 michelle staff 102 Aug 20 01:08 Music
 0: group:everyone deny delete
drwx------+ 4 michelle staff 136 Aug 20 01:08 Pictures
 0: group:everyone deny delete
drwxr-xr-x+ 7 michelle staff 238 Aug 20 15:29 Public
 0: group:everyone deny delete
drwxr-xr-x 5 michelle staff 170 Aug 20 01:08 Sites

Modifying File Permissions via Command Line

You will use two primary commands for changing file and folder permissions in the command line: chown for changing ownership and chmod for changing privileges.

Changing Ownership via Command Line

Short for “change ownership,” chown will let you change the owner and group associated with a file or folder. Using chown often requires root access, so this command is almost always preceded by the sudo command. To use chown, enter the new owner’s name, followed optionally by a colon and the new group name, and then finish with the item’s path. In the following example, Michelle will use the chown command to change testfile1’s ownership to the user account “kevin” and the group account “admin.”

MyMac:~ michelle$ ls -l Desktop/
total 0
-rw-r--r-- 1 michelle staff 0 Aug 20 15:49 testfile1
drwxr-xr-x 4 michelle staff 136 Aug 20 15:47 testfolder
MyMac:~ michelle$ sudo chown kevin:admin Desktop/testfile1
Password:
MyMac:~ michelle$ ls -l Desktop/
total 0
-rw-r--r-- 1 kevin admin 0 Aug 20 15:49 testfile1
drwxr-xr-x 4 michelle staff 136 Aug 20 15:47 testfolder

Changing Privileges via Command Line

Short for “change file mode,” chmod will let you change the privileges associated with a file or folder. Using chmod on files you don’t own requires root access, so the chmod command is often preceded by the sudo command. To use chmod, enter the new privileges first followed by the item’s path.

As for changing privileges, there are two basic methods when using the chmod command:

  • Using alphanumeric abbreviations—The basic syntax goes: account type, modifier, and then privilege. Account types include u for owner, g for group, and o for everyone else. Modifiers include + for allow, - for deny, and = for exact setting. Privileges are as expected with r for read, w for write, and x for execute or folder access. For example, if you’re using this method to allow full access for the owner and group but read-only access for everyone else, you’d enter ug=rwx,o=r.

  • Using octal notation—As you can see, chmod extensively uses shortcuts and abbreviations. To save even more keystrokes you can use octal notation, which uses numeric abbreviations for defining privileges. The basic syntax for octal notation is to use a single-digit number for the user first, followed by a single number for the group, and then a last single number for everyone else. Octal notation uses 0, for no access; 1, for execution only; 2, for write-only; and 4, for read-only. To use mixed permissions, simply add the numbers together. For example, if you’re using this method to allow for full access to a folder for the owner and group but read-only access for everyone else, you’d type 775.

In the following example, Michelle will use the chmod command to change the permissions of testfile1 and testfolder to allow read and write access for the owner and the group but read-only access for everyone else. She will first use alphanumeric abbreviations, and then octal privilege equivalents.

MyMac:~ michelle$ ls -l Desktop/
total 0
-rw-r--r-- 1 michelle staff 0 Aug 20 15:49 testfile1
drwxr-xr-x 4 michelle staff 136 Aug 20 15:47 testfolder
MyMac:~ michelle$ chmod ug=rw,o=r Desktop/testfile1
MyMac:~ michelle$ ls -l Desktop/
total 0
-rw-rw-r-- 1 michelle staff 0 Aug 20 15:49 testfile1
drwxr-xr-x 4 michelle staff 136 Aug 20 15:47 testfolder
MyMac:~ michelle$ chmod 775 Desktop/testfolder/
MyMac:~ michelle$ ls -l Desktop/
total 0
-rw-rw-r-- 1 michelle staff 0 Aug 20 15:49 testfile1
drwxrwxr-x 4 michelle staff 136 Aug 20 15:47 testfolder

Using the Sticky Bit

As mentioned previously in this chapter, the /Users/Shared folder has a unique permission setting that allows all local users to read and write items into the folder yet prevents other users from being able to delete files that they didn’t originally put in this folder. This special permissions configuration is brought to you courtesy of the “sticky bit.” Essentially, enabling the sticky bit on a folder defines it as an append-only destination, or, more accurately, a folder in which only the owner of the item can delete the item.

You can clearly see the sticky bit setting of the /Users/Shared folder when you view its ownership and permissions. Note the t on the end of the permissions information, which indicates that the sticky bit is enabled:

MyMac:~ michelle$ ls -l /Users/
total 0
drwxrwxrwt   7 root     wheel  238 Aug 10 18:49 Shared
drwxr-xr-x+ 16 cadmin   staff  544 Aug 17 00:10 cadmin
drwxr-xr-x+ 16 logan    staff  544 Aug 19 00:06 logan
drwxr-xr-x+ 17 kevin    staff  578 Aug 17 00:14 kevin
drwxr-xr-x+ 15 michelle staff  510 Aug 20 16:43 michelle

You can enable sticky bit functionality similar to the /Users/Shared folder on any other folder using a special octal notation with the chmod command. In the following example, Michelle has already created a new folder named NewShared. She then uses the chmod command with +t to set sharing for all users with sticky bit functionality:

MyMac:~ michelle$ chmod -R +t NewShared/
MyMac:~ michelle$ ls -l
total 0
drwx------+ 5 michelle staff 170 Aug 20 15:49 Desktop
...
drwxrwxrwt 2 michelle staff 68 Aug 20 17:20 NewShared
...

Managing Locked Items via Command Line

As mentioned previously, Mac OS X includes a special file system lock feature that prevents anyone but the owner of an item from making changes to that item. Any user can easily lock a file or folder he owns from the Finder’s Get Info window, also covered earlier in this chapter.

The problem with the file system lock is that the Finder prevents even other administrative users from making changes or even unlocking items they don’t own. In fact, this file system lock extends to the command line as well. Even with sudo access, an administrator is not allowed to change a locked item—with one important exception, the chflags command. This command allows the administrator to change file system flags, which among other things allows you to lock or unlock any file or folder on the system.

In the following example, Michelle needs to change the permissions of a folder owned by another user so the folder can be shared. However, even using sudo she is denied access from doing this, indicating the file is locked. She verifies this by using ls –lO to view the file listing with file flags, which indeed returns that the folder is locked, “uchg”. She then uses the chflags command with the nouchg option to unlock the folder. Finally, she is able to make changes to the previously locked file.

MyMac:Shared michelle$ sudo chmod go+rx SecureFolder/
chmod: Unable to change file mode on SecureFolder/: Operation not permitted
MyMac:Shared michelle$ ls -lO
total 0
drwx------  7 cadmin  wheel  -     238 Jul  7 13:18 AnotherFolder
drwx------  7 cadmin  wheel  uchg  238 Jul  7 13:18 SecureFolder
MyMac:Shared michelle$ sudo chflags nouchg SecureFolder/
MyMac:Shared michelle$ sudo chmod go+rx SecureFolder/
MyMac:Shared michelle$ ls –lO
total 0
drwx------  7 cadmin  wheel  -     238 Jul  7 13:18 AnotherFolder
drwxr-xr-x  7 cadmin  wheel  -     238 Jul  7 13:18 SecureFolder

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit 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 Peachpit 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 ask@peachpit.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 Adobe Press. 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.peachpit.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