ops102:permissions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ops102:permissions [2024/01/24 04:23] – [Setting Permissions] chris | ops102:permissions [2024/05/28 21:27] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 6: | Line 6: | ||
There are two broad categories of access controls applied to files and directories: | There are two broad categories of access controls applied to files and directories: | ||
* Discretionary Access Controls (DACs) - these are access controls that can be set to any value at the discretion of the users or administrators of the computer system. | * Discretionary Access Controls (DACs) - these are access controls that can be set to any value at the discretion of the users or administrators of the computer system. | ||
- | * Mandatory Access Controls (MACs) - these are access controls that are applied across the entire system in a uniform way, and cannot be individually overridden by the users or administrators. An example of a Mandatory Access Control system is SELinux (security-enhanced Linux), a system originally developed by the National Security Agency of the US Federal Government and now part of the Linux Kernel (via KSM - Kernel Security | + | * Mandatory Access Controls (MACs) - these are access controls that are applied across the entire system in a uniform way, and cannot be individually overridden by the users or administrators. An example of a Mandatory Access Control system is SELinux (security-enhanced Linux), a system originally developed by the National Security Agency of the US Federal Government and now part of the Linux Kernel (via KSM - Kernel Security |
In this OPS102 course, we will be looking only at DACs. | In this OPS102 course, we will be looking only at DACs. | ||
Line 19: | Line 19: | ||
* **User** -- the one user that owns the file | * **User** -- the one user that owns the file | ||
- | * **Group** -- the group of users that is the group-owner of the file | + | * **Group** -- the group of users that owns the file |
* **Other** -- every other user of the computer system | * **Other** -- every other user of the computer system | ||
These communitities are presented in this order, so remember the sequence!: User - Group - Other (u g o) | These communitities are presented in this order, so remember the sequence!: User - Group - Other (u g o) | ||
+ | |||
+ | Note that each file has both an individual user and a group owner. The '' | ||
==== Permissions | ==== Permissions | ||
Line 37: | Line 39: | ||
* **Read** -- the ability to //see// the names of the files and subdirectories within the directory. This is also called " | * **Read** -- the ability to //see// the names of the files and subdirectories within the directory. This is also called " | ||
- | * **Write** -- the ability to create/ | + | * **Write** -- the ability to create/ |
- | * **eXecute** -- the ability to access files with the directory. If turned off, the files cannot be accessed, and metadata about each file (such as the owner, group owner, file length, permissions, | + | * **eXecute** |
+ | |||
+ | If execute permission is enabled for a directory but read permission has not been enabled, the affected community cannot view a directory listing to determine filenames, but if they know the name of a file within that directory, they may still access it. | ||
+ | |||
+ | If read permission is enabled for a directory but execute permission has not been enabled, the affected community can view the names of files in a directory (but only the names, not permissions, | ||
+ | |||
+ | However, read and execute permission are almost always assigned to a directory together. | ||
- | If execute permission is enabled for a directory but read permission has not been enabled, the affected community cannot view a directory | + | In order to access |
- | In order to access a file, a user must have execute permission on __all__ of the directories from the root directory to the directory containing the file. For example, on the file ''/ | ||
==== Viewing Permissions | ==== Viewing Permissions | ||
Line 58: | Line 65: | ||
< | < | ||
| | ||
- | | + | |
| | ||
Line 91: | Line 98: | ||
$ ls -l -d / # displays the root directory itself | $ ls -l -d / # displays the root directory itself | ||
| | ||
+ | |||
+ | You can also view permissions as an [[# | ||
+ | |||
+ | < | ||
+ | $ stat /etc/hosts | ||
+ | File: /etc/hosts | ||
+ | Size: 386 | ||
+ | Device: 253, | ||
+ | Access: (0644/ | ||
+ | Context: system_u: | ||
+ | Access: 2024-01-23 16: | ||
+ | Modify: 2022-11-27 10: | ||
+ | Change: 2023-05-30 03: | ||
+ | | ||
==== Setting Permissions | ==== Setting Permissions | ||
Line 100: | Line 121: | ||
In either case, the command accepts the mode as the first positional argument, and the filename(s) (or patterns) as the remaining positional arguments: | In either case, the command accepts the mode as the first positional argument, and the filename(s) (or patterns) as the remaining positional arguments: | ||
- | < | + | '' |
- | chmod //mode// // | + | |
=== Using Symbolic Mode === | === Using Symbolic Mode === | ||
Line 129: | Line 149: | ||
x (execute - note that this is lowercase) | x (execute - note that this is lowercase) | ||
X (execute if applied to a directory, or nothing if applied to a file -- note that this is UPPERCASE)</ | X (execute if applied to a directory, or nothing if applied to a file -- note that this is UPPERCASE)</ | ||
+ | |||
+ | Therefore the symbolic notation '' | ||
Here is an example: | Here is an example: | ||
Line 236: | Line 258: | ||
$ ls -l example001 | $ ls -l example001 | ||
| | ||
+ | |||
+ | === Recursively Setting Permissions === | ||
+ | |||
+ | It is sometimes useful to use the chmod '' | ||
+ | |||
+ | # Don't do this! It will set Execute permission on files and directories. | ||
+ | chmod -R go+rx publicdir | ||
+ | | ||
+ | # Instead, do this: it will set Execute permission on directories only, and not on files | ||
+ | # (Notice the capital X in the symbolic permissions) | ||
+ | chmod -R go+rX publicdir | ||
+ | |||
+ | === Other useful chmod Options === | ||
+ | |||
+ | < | ||
+ | -v Verbose: show information about each file processed (whether changed or not) | ||
+ | -c Changes: show information about each change made (no output for unchanged files)</ | ||
==== Controlling Permissions on New Files and Directories | ==== Controlling Permissions on New Files and Directories | ||
Line 245: | Line 284: | ||
- The modes prohibited by the umask value. | - The modes prohibited by the umask value. | ||
- | For example, a umask value of 0022 represents the permissions '' | + | For example, a umask value of 0022 represents the permissions '' |
The umask value can be viewed or set with the '' | The umask value can be viewed or set with the '' | ||
Line 266: | Line 305: | ||
| | ||
- | Note that the umask value is specific to the process that is currently running, and it inherited by child processes. That means that if you're using multiple shells (perhaps in multiple windows), each shell' | + | To ensure that no one else has __any__ access to new files and directories that you create on Matrix (unless you change the permission mode of the file after it is created), set your umask to 0077: '' |
+ | |||
+ | Note that the umask value is specific to the process that is currently running, and it inherited by child processes. That means that if you're using multiple shells (perhaps in multiple windows), each shell' | ||
+ | |||
+ | **Warning: | ||
==== Special Permissions | ==== Special Permissions | ||
Line 274: | Line 317: | ||
There are three additional, " | There are three additional, " | ||
- | * Set User ID (SUID) - when applied to an executable program file, this permission changes the effective user ID from the user executing the file to the owner of the file for the duration of the process. For example, if a user '' | + | * **Set User ID (SUID)** - when applied to an executable program file, this permission changes the effective user ID from the user executing the file to the owner of the file for the duration of the process. For example, if a user '' |
- | * Set Group ID (SGID) - when applied to an executable program file, this permission is similar to SUID, but it changes the effective group ID instead of the effective user ID. When applied to a directory, this causes all newly-created files and directories with that directory to be owned by the same group that owns the directory. For example, if the directory ''/ | + | * **Set Group ID (SGID)** - when applied to an executable program file, this permission is similar to SUID, but it changes the effective group ID instead of the effective user ID. When applied to a directory, this causes all newly-created files and directories with that directory to be owned by the same group that owns the directory. For example, if the directory ''/ |
- | * Sticky bit (t) - when applied to a directory, any file within that directory may be renamed or deleted only by the owner of the file, by the owner of the directory, or by a privileged process (for example, '' | + | * **Sticky bit (t)** - when applied to a directory, any file within that directory may be renamed or deleted only by the owner of the file, by the owner of the directory, or by a privileged process (for example, '' |
These permissions are represented in the '' | These permissions are represented in the '' | ||
Line 310: | Line 353: | ||
| | ||
| | ||
+ | |||
+ | ==== Securing Your Account ==== | ||
+ | |||
+ | There are two ways to secure your account on Matrix: | ||
+ | |||
+ | 1. If you do not want to share //any// of your files with other users, you can disable access to your home directory by turning off all permissions for the group and other communities. The command '' | ||
+ | |||
+ | 2. If you want to share access to //some// of your files with other users, turn on the appropriate permissions for group and/or other users, and use the '' | ||
+ | |||
+ | For example, you might: | ||
+ | |||
+ | * Start by turning off all permissions on the files and directories that are currently in your home directory: | ||
+ | |||
+ | chmod -r go= ~/* | ||
+ | |||
+ | * Create a directory of files you wish to share, called '' | ||
+ | |||
+ | mkdir ~/public | ||
+ | chmod go=rx ~/public | ||
+ | |||
+ | * Place any files that you want to share in the '' | ||
+ | |||
+ | cp anyFilesYouWantToShare ~/public | ||
+ | chmod go=r ~/public | ||
+ | |||
+ | * Set up you umask so that, by default, other users have no access to any new files you create (place this in your '' | ||
+ | |||
+ | umask 0077 | ||
+ | |||
+ | * Ensure that users can access your '' | ||
+ | |||
+ | chmod go=rx ~ | ||
+ | | ||
===== Access Control Lists ===== | ===== Access Control Lists ===== |
ops102/permissions.1706070219.txt.gz · Last modified: 2024/04/16 18:10 (external edit)