1

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.

1 Answers1

1

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)
 do
    useradd -m -d /home/top100/${user} ${user}
 done
MelBurslan
  • 6,966
  • 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