By erel
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?
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!
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:
- # File named studentusers
- user1-password1
- user2-password2
- user3-password3
Your bash script will look like:
#!/bin/bash
# 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
done
To create the script, ssh to your Droplet, create a file called createusers.sh
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 createusers.sh
That should do the trick.
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.
Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.