Linux File Permissions & chmod Command Cheat Sheet

Jasai HansdaJasai Hansda
4 min read

Linux file permissions are key to controlling access to files and directories. It allows you to set who can read, write, or execute a file or directory. This guide will help you understand how to view and change these permissions.

The system divides users into:

  • u โ€“ user (owner)

  • g โ€“ group

  • o โ€“ others (everyone else)

  • a โ€“ all (user + group + others)


๐Ÿ“‚ 1. Viewing File Permissions

ls -l

Sample Output:

-rwxr-xr-- 1 user group 1234 Jul 5  file.sh

Breakdown:

  • - โ†’ file (or d for directory)

  • rwx โ†’ owner can read, write, execute

  • r-x โ†’ group can read and execute

  • r-- โ†’ others can only read


๐Ÿ”ง 2. Understanding Permission Types

SymbolMeaningApplies To
rReadView file contents / list dir contents
wWriteEdit file / create, delete inside dir
xExecuteRun file / enter directory

โœ๏ธ 3. Modifying Permissions with chmod

โž• Add Permission

chmod u+x file.sh     # Add execute for user
chmod g+w file.txt    # Add write for group
chmod o+r file.log    # Add read for others
chmod +x file.sh      # Add execute for everyone

โž– Remove Permission

chmod u-x file.sh     # Remove execute from user
chmod g-w file.txt    # Remove write from group
chmod o-r file.log    # Remove read from others
chmod -x file.sh      # Remove execute from everyone

โžก๏ธ Set Specific Permissions

chmod u=rwx file.sh   # Set user permissions to read, write, execute
chmod go=rw file.txt  # Set group and others to read, write only
chmod a=r file.txt    # Everyone gets read-only

๐Ÿ”ข 4. Numeric (Octal) Permissions with chmod

Symbolic
r = 4
w = 2
x = 1

Sum them up for each level:

User TyperwxBinaryOctal
Userrwx1117
Groupr-x1015
Othersr--1004

๐Ÿ”ง Examples:

chmod 755 script.sh   # rwx for user, rx for group and others
chmod 700 secret.txt  # rwx only for user (private)
chmod 644 file.txt    # rw for user, read-only for others

๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ 5. Changing Ownership with chown

chown user file.txt             # Change owner
chown user:group file.txt       # Change owner and group

Example:

chown ec2-user:ec2-user app.py

๐Ÿ”„ 6. Changing Group with chgrp

chgrp groupname file.txt

๐Ÿ“ 7. Apply Permissions Recursively

chmod -R 755 myfolder/    # Apply to all files & subfolders
chown -R user:group myfolder/

๐Ÿ“Œ Quick Reference: Symbolic vs Octal

OctalSymbolicMeaningchmod Command
777rwxrwxrwxAll permissions for user, group, and otherschmod 777 file
755rwxr-xr-xFull for user, read & execute for group & otherschmod 755 file
700rwx------Full access for user onlychmod 700 file
644rw-r--r--Read/write for user, read-only for group & otherschmod 644 file
600rw-------Read/write for user, no access for group & otherschmod 600 file
444r--r--r--Read-only for everyonechmod 444 file
400r--------Read-only for user, no access for group or otherschmod 400 file
000----------No permissions for anyonechmod 000 /

๐Ÿ“ŒQuick Reference: Symbolic chmod Commands (No Octal)

These donโ€™t use numbers but letters to modify permissions.

Symbolic CommandEffect
chmod +x fileAdd execute permission for all (user, group, others)
chmod u+x fileAdd execute for user only
chmod g-w fileRemove write permission from group
chmod o=r fileOthers get read-only access
chmod a+x fileAdd execute for all users (a = u+g+o)
chmod u=rwx fileSet user permission to full (read/write/execute)
chmod go= fileRemove all group and others permissions
chmod a=rw fileEveryone gets read/write, no execute

๐Ÿ‘ฎ Extra: Checking Permissions of a File

stat file.txt

Output includes:

  • Access rights in symbolic and numeric

  • Owner and group

  • Modification time


Conclusion

Mastering Linux file permissions is essential for effectively managing access to files and directories. By understanding and utilizing the chmod, chown, and chgrp commands, you can control who can read, write, or execute files, ensuring both security and proper access management. Whether you prefer symbolic or numeric (octal) methods, this guide provides a comprehensive overview to help you confidently modify permissions. Proper permission settings are crucial for maintaining system integrity and protecting sensitive data.

0
Subscribe to my newsletter

Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jasai Hansda
Jasai Hansda

Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!