kepper
Tue Jul 02 2024 21:07:09 GMT+0000 (Coordinated Universal Time)
Saved by
@chrixsaint
while IFS=';' read -r username groups; do
# Remove whitespace
username=$(echo "$username" | xargs)
groups=$(echo "$groups" | xargs)
# Create user and personal group
if id "$username" &>/dev/null; then
echo "User $username already exists." | tee -a "$LOG_FILE"
else
useradd -m -s /bin/bash -G "$groups" "$username"
echo "User $username created." | tee -a "$LOG_FILE"
# Create a random password
password=$(openssl rand -base64 12)
echo "$username:$password" | chpasswd
echo "$username,$password" >> "$PASSWORD_FILE"
# Set up home directory permissions
chown "$username:$username" "/home/$username"
chmod 700 "/home/$username"
echo "User $username added to groups: $groups" | tee -a "$LOG_FILE"
fi
done < "$USER_FILE"
content_copyCOPY
Comments