User Management in Linux
System administrators need to add more than a few users at a time. The graphical applets available in the various Linux desktops can only add a user at a time. This small tutorial presents a series of perl scripts to add many users at a time.
- The basic assumption is that a text file with the first and last name of the users is available as input. This file will be called list.txt in the scripts of this tutorial. It may also contain other information. In the tutorials e-mail is also available, but these other pieces of information will not be used. The first and last name and other information are separated by a comma (,). So John Doe, will be John,Doe in the file.The list.txt file will be input for two scripts: addaccounts and createpass.
- The addaccounts script will create a file called addscript with the commands necessary to create the user accounts when executed. The usernames will be comprised of the first initial and last name of the user. John Doe username would be jdoe. Each line of the file will be of the format useradd - c "name" username. For example the line for John Doe would be useradd -c "John Doe" jdoe .
- The createpass script will create a file called passad with the information necessary to assign passwords to the recently created accounts. In this very simplified script the password will be the same as the username, which the user is supposed to change at the first login. Each line of the file will be of the format username:username. In the case of John Doe it would be jdoe:jdoe. This file is used as input to the Linux standard command chpasswd: chpasswd < passadd .
- Finally, only one script needs to be run by the administrador: addstudents. This script runs addacount, createpass, etc, as shown below:
addaccounts
addscript
createpass
chpasswd < passadd
If you select the above links you can download each script.
This page is maintained by Al Bento
who can be reached at abento@ubalt.edu. This page was last updated on February 7, 2005. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.