Pages

Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts

Sep 10, 2011

A Bash Script to Create Multiple User Accounts in a Batch

There are a lot of introductions on the Internet about how to create multiple user accounts in a batch with "newusers" command. But in this way, there are some problems about the environment variables. The system will not initialize the ".bashrc" and the ".bash_proflie" files.

Here is anther way to create multiple user accounts with "useradd" command.
#!/bin/bash
password="123456"
for USER in $(cat example_userlist)
do
    useradd -m $USER
    echo -e "${password}\n${password}" | passwd $USER
done
The password of all the users is "123456", it can be changed in the second line.

In this script, the "example_userlist" is a list of user names, the format of this file is like this:
user1
user2
user3
...
Enjoy!