forked from MLShukai/ami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e266da
commit 61bbdd1
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
# User List | ||
users=("geson" "zassou" "myxy" "klutz" "bunnchinn" "suisen") | ||
|
||
# Password Information | ||
declare -A user_passwords | ||
|
||
# Add User Function | ||
add_user() { | ||
local username=$1 | ||
|
||
# Generate Random Initial Password | ||
local initial_password=$(openssl rand -base64 12) | ||
|
||
# Add User | ||
sudo useradd -m -s /bin/bash $username | ||
|
||
# Set Initial Password | ||
echo "$username:$initial_password" | sudo chpasswd | ||
|
||
# Force Password Change on Next Login | ||
sudo passwd -e $username | ||
|
||
# Add User to docker group | ||
sudo usermod -aG docker $username | ||
|
||
# Create User-Specific Configuration File in sudoers.d | ||
echo "$username ALL=(ALL) /usr/bin/apt, /usr/bin/docker, /bin/cat" | sudo tee /etc/sudoers.d/$username | ||
|
||
# Set Correct Permissions for Configuration File | ||
sudo chmod u=r,g=r,o= /etc/sudoers.d/$username | ||
|
||
echo "User $username has been added and has sudo rights and docker group." | ||
|
||
# Save Password Information to Array | ||
user_passwords[$username]=$initial_password | ||
} | ||
|
||
# Main Process | ||
for user in "${users[@]}"; do | ||
if id "$user" &>/dev/null; then | ||
echo "User $user already exists." | ||
else | ||
add_user $user | ||
fi | ||
done | ||
|
||
echo "User addition process completed." | ||
echo "---------------------------------------" | ||
echo "User name and password list:" | ||
for user in "${!user_passwords[@]}"; do | ||
echo "$user : ${user_passwords[$user]}" | ||
done | ||
echo "---------------------------------------" | ||
echo "Please keep these passwords safe and inform each user directly." |