0% found this document useful (0 votes)
19 views10 pages

Linux User & Group Management Guide

This document is a hands-on tutorial for user and group management in Linux, covering topics such as user creation, group management, access management, file permissions, root privileges, and file management. It includes practical exercises and a time breakdown for each section, along with key commands and a cheat sheet for quick reference. Prerequisites include having an Ubuntu system and basic shell command knowledge.

Uploaded by

Rik Koki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

Linux User & Group Management Guide

This document is a hands-on tutorial for user and group management in Linux, covering topics such as user creation, group management, access management, file permissions, root privileges, and file management. It includes practical exercises and a time breakdown for each section, along with key commands and a cheat sheet for quick reference. Prerequisites include having an Ubuntu system and basic shell command knowledge.

Uploaded by

Rik Koki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

🐧 User & Group Management

Hands-On Linux Practice Tutorial


Topics Covered:
1. User Management
2. Group Management
3. Access Management
4. File Permissions
5. Root Privileges
6. File Management

🧭 Prerequisites:
 Ubuntu system (or any Debian-based Linux)
 Access to terminal
 Basic understanding of shell commands

📚 Time Breakdown
Section Topic Time
1 Intro + User Management 15 min
2 Group Management 15 min
3 Access and File Permissions 20 min
4 Root Privileges and sudo 15 min
5 File and Directory Management 20 min
6 Wrap-up Challenge 5 min

1. User Management (15 minutes)


🔹 Check current user:

whoami
🔹 List system users:

cut -d: -f1 /etc/passwd

🔹 Create a new user:

sudo adduser alice

🔹 Switch to the user:

su - alice

Press Ctrl+D or type exit to return.

🔹 Delete a user:

sudo deluser alice

📘 Chapter 5 — "Managing Users and Groups"

✅ Exercise 1:

 Create a user named testuser


 Set a password for the user
 Switch to the user and confirm you’re logged in as testuser

👥 2. Group Management (15 minutes)


🔹 View current groups:

groups
🔹 Create a group:

sudo addgroup developers

🔹 Add user to a group:

sudo usermod -aG developers testuser

🔹 Verify group membership:

groups testuser

🔹 Remove user from a group:

sudo gpasswd -d testuser developers

📘 Chapter 5 — "Managing Users and Groups"

✅ Exercise 2:

 Create a group called students


 Add testuser to the group
 Verify using the groups command

🔐 3. Access Management & File Permissions


(20 minutes)
🔹 Check permissions:

ls -l

Example output:
-rw-r--r-- 1 alice alice 4096 Apr 30 12:00 [Link]

Breakdown of permissions:

[owner][group][others]
rw- r-- r--

🔹 Change file permissions:

chmod u+x [Link] # Add execute for owner


chmod g-w [Link] # Remove write from group
chmod o+r [Link] # Add read for others

🔹 Numeric permissions:

chmod 755 [Link] # rwxr-xr-x


chmod 644 [Link] # rw-r--r--

🔹 Change ownership:

sudo chown testuser [Link]


sudo chown testuser:developers [Link]

📘 Chapter 6 — "File System Permissions and Ownership"

✅ Exercise 3:

 Create a file called [Link]


 Change its permissions so only the owner can read/write
 Make sure others can’t access it
: 4. Root Privileges and sudo (15 minutes)
🔹 Check if you’re root:

whoami

🔹 Use sudo to run admin commands:

sudo apt update

🔹 Run a shell as root:

sudo -i

🔹 Add a user to the sudo group:

sudo usermod -aG sudo testuser

📘 Chapter 8 — “Root and Sudo”

✅ Exercise 4:

 Try running apt update as a normal user


 Add yourself to the sudo group (if needed)
 Run the command again using sudo

📁 5. File and Directory Management (20


minutes)
🔹 Create files and directories:

mkdir myfolder
touch myfolder/[Link]
🔹 Move and rename files:

mv myfolder/[Link] myfolder/[Link]

🔹 Copy files:

cp myfolder/[Link] myfolder/tasks_backup.txt

🔹 Delete files and directories:

rm myfolder/tasks_backup.txt
rm -r myfolder

🔹 View contents:

ls -l myfolder/
cat myfolder/[Link]

📘 Chapter 4 — “Working with Files and Directories”

✅ Exercise 5:

 Create a directory project


 Inside it, create a file [Link]
 Write your name into the file using echo
 Rename the file to [Link]
 Delete the file and directory

🚀 6. Wrap-Up Challenge (5 minutes)


Combine everything you’ve learned in a mini project:

✅ Challenge:

1. Create a user projectuser


2. Create a group projectteam and add projectuser to it
3. As root, create a folder /opt/project, assign ownership to
projectuser:projectteam
4. Set permissions so only the group can write to it, others can only
read
5. Switch to projectuser and create a file inside /opt/project

🧠 Summary Table
Topic Key Command
Create user sudo adduser username
Delete user sudo deluser username
Create group sudo addgroup groupname
sudo usermod -aG groupname
Add user to group
username
View permissions ls -l
Change permissions chmod, chown
File operations cp, mv, rm, touch, mkdir
Root access sudo, sudo -i
🧾 Linux User & Access
Management Cheat Sheet

👤 User Management
Action Command
Create user sudo adduser <username>
Delete user sudo deluser <username>
Switch user su - <username>
View all users cut -d: -f1 /etc/passwd
Set/change password sudo passwd <username>

