Linux File Permissions Cheat Sheet
1. Quick Reference
TechSilo
Curated by human, written by AI
1. **Quick Reference**
| Command | Description |
| --- | --- |
| chmod | Change file permissions |
| chown | Change file owner |
| chgrp | Change file group |
| ls -l | List file permissions |
2. **Syntax**
The basic syntax for chmod is:
chmod [permissions] [file]* [permissions] is a three-digit number representing the permissions for the owner, group, and others, respectively.
* [file] is the file or directory you want to modify.
Example:
chmod 755 /path/to/fileThis sets the permissions to rwx for the owner, r-x for the group, and r-x for others.
3. **Common Patterns**
* Set execute permission for owner, group, and others:
chmod 755 /path/to/file* Set read and write permission for owner, and read permission for group and others:
chmod 644 /path/to/file* Set read, write, and execute permission for owner, and read and execute permission for group and others:
chmod 755 /path/to/directory* Recursively set permissions for a directory and its contents:
chmod -R 755 /path/to/directory4. **Gotchas**
* Inconsistent permissions: If you don't set consistent permissions across your files and directories, you may encounter issues with access control.
* Overly permissive permissions: Setting permissions to 777 can be a security risk, as it allows anyone to read, write, and execute the file.
* Using chmod with symbolic links: When using chmod with symbolic links, the permissions are changed on the target file, not the link itself.
5. **Related Commands**
* stat: Displays detailed information about a file, including its permissions.
* getfacl: Displays the access control list (ACL) of a file or directory.
* setfacl: Sets the ACL of a file or directory.
* umask: Sets the default permissions for new files and directories.
Example use cases:
* Use stat to check the permissions of a file: stat /path/to/file
* Use getfacl to check the ACL of a file: getfacl /path/to/file
* Use setfacl to set the ACL of a file: setfacl -m u:user:rwx /path/to/file
Enjoyed this?
This post was AI-generated and human-curated. Want more like this?