0% found this document useful (0 votes)
10 views38 pages

Advance Kali Linux Batch Notes

The document provides comprehensive notes on advanced Kali Linux topics, including the differences between open-source and closed-source software, an overview of Linux and its kernel, and specific details about Kali Linux's features and tools. It also covers practical steps for installation, basic Linux commands, network management, and configuration files. Additionally, it includes troubleshooting tips and command analyses to enhance user understanding and proficiency in using Kali Linux for penetration testing and ethical hacking.
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)
10 views38 pages

Advance Kali Linux Batch Notes

The document provides comprehensive notes on advanced Kali Linux topics, including the differences between open-source and closed-source software, an overview of Linux and its kernel, and specific details about Kali Linux's features and tools. It also covers practical steps for installation, basic Linux commands, network management, and configuration files. Additionally, it includes troubleshooting tips and command analyses to enhance user understanding and proficiency in using Kali Linux for penetration testing and ethical hacking.
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

Advance Kali linux batch notes

1. Open Source vs Closed Source


🧠 Theory:
• Open Source Software (OSS):
o The source code is publicly available. o Anyone can inspect, modify, and
distribute the software–––––––. o Encourages transparency, community
collaboration, and security (bugs can be found/fixed by many eyes).
o Example: Linux, Wireshark, Nmap, Metasploit Framework.
• Closed Source Software:
o The source code is proprietary—you cannot see or modify it. o Owned
and maintained by a company. o Example: Windows OS, Burp Suite
Professional, Nessus.

Practical:

# Check license of an open-source tool apt


show nmap | grep License

# Check if you can view/edit source (nmap is in C, view GitHub) git clone
[Link] cd nmap ls

🔹 2. What is Linux and Linux Kernel


🧠 Theory:
• Linux: An operating system based on the Linux Kernel. It’s a Unix-like, multiuser,
open-source OS.
• Linux Kernel:
o The core of the Linux OS.
o Manages hardware interaction, process scheduling, file systems, etc.
• Linux Distros = Linux Kernel + Tools (e.g., , GNOME, utilities).

Practical:

# Check current kernel version uname


-r

# Check kernel-related information


cat /proc/version
🔹 3. About Kali Linux and its Specifications
🧠 Theory:
• Kali Linux is a Debian-based Linux distro focused on penetration testing, digital
forensics, and ethical hacking.
• Maintained by Offensive Security.
• Contains 600+ tools like:
o Metasploit o

Wireshark
o Burp Suite o

Nmap
o John the
Ripper
• Lightweight and can be installed on VMs, USBs, Raspberry Pi.

⚙️Specs:
• Default Desktop: XFCE (lightweight), GNOME (optional)
• Package Manager: apt
• Rolling release model (frequent updates)

Practical:

# Check Kali version cat


/etc/os-release

# List installed tools


ls /usr/bin | grep -E 'nmap|msfconsole|burp|hydra'

🔹 4. Installing Kali Linux & Virtualization Technology


🧠 Theory:
• Virtualization: Running one OS (guest) inside another (host) using software like:
o VirtualBox (Free) o
VMware (Free/Pro)
• Benefits:
o Easy snapshots o
Isolated environments o
Testing without harming
host system

Practical:
✅ Step-by-step (VirtualBox):

1. Download Kali ISO:


[Link]
2. Create VM:
o Open VirtualBox → New → Name: Kali o Type: Linux | Version: Debian
(64-bit) o Memory: 2GB+ recommended
3. Attach ISO: o Settings > Storage > Add ISO file to Optical Drive
4. Network Setup:
o Choose Bridged Adapter (for real IP on same network)
5. Start VM and Install Kali:
o Follow the GUI instructions:
▪ Set locale/timezone
▪ Create user/password
▪ Disk partition: "Guided - use entire disk"
6. Post-Installation:

sudo apt update && sudo apt upgrade -y

🔹 5. Basic Understanding of Linux


