-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock-user.sh
50 lines (46 loc) · 1.38 KB
/
lock-user.sh
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
#!/bin/bash
# Show only the last five users
echo "************"
echo "Show only the last five users: "
cut -d: -f1 /etc/passwd | tail -n 5
echo "************"
# Get username from user
echo "\e[91m************\e[0m"
read -p "Enter the username you want to lock/unlock: " username
echo
# Check if user exists
if id "$username" >/dev/null 2>&1; then
# Check if user is currently locked
if sudo passwd -S "$username" | grep -q ' LK '; then
echo "User is currently locked. Do you want to unlock the user? (y/n)"
read unlock_user
if [[ "$unlock_user" == "y" ]]; then
sudo passwd -u "$username"
echo "User '$username' has been unlocked."
else
echo "Aborting unlocking of user."
exit 1
fi
else
echo "User is currently unlocked. Do you want to lock the user? (y/n)"
read lock_user
if [[ "$lock_user" == "y" ]]; then
sudo passwd -l "$username"
echo "User '$username' has been locked."
pkill -u "${username}"
echo "User '$username' has been was fired."
else
echo "Aborting locking of user."
exit 1
fi
fi
else
echo "User '$username' does not exist."
exit 1
fi
# Show only the last five users
echo "************"
echo "Show only the last five users: "
cut -d: -f1 /etc/passwd | tail -n 5
echo "************"
exit 0