Sponsored Content
Full Discussion: Useradd issue
Operating Systems Linux Red Hat Useradd issue Post 302410157 by maverick_here on Monday 5th of April 2010 06:23:38 AM
Old 04-05-2010
Useradd issue

Hi all,

I'm using Red Hat Enterprise Linux Server release 5 (Tikanga)

I have a query regarding adding users, I have a requirement of creating multiple users at one go.
In order to do so I have written a shell script which would create a user and set the password at one go.
Now the problem is

1] Setting password.

I have tried two approcahes

Code:
password=`echo "PASSWORDSTRING"|md5sum`

useradd -p $password $username

and

Code:
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)

useradd -p $pass $username

In both the cases I'm able to create user without a problem.How ever when i try to login as the user Im unabel to as the password is in correct.

Following is the script

Code:
if [ $(id -u) -eq 0 ]
then
cat /root/newlis|while read IN
do
        username=`echo $IN|awk -F ":" '{print $2}'`
        password=`echo $IN|awk -F ":" '{print $3}'`
        egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]
then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
grep "$username" /etc/passwd >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo "User $username added" >> /root/user.log
else
echo "Problem adding $username"
fi
fi
done
else
echo "Only root may add a user to the system"
        exit 2
fi


Please suggest.

Thanks and Regards
Syed

---------- Post updated at 03:53 PM ---------- Previous update was at 03:13 PM ----------

Well ,the intresting thing is the passwords are valid as I m doing as follows

I m logged in as root so I am

Code:
su - newuser

passwd

it asks me for old pasword and then lets me change the pasword without any errors.Which means the password assigned by the script is OK ,its only that iam unable to login for some reason.

Last edited by pludi; 04-05-2010 at 08:20 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

useradd

I work on some hp ux 11.00 Servers. i have to add an user. i use the useradd command like follows: useradd -u 72022 -g 71095 -c " comment " -d /PACKAGE_NAME/home/username -s /usr/bin/sh username The command returns with error 3. The manpage means value number 3: Invalid argument supplied to an... (6 Replies)
Discussion started by: ortsvorsteher
6 Replies

2. UNIX for Advanced & Expert Users

useradd

Hi. due to some needs i gave a user the premission to use useradd command with sudo. i want to know if there is a way to let him set the initial password, without giving him the premission to use passwd command as root (sudo). maybe a way to set a default password for all the new users that... (2 Replies)
Discussion started by: dorilevy
2 Replies

3. Solaris

useradd

Hi, I need to add a new user who will only be able to access one single folder on my Solaris 9 system. Can this be achieved by using just useradd or do i need to fiddle with auth_attr table? TIA, Selma (4 Replies)
Discussion started by: Selma
4 Replies

4. UNIX for Dummies Questions & Answers

useradd question

The man pages for useradd show the -k flag as a option, problem is I don't know what the description means. Could someone explain what "an alternative skel directory" is? Is skel an acronym? Thanks From the man page: -k, --skel skeldir Specify an alternative skel... (1 Reply)
Discussion started by: thumper
1 Replies

5. Shell Programming and Scripting

useradd

Gurus, I need to add a user to all the machines. I need a script to do this. I did one but it does not allow me to su to root within a ssh session i open. It exists saying su: Sorry. Please let me know how i can do it. I do not have the freedom of using sudo either. Regards (4 Replies)
Discussion started by: earlysame55
4 Replies

6. UNIX for Advanced & Expert Users

useradd?

Hi Experts, when using useradd command, what are the necessary options/arguments to be included? Please advice. (4 Replies)
Discussion started by: etcpasswd
4 Replies

7. Shell Programming and Scripting

Help with useradd script

Ok Im trying too make this shell script create users from my text file, I also want to type in a password for the new users. So thay can make a uniq one themself after first logon. #!/bin/sh # Sebastian schmidt clear echo "*************************************************************"... (3 Replies)
Discussion started by: chipmunken
3 Replies

8. Solaris

useradd

if useradd command is deleted in solaris how do we add user (3 Replies)
Discussion started by: vivek_ng
3 Replies

9. Solaris

useradd problem

:wall:i want to create a user in solaris whose password expires after every 30 minutes and he has to change his password after evry thirty minutes.How can we do that?:confused: thanx and regards, shekhar (17 Replies)
Discussion started by: shekhar_4_u
17 Replies

10. Solaris

useradd

I want to creat a 27 logins in solaris.Can anyone tell me how to write a script for that so that i create at a time for all 27 people. Thanks to guide me. (6 Replies)
Discussion started by: kkalyan
6 Replies
dsenableroot(8) 					    BSD System Manager's Manual 					   dsenableroot(8)

NAME
dsenableroot -- enables or disables the root account. SYNOPSIS
dsenableroot [-d] [-u username] [-p password] [-r rootPassword] DESCRIPTION
dsenableroot sets the password for the root account if enabling the root user account. Otherwise, if disable [-d] is chosen, the root account passwords are removed and the root user is disabled. A list of flags and their descriptions: -u username Username of a user that has administrative privileges on this computer. -p password Password to use in conjunction with the specified username. If this is not specified, you will be prompted for entry. -r rootPassword Password to be used for the root account. If this is not specified for enabling, you will be prompted for entry. EXAMPLES
-dsenableroot Your username will be used and you will be queried for both your password and the new root password to be set to enable the root account. -dsenableroot -d Your username will be used and you will be queried for only your password to disable the root account. -dsenableroot -u username -p userpassword -r rootpassword The supplied arguments will be used to enable the root account. -dsenableroot -d -u username -p userpassword The supplied arguments will be used to disable the root account. Mac OS August 08 2003 Mac OS
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy