I teach a programming course with over 40 students. I want them to upload their projects to a Linux web server that I rent. So I want each student to create a user account on the server. I do not want to create each and every user manually by adduser.

Is it possible to let students create their own accounts, without giving them root access?

2 Answers 2


Yes. You can use other PAM modules than the default pam_unix.so and other NSS modules that default files.

If you are in some institution, odds are your students are already having accounts in some general directory, accessible via LDAP. In that case, pam_ldap and nss_ldap are your friends, you just link up the system to the directory and all users defined there could be your potential accounts. Popular directories like MS AD have dedicated PAM and NSS providers and supporting software which make it easier to configure and manage and provide for additional features like group policies and so on.

If not, you can use RDBMS modules like pam_mysql and nss_mysql to provide system authentication and user lookup against some table in the database. The records in the database may be created via self-registration web form, like the one you used to register in StackExchange web sites, and the similar form could provide the password reset/change.

A little note of warning here. When I built such a solution, I noticed that it is problematic to host MariaDB providing authentication on the same server. It failed to start. Probably my the problem was possible to solve by using even more advanced PAM configuration, nonetheless, I was able to host it on the nearby cluster, so it wasn't a big problem for me. YMMV.


If you don't want to go through trying to link an already defined database of logins, you could always script the user creation using bash scripting. Would be simple enough to create a text file containing all user names and temp passwords then loop through them with a bash script. Print out that text file afterward and cut the paper, pass out the temp passwords to the students and have them go in and change it afterward.

Starting with a list of your username you intend to add: users.txt (each line of the file is a username that you intend to add)


then, your bash script: addusers.sh


# reads your user.txt file while removing carriage returns
users=$(cat users.txt | tr -d '\r') 

# loop over each line in your user.txt file and adds that line as a user
for user in $users; do
# creates the user
sudo useradd -m "$user"
# user has no password
sudo passwd -d "$user"

while logged into the server with a sudo permissions account, run chmod u+x addusers.sh to make the script executable then, run said script with ./addusers.sh

Bonus: at the end of the year, you want to clean up the server you can use a script to wipe all those users as well (recommend using a different file for users you wish to delete so as to not accidentally delete users that are still using their account)


users=$(cat delusers.txt | tr -d '\r')

for user in $users; do
sudo deluser --remove-home "$user"

NOTE: all these files should be kept in the same folder as each other

  • Welcome to the site. Your answer might profit if you edited it to contain an example script-let.
    – AdminBee
    Commented Jun 13, 2023 at 13:58
  • Read man chage - you can set things up so the student/user initially has no password, but must change it immediately. You can also forbid logins after the End-of-Course date.
    – waltinator
    Commented Jun 14, 2023 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .