This mini project allows:
1️⃣ Add User
2️⃣ Delete User
3️⃣ Modify User
4️⃣ View User Info
5️⃣ List All Users
6️⃣ Exit
⚠️ Note: Must run as root user (use sudo ./script.sh)
Script: user_management.sh
#!/bin/bash
while true
do
echo "------------------------------"
echo "1. Add User"
echo "2. Delete User"
echo "3. Modify User"
echo "4. View User Info"
echo "5. List All Users"
echo "6. Exit"
echo "Enter your choice:"
read choice
case $choice in
1)
echo "Enter username to add:"
read uname
sudo useradd $uname
if [ $? -eq 0 ]
then
echo "User added successfully."
sudo passwd $uname
else
echo "Error adding user."
fi
;;
2)
echo "Enter username to delete:"
read uname
sudo userdel -r $uname
if [ $? -eq 0 ]
then
echo "User deleted successfully."
else
echo "Error deleting user."
fi
;;
3)
echo "Enter username to modify:"
read uname
echo "Enter new home directory:"
read home
sudo usermod -d $home -m $uname
echo "User modified successfully."
;;
4)
echo "Enter username to view info:"
read uname
id $uname
;;
5)
echo "System Users:"
cut -d: -f1 /etc/passwd
;;
6)
echo "Exiting program..."
break
;;
*)
echo "Invalid choice!"
;;
esac
done
✅ How to Run
chmod +x user_management.sh
sudo ./user_management.sh
🎯 Important Commands (Viva)
useradd→ create useruserdel -r→ delete user with home directoryusermod→ modify userpasswd→ set passwordid→ show user information/etc/passwd→ contains user details
🔥 Example Output
1. Add User
2. Delete User
3. Modify User
4. View User Info
5. List All Users
6. Exit
Enter your choice: