write a script that will create user accounts

how to create a script that will add 20 user accounts to the system. The usernames should be a user0 – user19. The uid for the users should be 5000-5019. The comment should be “Regular system user”. The user’s primary group should be system_users.

>Solution :

For Linux (exec as root)

START_ID=5000
USER_GRP="system_users"
USER_CMT="Regular system user"
USER_SHELL="/usr/bin/bash"

for ((i=0; i<20; i++))
do
   USER_ID=$((START_ID+$i))
   useradd -u ${USER_ID} -g ${USER_GRP}  -c "${USER_CMT}" -s ${USER_SHELL} user${i}
done

Leave a Reply