👥 Group Management
Action Command
Create group sudo addgroup <groupname>
Delete group sudo delgroup <groupname>
sudo usermod -aG <groupname>
Add user to group
<username>
Remove user from sudo gpasswd -d <username>
group <groupname>
List groups for user groups <username>

🔐 File Permissions
Action Command
View permissions ls -l
Change permissions (symbolic) chmod u+x <file>
Change permissions (numeric) chmod 755 <file>
sudo chown
Change ownership
<user>:<group> <file>

Permission Breakdown (e.g. -rwxr-xr--):


 u = user (owner)
 g = group
 o = others
 r = read, w = write, x = execute

Numeric Equivalents:

Permission Number
r (read) 4
w (write) 2
x (execute) 1
rw- 6
r-x 5
rwx 7

: Root & sudo


Action Command
Run as root sudo <command>
Become root sudo -i
Add user to sudo usermod -aG sudo
sudoers <username>

📁 File & Directory Management


Action Command
Create directory mkdir <dir>
Create file touch <file>
Copy file cp <source> <dest>
Move/rename file mv <source> <dest>
Delete file rm <file>
Delete directory rm -r <dir>
View file contents cat <file>

🧪 Bonus Commands
Purpose Command
Show current user whoami
Display current directory pwd
Search text in file grep "<text>" <file>
List all users in group getent group <groupname>

Common questions

Powered by AI

When deleting a user account in Linux, ensure that any critical data or configurations associated with the user are backed up or transferred if necessary. Use `sudo deluser <username>` to remove the user account cleanly . Additionally, check for and reassign ownership of any files belonging to the user using the `find` command to search and `chown` to change ownership, to prevent orphaned files and access issues for remaining users . It is also important to remove the user from any groups they were part of and, if necessary, delete any personal directories associated with the account.

To create a secured directory for a project with restricted access, first create the directory using `mkdir /opt/project`. Then change the ownership to the user and group specific to the project using `sudo chown projectuser:projectteam /opt/project` . Set permissions such that only the group has write access and everyone else only read access using `chmod 2755 /opt/project`, which translates to `rwxr-sr-x` permissions. This ensures that group members can add files, but others cannot alter contents .

Switching users in Linux can be done securely using the `su - <username>` command, where the terminal session changes to a new user's environment . This switch does not compromise security as it requires the password of the target user, ensuring that unauthorized access isn't granted. Once necessary tasks are completed, returning to the original user can be done by typing `exit` . This controlled access maintains security while providing flexibility in user management.

Verifying group memberships and managing access rights systematically involves several steps. Use the command `groups <username>` to list all groups a user belongs to, helping verify existing permissions . To adjust access rights, add a user to a group with `sudo usermod -aG <groupname> <username>`, allowing them access to resources grouped under that category . For removing users from a group, use `sudo gpasswd -d <username> <groupname>` to revoke access as necessary . Regular auditing of user memberships in critical groups helps maintain secure and efficient access management.

To empower a user with administrative privileges without logging in as the root user, add the user to the 'sudoers' group using the command `sudo usermod -aG sudo <username>`. This grants the user 'sudo' access, allowing them to execute commands with elevated privileges by prefixing them with 'sudo' . The 'sudo' command ensures that critical system commands are executed with care as the user must provide explicit confirmation.

Effective user and group management in Linux involves several steps. First, create user accounts using `sudo adduser <username>` and securely set a password for the new account . Next, create groups with `sudo addgroup <groupname>` to categorize users based on their roles or access needs . Add users to these groups using `sudo usermod -aG <groupname> <username>`, allowing for flexible permission management and collaboration . Regularly review group memberships using `groups <username>` to ensure appropriate access levels and perform audits with `cut -d: -f1 /etc/passwd` to list all users for effective account oversight .

First, check the current file permissions using the command `ls -l` to view the detailed information of the file, including permissions . Then, change the file's permissions using the `chmod` command. For example, to restrict access such that only the owner can read and write to a file, use `chmod 600 <filename>`, which sets the permission to `rw-------` . This ensures others cannot access the file. Additionally, change the ownership of the file, if necessary, using `sudo chown <user>:<group> <file>` to specify the correct user and group that should own the file .

Using the 'sudo' command instead of logging in as root enhances security and reduces the risk of system misconfigurations. 'Sudo' grants temporary administrative privileges and logs each action taken by users, providing accountability and audit trails . It ensures that users are prompted for their password for critical actions, reinforcing authorization checks. This minimizes accidental system-wide changes since actions are intentional and controlled, unlike root login, which opens unrestricted access to potentially hazardous commands . It also supports the principle of least privilege by allowing more granular control over command execution.

To ensure a file is only accessible by its owner, first check the current permissions with `ls -l` to verify its access settings . Set the file's permissions using `chmod 600 <filename>`, which changes its permission to `rw-------`. This configuration permits only the owner to read and write, denying access to group members and others . Additionally, confirm that the ownership is correctly assigned using `ls -l` and, if needed, adjust it with `sudo chown <user> <file>` to establish the right owner .

Effective file management in Linux involves several operations. To organize files, create directories with `mkdir <directory>`, and then create files using `touch <file>` within these directories . Move and rename files using `mv <source> <destination>`, which helps in reorganizing file locations and adjusting file names as necessary . Use `cp <source> <destination>` to duplicate files for backups or version control . Delete unnecessary or outdated files and directories with `rm <file>` and `rm -r <directory>` to keep the workspace clean and prevent clutter . Regularly view contents with `ls -l` to verify the organizational structure and file integrity .

You might also like