🧠 Theory:
• Linux is case-sensitive.
• Everything is treated as a file (even hardware).
• Important directories:
o /etc – config files o
/home – user files o /var –
logs o /bin – binaries •
Default shell:

Practical:
# Navigate
system cd /etc ls
-l cat passwd

# Check current user whoami

# Create file & directory mkdir


testfolder
touch [Link]

# View file content cat


[Link]
1. Open Source vs Closed Source
Theory:

• Open Source: Source code is publicly available. Anyone can inspect, modify, or
distribute it (e.g., Linux, Kali, Firefox).
• Closed Source: Code is proprietary. Only the creator or licensed users can modify or
distribute it (e.g., Windows, macOS).

Examples:

• Open Source: Kali Linux, Metasploit, Wireshark


• Closed Source: Burp Suite Professional, Windows Defender

2. What is Linux and the Linux Kernel?


Theory:

• Linux: An open-source OS based on UNIX, used widely in servers, desktops, and


hacking tools.
• Kernel: Core of the OS that manages hardware (CPU, memory, devices) and system
processes.

Practical:

• Check kernel version:


uname -r

3. About Kali Linux and Its Specifications


Theory:

• Kali Linux: A Debian-based OS for ethical hacking, pen-testing, and digital


forensics.
• Key Tools: Nmap, Metasploit, Burp Suite, Wireshark, Aircrack-ng, Hydra.

Specs:

• Recommended: 4GB RAM, 20GB disk space, VirtualBox/VMware for virtualization.


4. Install Kali Linux & Virtualization Technology
Theory:

• Use VirtualBox or VMware to install Kali without affecting host OS.

Practical:

1. Download Kali ISO: [Link] 2.


Set up in VirtualBox:
o Create VM → 4GB RAM → 20GB disk → Attach Kali ISO. o
Boot and follow graphical install steps.

5. Basic Understanding of Linux


Theory:

• Everything is a file.
• Linux Filesystem Hierarchy (/, /bin, /etc, /home, /root, /tmp etc.)
• Users: root (admin), normal users

Practical:

• List files: ls
• Navigate: cd /home
• Print working directory: pwd

6. Troubleshooting Issues in Kali (Old Versions)


Examples:

• Black Screen after Boot:


o Use: Ctrl + Alt + F1 → login and update:

sudo apt
update &&
sudo apt
upgrade

• Broken Dependencies:

sudo apt --fix-broken install

• Network not working:


sudo systemctl restart NetworkManager

7. Useful Commands Command


Description
ls List files and directories
cd Change directory
pwd Print current directory
mkdir Make a new directory
rm Remove file/directory
cp Copy files/folders
mv Move/rename files/folders
chmod Change file permissions
chown Change ownership
sudo Run command as superuser

8. Analysis of ls Command

Theory: Lists files in current directory.

Practical:

ls # Basic
ls -l # Long listing with permissions
ls -a # Show hidden files ls -lh
# Human-readable size

9. Analysis of cd Command

Theory: Used to move between directories.

Practical:

cd /etc # Go to /etc cd ~
# Go to home directory cd .. # One
directory up cd - # Go back to
previous directory

10. Helping Yourself in Kali Linux


Practical:
man ls # Manual page for ls ls --help
# Short help for ls apropos network # Search man
pages for 'network'

11. Configuration Files in Kali Linux Important

Files:

• /etc/passwd → User account info


• /etc/shadow → Passwords (hashed)
• /etc/hosts → Maps IP to hostnames
• /etc/network/interfaces → Manual network settings
• /etc/[Link] → DNS configuration

12. passwd File Analysis

Command:
cat
/etc/passwd
Format:
ruby
username:x:UID:GID:comment:/home/dir:/bin/
Example:
ruby
root:x:0:0:root:/root:/bin/

13. Permissions in Linux


Theory:

• rwx (read, write, execute)


• 3 groups: User, Group, Others
• Represented in numbers (chmod): 7 = rwx, 6 = rw-, etc.

