Chapter 5: File Permissions

Foreword

We recommend that you do not use AI to do the exercises because you are in the learning phase.

Introduction

In this section, we will discuss file management in Linux. More specifically, we will talk about file permissions and access management.

Prerequisites

Same old story. 😉



File Management

File Permissions

General

In Linux, file permissions are an essential barrier against unauthorized access.

l: Symbolic link p: Named pipe (IPC) s: Local socket (IPC)

Managing the owner and group of a file

The Sticky Bit (ℹ️ Good to know!)

The sticky bit is a special permission that can be set on a directory. When enabled, this bit changes the behavior of files placed in that directory. Essentially, it allows you to restrict file deletion to the file owner. In other words, only the file owner or the administrator (root) can delete or rename a file in a directory marked with the sticky bit, even if other users have write permissions on the directory.

Usefulness of the Sticky Bit

The sticky bit is often used in shared directories, such as /tmp, where many users can create and modify files, but where it is essential that users cannot delete or modify other users’ files. Typical use case:

To test 👨🏾‍💻👩🏾‍💻:

$ ls -l /usr/bin/passwd ## You will see the ‘s’ representing the SETUID bit at the user level. This binary file belongs to root, but anyone can execute it as root. $ passwd ## This allows you to change your password without using ‘sudo’, thanks to the SETUID bit.



### SETGID (Set Group ID)
- **Purpose**: Allows a user to execute a file with the **permissions of the group** of the file, rather than the permissions of the group of the user who launches the execution.
- **Use case**: Very useful for shared programs or directories where it is important to maintain specific group permissions.
#### Example:
```bash
chmod g+s /path/to/file

This adds the SETGID bit to an executable file or directory.

Summary:



Training ⚔️

Exercise 1

👉🏾 Click here