-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_add_batch.sh
More file actions
56 lines (40 loc) · 1.5 KB
/
Copy pathuser_add_batch.sh
File metadata and controls
56 lines (40 loc) · 1.5 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
#!/bin/bash
# Developed by DevTae@2023
# declare users with username and password
declare -A pwds_normal
pwds_normal["user1"]="password1"
pwds_normal["user2"]="password2"
pwds_normal["user3"]="password3"
declare -A pwds_admin
pwds_admin["admin1"]="password1"
pwds_admin["admin2"]="password2"
pwds_admin["admin3"]="password3"
# create the users using useradd script
echo "the account creation process is starting ..."
useradd -D -s /bin/bash # Default setting /bin/bash (shell)
for _key in ${!pwds_normal[@]}
do
pwd=$(perl -e 'print crypt($ARGV[0], "password")' ${pwds_normal[$_key]})
useradd -m -p "$pwd" $_key # m is option of making home directory
echo "the user ${_key} is created."
done
for _key in ${!pwds_admin[@]}
do
pwd=$(perl -e 'print crypt($ARGV[0], "password")' ${pwds_admin[$_key]})
useradd -m -r -p "$pwd" $_key # r is option of having administrator features
echo "the admin ${_key} is created."
done
echo "the account creation process is completed."
# the section of setting sudoers.d files
echo "the process of the setting sudoers.d is starting ..."
for _key in ${!pwds_normal[@]}
do
echo "${_key} ALL=(ALL) /usr/bin/docker" | sudo tee /etc/sudoers.d/$_key > /dev/null
echo "the user ${_key}'s sudoers.d file is set."
done
for _key in ${!pwds_admin[@]}
do
echo "${_key} ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/$_key > /dev/null
echo "the admin ${_key}'s sudoers.d file is set."
done
echo "the process of the setting sudoers.d is completed."