-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_menu.sh
More file actions
executable file
·67 lines (57 loc) · 1.55 KB
/
user_menu.sh
File metadata and controls
executable file
·67 lines (57 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# FILE: create_user.sh
# USAGE: create_user.sh OR create_user <username> (Generated default password) OR create_user <username> <password>
# AUTHOR: LudwigJL
# VERSION: 1.2
# NOTES/BUGS:
# CREATED AT: 31-01-2025
# PARAMETERS: <username> as $1 <password> as $2
# NOTES: This script streamlines the process of creating users within the linux env. This was written on an Ubuntu system.
prompt_user () {
message="${1:-"Enter the account details"}"
echo "$message"
read -p "Enter a username: " user_name
read -sp "Enter a password: " user_password
echo ""
read -sp "Enter the password again: " user_password_check
echo ""
}
check_user () {
grep -q \^${1}\: /etc/passwd && return 0
}
create_user () {
prompt_user "Enter new user account details"
while check_user "$user_name" ; do
prompt_user "The username you have chosen already exists, please re-select fresh details"
done
while [ "$user_password" != "$user_password_check" ] ; do
prompt_user "Passwords didn't match, re-enter the details"
echo ""
done
sudo useradd -m "$user_name"
echo "${user_name}:$user_password" | sudo chpasswd
echo "$user_name created"
}
delete_user () {
read -p "Enter user to delete: " user_name
while ! check_user "$user_name" ; do
echo "User not found"
return 1
done
sudo userdel -r $user_name
echo "$user_name deleted"
}
while true ; do
clear
echo "user management"
echo "1: Create User"
echo "2: Delete User"
echo "3: Exit"
read -sn1
case "$REPLY" in
1) create_user;;
2) delete_user;;
3) exit 0;;
esac
read -n1 -p "Press any key"
done