This question already has an answer here:

I have 100 names no passwords and i have to create accounts for them under directory /home/top100

how do I do this? Because using useradd 100 times does not sound fun, and even if i did, I have no clue how o make the accounts appear under /home/top100/ directory.

marked as duplicate by steeldriver, Gilles, don_crissti, Jeff Schaller, jw013 Feb 11 '16 at 1:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Assuming usernames are one per line or separated by one or more spaces, in the listfile, you can use this :

 for user in $(cat listfile)
    useradd -m -d /home/top100/${user} ${user}
  • I'll be honest I get its a bash script but I have no clue how to compile it or how to run it. – Pursuer of Dying Stars Feb 10 '16 at 23:14
  • just type it line by line on the command prompt, as you see it written above, changing the listfile to the name of the file in which your users are listed – MelBurslan Feb 10 '16 at 23:16
  • I get an error saying: useradd: cannot create directory /home/top100/niumor and he end changes based on username. – Pursuer of Dying Stars Feb 10 '16 at 23:23
  • so if you want all your 100 users to use the same home directory, change the useradd command line to this: useradd -d /home/top100 ${user} assuming this directory already exists – MelBurslan Feb 10 '16 at 23:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.