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"
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter