If you create new users (as root) using
# useradd –m tux
You will have created a newuser with it being disabled. This means that the password entry (the 2nd column) in the /etc/shadow will have a ! as the entry, i.e.
tux:!:14343:0:99999:7:::
You can use a script to go through it and change the ! to the encrypted password (which you can create earlier) but you must be aware that existing users that are disabled will have the 2nd field starting with !.
The -p option on useradd will require the encrypted password as the given parameter. This will be cumbersome if you are trying to use the script to create a set of new users and you will have to encrypt the individual passwords prior to using the useradd with the -p option.
In order to create a newuser with a password assigned, you can use
# useradd –m tux
# echo welcome | passwd –stdin tux
Or you can copy the following script and use it to create a new user with password and home directory.
#!/bin/sh
if [ $# –ne 2 ]; then
echo “Usage: $0 <username> <password>”
exit 1
fi
useradd –m $1
echo $2 | passwd –stdin $1
There are other ways to do it as well, but this is an easy way to understand it. Have fun!



No comments yet.