How do I add to an Ubuntu system many users at once?

I have a list of over 40 students, that I want to add as users to my Ubuntu server. I do not wantto do “adduser” for each of them separately. Is there an easy way to add all of them at once? For example, can I create a CSV file with usernames and passwords, and create a username for each row of the file?

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
January 5, 2023
Accepted Answer

Hi @erel,

You can create a list of users and passwords and then use a small bash script to go through them.

Let’s assume the list looks like this:

  1. # File named studentusers
  2. user1-password1
  3. user2-password2
  4. user3-password3

Your bash script will look like:

# Run script with SUDO
for user in $(cat /root/studentusers); do
  STUDENT=$(echo $user | awk -F"-" '{print $1}')
  STUDENT_PASSWORD=$(echo $user | awk -F"-" '{print $2}')
  useradd $STUDENT
  echo "${STUDENT}:${STUDENT_PASSWORD}" | chpasswd

To create the script, ssh to your Droplet, create a file called and put the above contents in it. Additionally, don’t forget to create the studentusers file in your /root directory.

Once that is done, just execute the following sudo bash

That should do the trick.

Site Moderator
Site Moderator badge
January 10, 2023

Hello @erel

What I can add as an idea is to use random passwords for the usernames and not re-using the same password or just changing the last digit, as in my experience students usually tend to abuse a system during exams and are often able to find the pattern in the username/password generation.