Key concepts and commands for managing permission on a Macintosh in the CLI interface.
- ls -alh; to list a directory.
- d or "-" indicates directory or file respectively.
- rwx; first the owner, then group, then world's permissions.
- "+" or "@" indicates ACL's or extended attributes respectively.
- ls -e; view the ACL's of an item.
- chown; change ownership. To change the owner and group associated with a file or folder.
- sudo chown user:group path/to/item
- chmod; change permissions. Two ways of notating this command.
- u for owner, g for group, o for everyone.
- ug=rwx,o=r yields read, write, execute for owner and group but read-only for everyone.
- octal notation: 0 for no access, 1 for execute only, 2 for write-only, 4 for read-only.
- 777=control for everyone.
- 755=control for owner, read-write for group and everyone.
- 644=read-write for owner, read-only for group and everyone.
- 444=read-only for all.
- 440=read-only for owner and group, nothing for everyone. This is very secure and is still useful.
- t; as the last item in the permissions list a "t" means the "sticky bit" is set. The "sticky bit" is applied to a folder and it means that only the owner of the item inside can delete it.
- chmod +t path/to/item
- chmod -R +t path/to/folder, to add sticky bit to all items inside.
- chmod -t path/to/item, to remove sticky bit.
- chmod -R-t path/to/folder, to remove the sticky bit from the folder and contents.
- Locked files cannot be changed even with sudo. Use the chflags to check the lock flag.
- ls -lO path/to/item, that is a cap "o", will show the "uchg" in the item listing.
- sudo chflags nouchg path/to/item to remove the lock.
- sudo chmod -N path/to/item; to clear ACLs from an item.
- sudo /usr/libexec/repair_packages --list-standard-pkg; will list all items that repair permissions will work on. Repair permissions does not work on anything else including user data, applications, etc.