-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes_servicemonitor.sh
24 lines (24 loc) · 1.02 KB
/
es_servicemonitor.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
#!/bin/bash
# This script is part of the EventSentry repository
# Purpose - Script to add a user to Linux system including passsword.
# Also will grant the user access to start and stop services by creating a file
# with the same namne as the username inside sudoers.d
# -----------------------------------------------------------------------------
# Am i Root user?
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
useradd -m "$username"
passwd "$username"
echo $username ALL=NOPASSWD: /bin/systemctl start \* >/etc/sudoers.d/$username
echo $username ALL=NOPASSWD: /bin/systemctl stop \* >>/etc/sudoers.d/$username
echo $username ALL=NOPASSWD: /bin/systemctl start \* >>/etc/sudoers.d/$username
fi
else
echo "Only root may add a user to the system."
exit 2
fi