Practical:
ls -l chmod 755
[Link] chown
user:group [Link]
14. Managing Network in Kali Linux
Commands:

ip a # View IP address
ifconfig # (older tool) ping
[Link] # Test connectivity nmcli
device status # NetworkManager CLI sudo
systemctl restart NetworkManager WiFi Setup
Example:
nmcli d wifi
list
nmcli d wifi connect "SSID" password "your_password"

15. Macchanger (Spoof MAC Address)


Theory: Helps in anonymity or bypassing MAC-based restrictions.

Practical:

sudo apt install macchanger sudo


ifconfig eth0 down
sudo macchanger -r eth0 # Random MAC sudo
ifconfig eth0 up
macchanger -s eth0 # Show current MAC

1. ls – List Directory Contents


ls -l

Output Example:
css
-rw-r--r-- 1 user user 4096 Apr 7 12:00 [Link] Explanation:

• -rw-r--r--: File permissions (User: rw, Group: r, Others: r)


• 1: Hard link count
• user: Owner
• user: Group
• 4096: File size in bytes
• Apr 7 12:00:Last modified date/time
• [Link]: File name
📁 2. cd – Change Directory
cd /etc

Effect: You move into the /etc directory.


pwd

Output: /etc — shows current location.

📄 3. cat – View File Content


cat
/etc/hostname
Output Example:
nginx kali
Explanation: Prints the hostname of your Kali system. Useful to verify machine identity.

📝 4. touch – Create Empty File


touch
[Link]

Effect: Creates a blank file [Link] in the current directory.


ls -l
[Link]
Output:
css
-rw-r--r-- 1 user user 0 Apr 8 12:00 [Link]

• 0: File size is zero since it’s empty.

📁 5. mkdir – Make Directory


mkdir
demo
Effect: Creates a directory named demo.
ls -ld
demo
Output:
sql
drwxr-xr-x 2 user user 4096 Apr 8 12:05 demo

• d: This is a directory.

🗑 6. rm – Remove File/Directory
rm
[Link]

Effect: Deletes the file [Link].


rm -r
demo

Effect: Deletes the directory demo and all its content recursively.

📤 7. cp – Copy Files/Directories
cp /etc/hosts
my_hosts.txt

Effect: Copies hosts file to your current directory and renames it to my_hosts.txt.

🔄 8. mv – Move or Rename
mv my_hosts.txt
backup_hosts.txt

Effect: Renames the file.


📑 9. nano – Text Editor
nano
[Link]

Effect: Opens [Link] in a text editor. Press Ctrl+O to save and Ctrl+X to exit.

📃 10. man – Manual Page


man ls

Effect: Shows the full manual (help) documentation for the ls command.

📊 11. df -h – Disk Space Usage


df -h
Output:
nginx

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 50G 25G 25G 50% / Explanation:

• Size: Total disk space


• Used: Used space
• Avail: Free space
• /: Mount point (root directory)

📁 12. du – Directory Size


du -sh
/var/log
Output:

100M /var/log

Explanation: /var/log is using 100MB of disk space.


👥 13. whoami – Current User
whoami
Output:
nginx kali
Explanation: You are logged in as user kali.

14. id – User and Group Info


id
Output:
ini uid=1000(kali) gid=1000(kali)
groups=1000(kali),24(cdrom),27(sudo) Explanation:

• uid=1000: User ID
• gid=1000: Group ID
• Lists all groups the user belongs to.

🔐 15. chmod – Change Permissions


chmod 755
[Link]

Effect: Sets permissions to:

• Owner: read, write, execute


• Group/Others: read, execute

👑 16. sudo – Superuser Privileges


sudo apt
update

Effect: Runs command as root. Updates package list.


🌐 17. ping – Network Connectivity
ping
[Link]
Output:
python
64 bytes from [Link]: icmp_seq=1 ttl=115 time=20.0 ms Explanation:

