Chmod Permissions Calculator & Generator
Interactively calculate POSIX file permissions in octal (0755, 0644) and symbolic notation (-rwxr-xr-x). Includes SUID, SGID, Sticky Bit, and recursive command generation.
Permission Toggles
| Scope | Read (4) | Write (2) | Execute (1) |
|---|---|---|---|
| Owner (u) | |||
| Group (g) | |||
| Public / Others (o) |
Special Permission Flags
Calculated Permissions
Production Incident Runbook: Recovering from Sudo & SSH Lockouts Caused by Permissions Errors
One of the most catastrophic administrative blunders in Linux systems engineering is executing an unconstrained permission change (such as running chmod -R 777 / or mistakenly modifying permissions on /etc/sudoers or ~/.ssh/). When permissions on critical security files are corrupted, the Linux kernel and OpenSSH daemons immediately reject login attempts with severe security locks:
- SSH Private Key Rejection: OpenSSH refuses to load private keys with permissions looser than
0600, outputtingPermissions 0644 for '/root/.ssh/id_rsa' are too open. It is required that your private key files are NOT accessible by others. - Sudo Command Lockout: The
sudobinary requires an exact0440permission on/etc/sudoers. If permissions are altered, running any sudo command yieldssudo: /etc/sudoers is world writableorsudo: parse error in /etc/sudoers, locking sysadmins out of root privileges.
Emergency Incident Remediation Checklist:
- Recovering Broken Sudo Permissions via pkexec: If sudo is locked out but PolicyKit is installed, restore
/etc/sudoersusing:pkexec chmod 0440 /etc/sudoers
- Restoring Sudoers via Cloud Console / Single-User Mode: If pkexec is unavailable, attach to the cloud serial console (AWS EC2 Serial Console or GCP Cloud Shell), reboot into single-user rescue mode (appending
init=/bin/bashto GRUB kernel flags), and execute:chmod 4755 /usr/bin/sudo chmod 0440 /etc/sudoers chmod 0440 /etc/sudoers.d/*
- Standardizing OpenSSH Directory Permissions: OpenSSH enforces strict permission hierarchies. Apply these hardened rules across all server hosts:
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub
POSIX File Permissions & Octal Bitmask Mathematics
Linux and Unix file systems represent permissions using a 9-bit binary mask grouped into three octets: Owner (User), Group, and Others (Public). Each octet assigns binary weights to three operations:
| Permission | Symbolic | Binary Weight | Octal Value | Directory Meaning |
|---|---|---|---|---|
| Read | r | 100 | 4 | Ability to list files within directory (ls) |
| Write | w | 010 | 2 | Ability to create, rename, or delete files inside directory |
| Execute | x | 001 | 1 | Ability to enter or traverse the directory (cd) |
Summing the octal values yields the permission digit. For example, Read (4) + Write (2) = 6 (read-write), while Read (4) + Execute (1) = 5 (read-execute). A permission of 0755 translates to Owner: 7 (rwx), Group: 5 (r-x), Others: 5 (r-x).
Production Web Server Permission Hardening Script
A frequent security mistake when deploying WordPress, Laravel, or Node.js applications is assigning blanket 777 permissions to fix upload errors. This grants any local process or compromised service full write and execute rights, enabling instant remote code execution (RCE). Use this production-hardened recursive separation script:
#!/usr/bin/env bash
# web-server-hardening.sh - Production POSIX Hardening
WEB_ROOT="/var/www/zelobiz"
WEB_USER="www-data"
WEB_GROUP="www-data"
echo "Applying ownership to ${WEB_USER}:${WEB_GROUP}..."
chown -R ${WEB_USER}:${WEB_GROUP} ${WEB_ROOT}
echo "Standardizing directories to 755 (drwxr-xr-x)..."
find ${WEB_ROOT} -type d -exec chmod 755 {} +
echo "Standardizing files to 644 (-rw-r--r--)..."
find ${WEB_ROOT} -type f -exec chmod 644 {} +
echo "Hardening writable upload directories..."
chmod 775 ${WEB_ROOT}/wp-content/uploads
echo "Locking down wp-config.php / .env configuration secrets..."
chmod 600 ${WEB_ROOT}/wp-config.php
chmod 600 ${WEB_ROOT}/.env
Frequently Asked Questions: Linux Chmod & File Permissions
What is the Sticky Bit (1777) and why is it mandatory on the /tmp directory?
The sticky bit (indicated by a t in symbolic notation, such as drwxrwxrwt) restricts file deletion in shared writable directories. In standard directories with write access, any user can delete or rename any other user’s files. The sticky bit ensures that only the file’s creator, the directory owner, or the root superuser can delete or modify the file, securing temporary directories like /tmp and /var/tmp.
What is UMASK and how does it determine default file permissions?
The user mask (umask) defines the permission bits automatically stripped when new files or directories are created. Default base permissions are 0666 for files and 0777 for directories. A standard production umask of 0022 subtracts group and other write bits, resulting in default creations of 0644 for files and 0755 for directories.
Why is SUID (4755) dangerous on custom binaries?
When an executable file has the SUID (Set User ID) bit set, the Linux kernel executes the process with the permissions of the file owner (often root), rather than the permissions of the user launching it. If an application containing memory corruption flaws or command injection vulnerabilities is owned by root with SUID set, unprivileged attackers can exploit it to achieve instantaneous root privilege escalation.
Granular Linux Permissions with POSIX Access Control Lists (ACLs)
Standard Unix permissions restrict access to exactly three entities: one Owner, one Group, and Everyone Else. In enterprise multi-user servers, this model quickly breaks down—for example, when a web directory must be writable by both www-data (the web server) and deployer (the CI/CD deployment user), without making the files world-writable.
POSIX Access Control Lists (ACLs) extend standard permissions, allowing administrators to grant explicit read/write/execute rights to multiple specific users and groups using setfacl and getfacl:
# Grant specific user 'deployer' read-write-execute permissions
setfacl -m u:deployer:rwx /var/www/zelobiz
# Grant specific group 'devops-auditors' read-only permission
setfacl -m g:devops-auditors:rx /var/www/zelobiz
# Set DEFAULT ACLs so newly created child files inherit permissions automatically
setfacl -d -m u:deployer:rwx /var/www/zelobiz
setfacl -d -m g:www-data:rwx /var/www/zelobiz
# Inspect active ACL entries on a file or directory
getfacl /var/www/zelobiz
When an ACL is present on a file, standard ls -l displays a plus sign (+) at the end of the permission string (e.g. drwxrwxr-x+), indicating that extended ACL policies are actively governing access.
Immutable File Attributes: Defense Against Malware & Accidental Deletion
Even root users can accidentally truncate critical files or have credentials hijacked by ransomware. Linux ext4 and XFS filesystems provide extended attributes managed via chattr and lsattr:
- The Immutable Flag (`+i`): Setting
chattr +i /etc/resolv.confprevents any process—including root—from modifying, renaming, deleting, or creating symlinks to the file. Evenrm -rfwill fail withOperation not permitteduntil the attribute is explicitly removed withchattr -i. - Append-Only Flag (`+a`): Setting
chattr +a /var/log/secureensures that log files can only be opened in append mode. Attackers who compromise a service cannot erase their historical tracks by truncating or rewriting log files.
SUID Privilege Escalation Analysis (GTFOBins Vectors)
The SUID (Set User ID) permission bit (octal 4000) is one of the most common vectors exploited in Linux penetration testing and privilege escalation attacks. When system administrators mistakenly assign SUID permissions to common system utilities to let junior operators perform maintenance tasks, attackers can abuse built-in command switches to escape into interactive root shells:
| Binary | Dangerous SUID Command | Exploitation Mechanism |
|---|---|---|
| find | find . -exec /bin/sh -p \; -quit | Executes shell under inherited root process credentials |
| vim | vim -c ‘:!sh’ | Escapes editor directly into interactive root terminal |
| bash | bash -p | Preserves elevated effective UID without dropping privileges |
Defensive Hardening: Regularly scan your filesystems for rogue SUID binaries using:
find / -perm -4000 -type f -exec ls -ld {} + 2>/dev/null. Mount temporary partitions (like /tmp and /dev/shm) with the nosuid,nodev,noexec mount flags in /etc/fstab to block arbitrary SUID execution.
Frequently Asked Questions: Linux File Permissions & Hardening
What is the SGID bit on a directory and why is it useful in shared team projects?
When the SGID (Set Group ID, octal 2000) bit is applied to a directory (e.g. chmod 2775 /shared/repo), any new file or subfolder created within that directory automatically inherits the group ownership of the parent folder, rather than the primary group of the individual user who created it. This ensures continuous shared write access for team members without manual permission fixes.
Why does a user need execute (x) permission on a directory to read files inside it?
In POSIX systems, read permission (r) on a directory only allows listing file names. The execute permission (x) acts as a “traverse / search” permission. Without execute permission, the operating system kernel will reject file access calls (like cat /dir/file.txt or cd /dir) with Permission denied, even if the user has full read permissions on both the parent directory and the file itself.
How does Docker container user mapping interact with host file permissions?
By default, the root user inside a Docker container shares the identical User ID (UID 0) as the root user on the host operating system. If a container mounts a host volume and writes files, those files are owned by host root. To eliminate this security risk, production Docker daemons enforce User Namespaces (userns-remap) or run as Rootless Docker, mapping container UID 0 to an unprivileged high UID (e.g. UID 100000) on the host.
Mandatory Access Control (MAC): SELinux & AppArmor Beyond POSIX Chmod
Standard POSIX file permissions represent Discretionary Access Control (DAC): the owner of a file decides who can read or write to it. If an application running as www-data is compromised through a PHP file upload vulnerability, the attacker inherits full write access to every file owned by www-data across the operating system.
To prevent DAC compromise from escalating into a full system takeover, enterprise Linux distributions enforce Mandatory Access Control (MAC) via Security-Enhanced Linux (SELinux) or AppArmor:
- SELinux Type Enforcement: Regardless of POSIX chmod permissions (even if a file is set to
777), SELinux restricts processes based on cryptographic security labels. An Nginx or Apache worker process running in thehttpd_tdomain is strictly forbidden by the Linux kernel from reading files labeleduser_home_t(user directories) or executing binaries labeledadmin_home_t. - Restoring Security Contexts: When moving files into web roots manually, files often inherit incorrect temporary SELinux contexts, resulting in unexpected HTTP 403 Forbidden errors despite valid 755 chmod permissions. Restore proper contexts with:
restorecon -Rv /var/www/zelobiz