Skip to content

Commit

Permalink
開発用計算機にユーザを追加するスクリプトを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
Geson-anko committed Jul 22, 2024
1 parent 5e266da commit 61bbdd1
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/add-dev-users.sh
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."

0 comments on commit 61bbdd1

Please sign in to comment.