When it’s time to troubleshoot Linux file permissions, start by asking which operation failed. Running program, editing file, and deleting same file involve different permissions to check. That distinction matter when “ls -l” shows an “s” or a “t” where I expected an “x”.
In this guide, I will walk you through permissions commonly used on “/tmp”. If you manage Linux VPS or share deployment directory with teammate, these example will help you read mode, choose right setting, and verify what changed.
TL;DR
- Linux file permissions control user access to files and directories
- When program with SUID bit set run, it executes under privileges of file’s owner rather than user who launched it
- SGID enable group-based execution and directory group inheritance
- Sticky Bit prevent user from deleting or renaming other users’ files in shared directories
- Use “chmod 4755”, “chmod 2775”, and “chmod 1777” to set special permission
- Use “ls -l” and “ls -ld” to check file and directory permissions
- Regularly audit special permissions to maintain Linux security
How to Read Linux File Permission before Changing
Owner, group, and other
Use “ls -l” to inspect file and “ls -ld” to inspect directory itself. The “-d” matter if want directory’s mode and ownership on one line. Looking at “-rwxr-xr-x”, leading dash indicates that item is standard file rather than directory or special file.
Each ordinary permission has value: read is 4, write is 2, and execute is 1. Add those values within each group of three. That’s how “rwxr-xr-x” becomes 755. Add leading 4 for SUID and mode becomes 4755. Owner’s execute position then displays as “s”, giving “-rwsr-xr-x”.
Linux stores these permission flags as part of an inode’s mode information. Same special bits can behave differently depending on file type, which is why executable files and directories need to be examined separately. Linux inode manual explains these distinctions in detail.
If you are new to Linux permissions, start with our guide on Linux file permissions, including read, write, and execute access to understand the basics before exploring special permission bits.
Why directory permissions change diagnosis
On regular file, read let see content, write let modify them, and execute let run file if it’s executable in format Linux understand. On directory, read let list entry name, write support creating or removing entries, and execute let traverse directory and access entries by name. Creating, deleting, or renaming entry normally require both write and execute permission on relevant parent directory.
Read-only file can still be deletable if parent directory grant necessary access. When someone can edit file but can’t rename it, I check parent directory before touching file’s mode.
SUID on Linux
SUID stand for set user ID. Real user ID identify user account that started program. If Linux execute file with SUID permission enable, it temporarily use file owner’s permissions instead of user’s permission.
How SUID Work?
Consider executable file owned by root user. Normally, when regular user executes any program, it run with that user’s effective privileges. However, when SUID permission is enabled, program runs with effective user ID of its owner, provided operating system with permission.
For example, Linux “passwd” command commonly use SUID. Regular user need to change their passwords, but password-related account information is protected by operating system.
The SUID allows password utility to perform required privileged operations without giving ordinary users unrestricted root access. You can explore the execve system call manual for more technical details about executing programs and credential changes.
Read Full Article: https://serveravatar.com/linux-file-permissions-suid-sgid-sticky-bit
Top comments (0)