From e33f979844e33ef0e316e8759caef4fc958d210e Mon Sep 17 00:00:00 2001 From: Tharindu Lakshan Date: Wed, 6 Aug 2025 00:01:44 +0530 Subject: [PATCH 1/3] add file-permissions.md --- .../file-permissions.md | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md diff --git a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md new file mode 100644 index 0000000..62b1936 --- /dev/null +++ b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md @@ -0,0 +1,101 @@ +# ๐Ÿ“ File Permissions in Linux + +File permissions help control **who** can read, write, or execute a file or directory. + +## ๐Ÿ” Symbolic Permissions + +User types: + +- `u` โ†’ **user** (owner) +- `g` โ†’ **group** +- `o` โ†’ **others** + +Permissions: + +- `r` โ†’ **read** +- `w` โ†’ **write** +- `x` โ†’ **execute** + +Operators: + +- `+` โ†’ **add** permission +- `-` โ†’ **remove** permission +- `=` โ†’ **set exactly** (override) + +### ๐Ÿงช Examples + +```bash +# Add execute permission for user +chmod u+x script.sh + +# Remove write permission from group +chmod g-w file.txt + +# Set read-only for everyone. `a` means all (user, group, others) +chmod a=r file.txt + +# Custom permission set for user, group, others +chmod u=rw,g=r,o= file.txt +``` + +## ๐Ÿ—‚๏ธ Numeric Permissions + +Each permission has a number: + +- `r` = **4** +- `w` = **2** +- `x` = **1** + +To calculate total: + +- `7` = 4 + 2 + 1 โ†’ **read + write + execute** +- `6` = 4 + 2 โ†’ **read + write** +- `5` = 4 + 1 โ†’ **read + execute** +- `0` = **no permissions** + +**Permissions** are defined in **three digits: user-group-others** (755, 644, etc.). + +### ๐Ÿงช Examples + +```bash +# rwx for user, rx for group and others +chmod 755 script.sh + +# rw for user, r for group and others +chmod 644 notes.txt + +# full access for user only +chmod 700 secret.sh +``` + +## Ownership + +Every file or directory has an owner and a group. To view ownership `ls -l` command is used. + +To change owner: + +```bash +sudo chown username file.txt +``` + +To change group: + +```bash +sudo chgrp groupname file.txt +``` + +To change both owner and group: + +```bash +sudo chown username:groupname file.txt +``` + +### ๐Ÿงช Examples + +```bash +# Change owner to alice +sudo chown alice document.txt + +# Change owner to bob and group to developers +sudo chown bob:developers script.sh +``` From 444567b066aa59cd63035253597a4d1cd077c57d Mon Sep 17 00:00:00 2001 From: Tharindu Lakshan Date: Wed, 6 Aug 2025 00:06:58 +0530 Subject: [PATCH 2/3] update file-permissions.md --- .../03_Users_and_Permissions/file-permissions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md index 62b1936..00feeae 100644 --- a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md +++ b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md @@ -68,7 +68,7 @@ chmod 644 notes.txt chmod 700 secret.sh ``` -## Ownership +## ๐Ÿ‘ค Ownership Every file or directory has an owner and a group. To view ownership `ls -l` command is used. From 1e2660e0d757df594a0c0f4c53eedcd0320ac340 Mon Sep 17 00:00:00 2001 From: Tharindu Lakshan Date: Wed, 6 Aug 2025 12:47:56 +0530 Subject: [PATCH 3/3] add users-and-groups.md --- .../users-and-groups.md | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Week 1 - Linux Fundamentals/03_Users_and_Permissions/users-and-groups.md diff --git a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/users-and-groups.md b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/users-and-groups.md new file mode 100644 index 0000000..e733005 --- /dev/null +++ b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/users-and-groups.md @@ -0,0 +1,100 @@ +# ๐Ÿ‘ค Users and Groups in Linux + +**Users** and **groups** help manage access to files and resources securely. Every user has an entry in the `/etc/passwd` file, and every group is defined in `/etc/group`. + +## ๐Ÿ™โ€โ™‚๏ธ Users + +A user is an **individual account** that can log in to the system. Each user has a unique User ID (UID) and can own files and processes. + +### Create a user + +```bash +sudo useradd -m -s /bin/bash alice +``` + +- `-m`: create a home directory. +- `-s`: specify the default shell. + +### Set a password for the user + +```bash +sudo passwd alice +``` + +### Delete a user + +```bash +# delete a user (keep home directory) +sudo userdel alice + +# delete a user and remove home directory +sudo userdel -r alice +``` + +## ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Groups + +A group is a **collection of users.** You can create a group to manage permissions collectively. + +### Create a group + +```bash +sudo groupadd developers +``` + +### Delete a group + +```bash +sudo groupdel developers +``` + +### Add a user to a group: + +```bash +sudo usermod -aG developers alice +``` + +### Remove a user from a group + +```bash +sudo gpasswd -d alice developers +``` + +## ๐Ÿ” View user and group information + +### View user and group IDs: + +```bash +id alice +``` + +### View groups a user belongs to: + +```bash +groups alice +``` + +### /etc/passwd file + +Stores basic user info. Each line has 7 fields: + +```bash +cat /etc/passwd +``` + +```plaintext +username:password:UID:GID:GECOS:home_directory:shell +alice:x:1001:1001:alice:/home/alice:/bin/bash +``` + +### /etc/group file + +Stores group information. Each line has 4 fields: + +```bash +cat /etc/group +``` + +```plaintext +groupname:password:GID:user_list +developers:x:1002:alice,bob +```