7

I need to create bunch of new users with given password. What I want is a script that I would pass the user name of new user and it will create/add the user and set its password. (the password is the same for all new users - no security issues here.)

Any suggestions how to do that on SuSE from command line?

Radek
  • 2,993
  • 18
  • 39
  • 52

4 Answers4

8

Does SuSE useradd have the -p option? That takes the password (albeit in encrypted form, but you should be able to generate that I think).

So useradd -p <crypt'ed password> <new username> should do it I think

lxop
  • 255
  • Yes, it does have it. -p password Encrypted password as returned by crypt(3) any idea how I can generate it from a text? – Radek Jul 17 '12 at 04:56
  • 1
    This site appears to have everything you need: http://www.cyberciti.biz/tips/howto-write-shell-script-to-add-user.html – lxop Jul 17 '12 at 05:03
0

You can create a shell script like this:

#!/bin/bash
echo "Type the username:"
read USERNAME
echo "Type the pass:"
stty -echo
read PWD
stty echo
useradd -p ${PWD} ${USERNAME}
0

Can be done in two steps.

  1. First create users with useradd command
  2. On the second run something like this
    cat 1.txt | while read line; do echo "12345" | passwd --stdin $(echo ${line}); done
    
    where 1.txt is a file containing the list of logins.
AdminBee
  • 22,803
andrey
  • 1
0
for i in `cat userlist`
do
useradd $i
echo "$i:your_password"|chpasswd
done

userlist should contain list of users to be created.

Archemar
  • 31,554
  • Welcome to the site, and thank you for your contribution. Please note, however, that the "backtick"-style for command substitutions is deprecated, and the $( ... ) style should be used instead. – AdminBee Aug 05 '20 at 15:11