Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to create a new user account with password in more than 200 systems. What will be the easiest way? Is it possible to do this task via bash script or perl script?

share|improve this question
    
Have a look at the commands addgroup and adduser. –  Paddy Landau Jul 21 '12 at 18:58
add comment

2 Answers 2

up vote 3 down vote accepted

Generate the password with perl perl -e 'print crypt("passwd", "passwd");'.

Then just use a bash script to call useradd via ssh on each server (assuming you already setup ssh keys for password-less login, otherwise this will get old, fast)

pass=$(perl -e 'print crypt("passwd", "passwd");')
for srv in $(cat server.list); do
   ssh $srv useradd -m -p "$pass" username
done

and check the manpage for the useradd command Manpage icon.

share|improve this answer
add comment

I would suggest to use ansible if you want to create a user account across a large number of servers. Ofcourse, it's not limited to just user accounts and it's very easy to get setup and started with using ansible. The documentation is quite nice!

All you do is add all your 200 servers into an inventory file and run a simple command to create all the accounts. Take a look at this example of adding a user.

share|improve this answer
    
Could you share here an example, on using ansible with ssh private key.. –  karthick87 Jan 16 '13 at 7:51
    
As part of your initial setup of ansible you will be adding your ssh private key to ssh-agent, see the Getting Started section. The example itself would just be that one line command as shown in the example link I have given above. viz. ansible all -m user -a "name=test1 comment=TestUser1 group=users shell=/bin/bash" –  Amar Jan 17 '13 at 12:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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