[00:00] Today, we're diving into a fundamental concept in Linux, file permissions. Understanding file permissions is crucial for maintaining security and proper access control in any Linux environment. So let's get started. First, let's talk about ownership. In Linux, [00:16] every file or directory is assigned three types of owners, the user, the group, and others. The user is the owner who created the file or directory. They have the most control over it. The group consists of users who share the same permissions to access the file or directory. [00:32] Others are users who are neither the owner nor members of the group. They have the least control. To manage access, Linux uses three types of permissions, read, write, and execute. Read allows the user to open and read file contents. [00:46] Write allows modifying or editing file contents. Execute allows the file to be run as a program. Permissions are represented in three ways, binary, octo, and string representation. [00:58] Consider the permission rwx. In binary it is 1 1 1 where each bit represents a permission Read is 1 write is 1 and execute is 1 In Octo this is represented as 7 with read being 4 write being 2 and execute being 1 added together [01:16] In string representation, it's simply RWX. Let's consider a practical example. Suppose you have a file where the owner has full permissions, which is RWX and translates to 7. [01:28] The group can read and write, which is RW- and translates to 6. Others can only read, which is r dash dash, and translates to 4. In Octo, [01:40] you could represent this as 764. Using the chmod command, you can set these permissions like this, chmod 764 and the file name. The owner can read, write, and execute the file. The group can read [01:53] and write, and others can only read. Now let's talk about special permissions bit, setuid, setgid, and the sticky bit. These provide additional control over files and directories. [02:05] The set UID bit, when set on an executable file, allows it to run with the permissions of the file owner not the user running the file This is useful for tasks that require higher privileges For example the password command which changes user passwords [02:21] has the setuid bit set. This allows regular users to change their passwords, which requires modifying sensitive system files. When the setuid bit is set, the execute bit for the owner shows as S. The setuid bit can be set on files [02:36] on files or directories. On the executable file, it allows the file to run with the permissions of the group that owns the file. On the directory, it ensures that the new files and directories created within the directory [02:48] inherit the group ownership of the directory. This is useful for shared project directories, ensuring all files created within have the same group ownership, allowing team members the necessary access permissions. [03:01] When the setGid bit is set, the execute bit for the group shows as s. The sticky bit, when set on a directory, ensures that only the file owner, the directory owner, or the root user can delete or rename the files within the directory. [03:16] This is commonly used on directories like temp to prevent users from deleting each other files When the sticky bit is set the execute bit for the others is shown as T To set these special permissions you can use the chmod command with specific symbols or [03:31] numeric representations. For example, let's say you want to set the setuid bit on an executable file named important script, along with the typical permissions of read, write, execute for the owner, [03:43] the read and execute for the group and others. In this command, for set the setuid bit, 7 gives the owner read, write, and execute permissions, and 5 gives the group and others read and execute permissions. [03:55] Understanding these permissions and special bits is essential for managing access and ensuring security in your Linux environment. Correctly setting file permissions and special bits can prevent unauthorized access [04:07] and accidental modifications, safeguarding your data and ensuring smooth collaboration. That's it for today's video on Linux file permissions. If you like our videos, you might like our system design newsletter as well. [04:21] It covers topics and trends in large-scale system design, trusted by 500,000 readers.