• You’re connected to the internet. •


time=20.0 ms: Round-trip time.

📡 18. ip a – IP Address
ip a
Output:
nginx inet [Link]/24 brd [Link] scope
global eth0

Explanation: Shows the IP address ([Link]) for your eth0 interface.

🔄 19. systemctl – Manage Services


sudo systemctl restart
NetworkManager

Effect: Restarts networking service — helpful if WiFi/Ethernet stops working.

20. history – Show Command History


history

Effect: Lists all previous commands with their line numbers.


Configuration Files in Kali Linux
Linux configuration files are mostly located in the /etc directory. They control system
behavior, user access, networking, services, and more.
🔑 1. /etc/passwd – User Account Information
Purpose: Stores user details.

Command:
cat
/etc/passwd
Sample Output:
ruby
root:x:0:0:root:/root:/bin/ kali:x:1000:1000:Kali

User:/home/kali:/bin/ Explanation:

• root: Username
• x: Placeholder for password (stored in /etc/shadow)
• 0: UID (0 = root)
• 0: GID
• /root:Home directory
• /bin/: Default shell

🔐 2. /etc/shadow – Encrypted Passwords Purpose:

Stores user password hashes (only root can read).

Command:
sudo cat
/etc/shadow Output
Example:
javascript kali:
$6$9WKn3...:19234:0:99999:7:::
Explanation:

• $6$...: Encrypted password


• Fields: last password change, min/max age, etc.

🧩 3. /etc/hostname – System Hostname


Purpose: Stores the system's hostname.

Command:
cat
/etc/hostname
Output:
nginx kali

Change Hostname:

sudo echo "newname" > /etc/hostname

🌐 4. /etc/hosts – Local DNS Mapping


Purpose: Maps hostnames to IPs locally.

Command:
cat
/etc/hosts
Output:

[Link] localhost [Link]


kali

Use Case: Map [Link] to [Link] for testing.

🌐 5. /etc/[Link] – DNS Servers


Purpose: Defines nameservers for DNS lookups.

Command:
cat
/etc/[Link]
Output:
nginx nameserver
[Link] Edit DNS:

sudo nano /etc/[Link]

📶 6. /etc/network/interfaces – Manual Network Config (older method)


Purpose: Define static/manual network configuration.
Command:
cat
/etc/network/interfaces
Output:
cpp auto lo iface lo
inet loopback

Note: Kali now mainly uses NetworkManager, but this still works for manual setups.

📡 7. /etc/NetworkManager/[Link] Purpose:

Controls NetworkManager behavior.

Command:
cat
/etc/NetworkManager/[Link]
Output Example:
ini [main]
plugins=ifupdown,keyfile

Edit Example: Disable MAC randomization


[device]
[Link]-rand-mac-address=no

🔄 8. /etc/fstab – Mount Drives at Boot


Purpose: Lists disks/partitions to mount at boot.

Command:
cat
/etc/fstab
Output:
ini

UUID=... / ext4 defaults 0 1

Be careful editing this! Mistakes can prevent booting.


🔒 9. /etc/sudoers – Sudo Permissions

Purpose: Controls who can use sudo.

Proper Way to Edit:


sudo visudo
Output Snippet:
sql kali
ALL=(ALL:ALL) ALL

Never directly edit this file with nano or vi. Use visudo to prevent syntax errors.

🛑 10. /etc/apt/[Link] – Repositories Purpose:

Defines the source URLs for package updates.

Command:
cat
/etc/apt/[Link]
Output Example:
cpp deb [Link] kali-rolling main non-free
contrib If broken: Reset using:

echo "deb [Link] kali-rolling main non-free contrib" |


sudo tee /etc/apt/[Link] sudo apt update

📚 Bonus: How to Edit Configuration Files Safely


Use nano, vim, or gedit
sudo nano
/etc/hosts

• Ctrl+O: Save
• Ctrl+X: Exit

