In Linux, each file and directory has three types of permissions assigned to it: read, write, and execute. These permissions are represented by characters and determine what actions users and groups can perform on the file.
- r: Read permission allows viewing the contents of a file or listing a directory.
- w: Write permission allows modifying the contents of a file or creating, renaming, or deleting files within a directory.
- x: Execute permission allows running a file as a program or entering (accessing) a directory.
Permissions are represented in a symbolic notation as follows:
-: Indicates a regular file.d: Indicates a directory.r: Read permission.w: Write permission.x: Execute permission.-: Indicates absence of a permission.
-rw-r--r--
In this example:
- The owner has read and write permissions (
rw-). - The group has read permission (
r--). - Others have read permission (
r--).
The chmod command is used to change permissions of files and directories.
chmod options permissions filenamechmod u+x file.txtThis command grants the owner (u) execute (x) permission on file.txt.
The chown command changes file ownership.
chown owner:group filenamechown john:developers file.txtThis command changes the owner of file.txt to john and assigns the group developers.
- SUID: Executes a file with the permissions of the file owner.
- SGID: Executes a file with the permissions of the group owner.
- Sticky Bit: Restricts deletion of files within a directory to only the owner.
chmod +s file.txtThis command sets the SUID bit on file.txt.
The ls command lists files and directories with their permissions.
ls -l file.txtThis command displays detailed information about file.txt, including permissions.