I am in the process of creating 60 users locally in a linux machine. I wanted to do it automatically and so I found I can use the newusers command to add the users in batch. I have the users and password list a text file. Currently, I have the text file in the below format.


However, for the newusers command, I need to have the file in the following format.


I need to modify the text file to append the UID, group ID and the user home path and the user shell. Is there an easier way than this?


Modifying the file is easy enough, just loop through your username:pass file:

k=1000; while IFS=: read user pass; do 
             echo "$user:$pass:$k:1000:/home/$user:/bin/bash"; let k++;
        done <  users.txt > newusers.txt

This will create a file called newusers.txt with the following content:

  • it creates the newusers.txt file as expected. But I am getting an error as, **bash: 1=1000: command not found **. Also, the value of $k is assigned from 1.
    – Ramesh
    Oct 28 '13 at 17:49
  • @Ramesh I think I see. The $ in my answer represents the prompt, it should not be included when you run it. See updated answer.
    – terdon
    Oct 28 '13 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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