Problem Statement
Explain Linux file permissions including special permissions (setuid, setgid, sticky bit). How do they work and when are they used?
Explanation
Standard Linux permissions include read (r/4), write (w/2), and execute (x/1) for owner, group, and others. Read allows viewing file contents or listing directory contents. Write allows modifying files or creating/deleting files in directories. Execute allows running files as programs or entering directories.
Special permissions provide additional security control. Setuid (4000 in octal, s in owner execute position) makes executable files run with the owner's privileges rather than the executor's - useful for programs needing elevated privileges like passwd command. Setgid (2000 in octal, s in group execute position) makes executables run with group privileges, or in directories, makes new files inherit the directory's group.
Sticky bit (1000 in octal, t in others execute position) on directories restricts file deletion - only file owners can delete their files even if directory is world-writable. Used on /tmp to prevent users from deleting others' temporary files. Set with chmod +t directory or chmod 1777 directory.
Example permissions: chmod 4755 file sets setuid with standard 755 permissions. chmod 2775 directory sets setgid for group collaboration. Understanding special permissions is crucial for security, multi-user environments, and proper system configuration. Misuse can create security vulnerabilities, so use them carefully.
