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
partimaged-passwd(8)				       Partition Image Server Configuration				      partimaged-passwd(8)

NAME
partimaged-passwd - Manage partimaged user accounts SYNTAX
partimaged-passwd [-Dhl] username password partimaged-passwd [-Dhl] username DESCRIPTION
partimaged can either authenticate against local user accounts (This needs access to /etc/shadow. As this is a potential security risk this method is not recommended) or its own password database in /etc/partimaged/passwd.db. To simplify the management of the partimaged user database this tool was written. It allows to easily add and remove users or list the users in the database. All users in this database are allowed to access the partimaged server. OPTIONS
-D username Delete the specified user from the password file. -l List users in password file and exit. -h Output help information and exit. FILES
/etc/partimaged/passwd.db AUTHORS
Michael Biebl <biebl@debian.org> SEE ALSO
partimaged(8), partimagedusers(5), partimage(1) Michael Biebl <;biebl@teco.edu> 0.1 partimaged-passwd(8)
All times are GMT -4. The time now is 08:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy