2

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.

user1:password1
user2:password2
user3:password3

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

user1:password1:1011:1000:user1:/home/user1:/bin/bash

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?

1 Answer 1

2

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:

user1:password1:1000:1000:/home/user1:/bin/bash
user2:password2:1001:1000:/home/user2:/bin/bash
user3:password3:1002:1000:/home/user3:/bin/bash
2
  • 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, 2013 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, 2013 at 17:51

You must log in to answer this question.

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