✅ Summary Table
File Purpose
/etc/passwd User info
/etc/shadow Passwords (hashed)
/etc/hostname System hostname
/etc/hosts Local DNS
/etc/[Link] DNS servers
/etc/network/interfaces Manual network setup
/etc/fstab Disk mounting
File Purpose
/etc/sudoers Sudo user permissions
/etc/apt/[Link] Kali software sources
/etc/NetworkManager/* NetworkManager settings

📂 What is ls?
The ls command is used to list directory contents. It helps you see what files or folders are
inside a directory.

🔹 Basic Usage
ls

Example Output:
nginx
Documents Downloads Music Pictures [Link]

Explanation: Shows a simple list of files and directories in the current working directory
(where you are).

🔹 Detailed View: ls -l
ls -l

Example Output:
yaml

-rw-r--r-- 1 kali kali 1234 Apr 8 12:00 [Link]


drwxr-xr-x 2 kali kali 4096 Apr 7 15:10 Projects

Breakdown of Each Part:

Field Explanation
-rw-r--r-- File type & permissions (file: -, dir: d)
1 Number of hard links kali
Owner (user)
kali Group
1234 File size in bytes
Apr 8 12:00 Last modified date/time
[Link] Filename

🔹 Show Hidden Files: ls -a


ls -a

Output:

. .. .rc .profile Documents [Link]

• . → current directory
• .. → parent directory
• .rc → hidden file (starts with a dot)
🔹 Combine Flags: ls -la
ls -la

Effect: Shows all files, including hidden, with detailed info.

🔹 Human-Readable Sizes: ls -lh


ls -lh
Output:
css
-rw-r--r-- 1 kali kali 1.2K Apr 8 12:00 [Link]

• 1.2K: Easier to read than 1234 bytes.

🔹 List by Modification Time: ls -lt


ls -lt

Effect: Shows files sorted from most recently modified to oldest.

🔹 Reverse Order: ls -ltr


ls -ltr

Effect: Oldest modified files listed first (useful for log review, backups).

🔹 Classify Files: ls -F
ls -F

Output Example:

[Link] [Link]* mydir/

• * → executable
• / → directory
🔹 List Specific File Types
Show only directories:
ls -l | grep "^d"

Show only regular files:


ls -l | grep "^-"

🧠 Advanced Example: Combined Flags


ls -alh --
color=auto
Explanation:
• -a: All files
• -l: Long format
• -h: Human-readable sizes
• --color=auto: Adds color to make types easier to see (Kali does this by default)

🔧 Practical Scenario
Let’s say you’re checking file permissions for a reverse shell script:
ls -l
[Link]
Output:
css

-rw-r--r-- 1 kali kali 254 Apr 8 13:00 [Link]

• It’s not executable yet. So you fix it:


chmod +x
[Link] Then
check again:
ls -l
[Link] New
Output:
diff
-rwxr-xr-x 1 kali kali 254 Apr 8 13:00 [Link] ✅

Now it's executable.

✅ Summary Table
Command What it does
ls Basic list
ls -l Detailed view with permissions
ls -a Show hidden files
ls -lh Human-readable sizes
Command What it does
ls -lt Sort by modified time
ls -ltr Reverse time order
ls -F Classify files with symbols
ls -alh All + long + human-readable sizes
`ls -l grep "^d"`

1. Creating a New User

sudo adduser newusername

 Explanation: Adds a new user with a home directory.


 Practical:

sudo adduser alice

🔹 2. Setting/Changing a Password

sudo passwd username

 Example:

sudo passwd alice

🔹 3. Adding User to a Group


sudo usermod -aG groupname username

 Explanation: Adds user to a group without removing them from others.


 Example:

sudo usermod -aG sudo alice

🔹 4. Creating a Group

sudo groupadd groupname

 Example:

sudo groupadd hackers

🔹 5. Adding a User to Multiple Groups

sudo usermod -aG group1,group2 username

 Example:

sudo usermod -aG sudo,hackers alice

🔹 6. Switching User

su - username

 Example:

su - alice

🔹 7. Listing User Information

id username
 Example:

id alice

🔹 8. List All Users

cat /etc/passwd

 Explanation: Each line = one user, format: username:x:UID:GID:info:home:shell

🔹 9. List All Groups

cut -d: -f1 /etc/group

🔹 10. Delete User

sudo deluser username

 With home directory:

sudo deluser --remove-home alice

🔹 11. Delete Group

sudo groupdel groupname

🔹 12. Changing File Permissions

chmod [permissions] filename

 Example:

chmod 755 [Link]


Symbolic Meaning

r read

w write

x execute

 Numeric Format:
o 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--, etc.

🔹 13. Changing Ownership

sudo chown user:group filename

 Example:

sudo chown alice:alice [Link]

🔹 14. Default Shell for a User

chsh -s /bin/ username

🔹 15. Switch to Root

sudo -i

🔹 16. Give Sudo Privileges to a User

sudo usermod -aG sudo username

🔹 17. Edit Sudoers File (Be Careful!)

sudo visudo

 Add this line to give full privileges:

sql
alice ALL=(ALL:ALL) ALL

🔹 18. Special Permissions: SUID


✔️SUID (Set User ID on execution)

chmod u+s filename

 Example:

sudo chmod u+s /bin/


ls -l /bin/

 Look for s in the permissions:

diff

-rwsr-xr-x

🛑 WARNING: SUID on sensitive binaries is a major security risk.

✔️Find SUID Binaries

find / -perm -4000 -type f 2>/dev/null

🔹 19. Sticky Bit

Used on directories to restrict deletion to file owners.

chmod +t /directory

 Example:

chmod +t /tmp

🔹 20. SGID (Set Group ID)

chmod g+s directory

 Files created will inherit the group of the directory.


🔹 21. Check Current User

whoami

🔹 22. Check Logged-in Users

who

🔹 23. List User Sessions

🔹 24. See Last Login

last username

🔹 25. Environment Variables for User

env

🔹 26. List Shells Available

cat /etc/shells

🔹 27. Create User Without Home Directory

sudo useradd -M username

🔹 28. Lock/Unlock a User

sudo passwd -l username # Lock


sudo passwd -u username # Unlock
🔹 29. Force Password Change on First Login

sudo chage -d 0 username

🔹 30. See Password Expiration Info

chage -l username

31. List Directory Contents

ls -l

 Example:

ls -l /etc

 Output:

yaml

drwxr-xr-x 5 root root 4096 May 9 11:00 network


-rw-r--r-- 1 root root 2365 May 8 10:00 hosts

🔸 32. Create a Directory

mkdir dirname

 Example:

mkdir testfolder

🔸 33. Remove a File or Directory

rm filename # Remove file


rm -r directory # Remove directory

 Example:
rm -r testfolder

🔸 34. Move/Rename File

mv oldname newname

 Example:

mv [Link] [Link]

🔸 35. Copy Files or Folders

cp file1 file2 # Copy file


cp -r dir1 dir2 # Copy directory

 Example:

cp -r folder1 folder2

🔸 36. Search for Files

find /path -name filename

 Example:

find /etc -name hosts

 Output:

/etc/hosts

🔸 37. Monitor Running Processes

top
 Live display of CPU/memory usage, like Task Manager.

🔸 38. Kill a Process

kill PID

 Find PID:

ps aux | grep firefox

 Kill it:

kill 1234

🔸 39. Check Disk Usage

df -h

 Output:

nginx

Filesystem Size Used Avail Use% Mounted on


/dev/sda1 50G 15G 32G 33% /

🔸 40. Check Directory/File Size

du -sh foldername

 Example:

du -sh /etc

 Output:

12M /etc
🔸 41. Monitor Network Connections

netstat -tuln

 Shows open TCP/UDP ports.

🔸 42. Ping a Host

ping -c 4 [Link]

 Output:

python

64 bytes from [Link]: icmp_seq=1 ttl=118 time=21.5 ms

🔸 43. Display Network Interfaces

ip a

 Or:

ifconfig

🔸 44. Change IP Address Temporarily

sudo ip addr add [Link]/24 dev eth0

🔸 45. Download Files (CLI)

wget [Link]

🔸 46. Extract Compressed Files

tar -xvf [Link] # Extract .tar


tar -xzvf [Link] # Extract .[Link]
unzip [Link] # Extract .zip
🔸 47. Check System Info

uname -a

 Output:

nginx

Linux kali 6.3.0-kali3-amd64 #1 SMP Debian 6.3.3-1kali1 ...

🔸 48. Check Memory Usage

free -h

 Output:

makefile

total used free


Mem: 7.6G 3.2G 4.4G

🔸 49. Edit Files

nano filename

 Simple text editor in terminal.

🔸 50. Check Listening Services

ss -tuln

🔸 51. View Kernel Logs

dmesg | less

🔸 52. Check Login History


last

🔸 53. Get Command Location

which nmap

 Output:

/usr/bin/nmap

🔸 54. Make a Script Executable

chmod +x [Link]

🔸 55. Schedule Tasks with Cron

crontab -e

 Add job:

arduino

* * * * * /home/user/[Link]
1. Add a User

Command:

bash
CopyEdit
sudo adduser student1

Explanation:

 Creates a new user student1.


 Prompts you to set a password and optional user details (name, room, etc.).

🔹 2. Delete a User

Command:

bash
CopyEdit
sudo deluser student1

Explanation:

 Deletes user student1.


 Does not delete their home directory.

To delete the user and their home directory:


bash
CopyEdit
sudo deluser --remove-home student1

🔹 3. Create a Group

Command:

bash
CopyEdit
sudo addgroup testers

Explanation:

 Creates a group named testers.

🔹 4. Delete a Group

Command:

bash
CopyEdit
sudo delgroup testers

Explanation:

 Deletes the group testers.

🔹 5. Add User to a Group

Command:

bash
CopyEdit
sudo usermod -aG testers student1

Explanation:

 Adds user student1 to group testers.


 -aG: Append (add without removing from other groups).

🔹 6. View User Group Memberships

Command:

bash
CopyEdit
groups student1

Example Output:

yaml
CopyEdit
student1 : student1 testers

🔹 7. Create a Sudo (Admin) User

Command:

bash
CopyEdit
sudo usermod -aG sudo student1

Explanation:

 Adds student1 to the sudo group.


 Gives them admin rights to use sudo.

Verify with:

bash
CopyEdit
sudo -l -U student1

🔹 8. Check All Users

Command:

bash
CopyEdit
cut -d: -f1 /etc/passwd

Explanation:

 Shows all local system users.

🔹 9. Check All Groups

Command:

bash
CopyEdit
cut -d: -f1 /etc/group

Or to list groups for a specific user:


bash
CopyEdit
id student1

🔹 10. Switch to a Different User

Command:

bash
CopyEdit
su - student1

Explanation:

 Switches to user student1 (use password when prompted).

🔹 11. Delete User from a Group

Command:

bash
CopyEdit
sudo gpasswd -d student1 testers

Explanation:

 Removes student1 from group testers.

🔹 Summary Table
Task Command Example

Add User sudo adduser student1

Remove User sudo deluser student1

Remove User & Home sudo deluser --remove-home student1

Add Group sudo addgroup testers

Delete Group sudo delgroup testers

Add User to Group sudo usermod -aG testers student1

Make User Admin (sudo) sudo usermod -aG sudo student1

Remove User from Group sudo gpasswd -d student1 testers

Show User Groups groups student1

List All Users cut -d: -f1 /etc/passwd


Task Command Example

List All Groups cut -d: -f1 /etc/group

Switch User su - student1

You might also like