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
RHN_REGISTER(8) 						   Red Hat, Inc.						   RHN_REGISTER(8)

NAME
rhn_register - Connect to RHN Satellite or Red Hat Network Classic. SYNOPSIS
rhn_register [options] DESCRIPTION
rhn_register is a client program that registers your system with Red Hat Network Classic (or a RHN Satellite). After registering, your sys- tem can receive software updates, install new software, and remotely manage your system. It can run both in graphical and text modes. OPTIONS
-v, --verbose Increase the debugging output. --proxy=PROXY Specify an http proxy to use. --proxyUser=PROXYUSER Specify a username to use for an authenticated proxy. This option must be used in conjunction with proxyPassword. --proxyPassword=PROXYPASSWORD Specify a password to use for an authenticated proxy. This option must be used in conjunction with proxyUser. --nox Run in text mode. --version Show the program's version number and exit. -h, --help Show a help message and exit. FILES
/etc/sysconfig/rhn/systemid The digital server ID for this machine if the system has been registered onto RHN Satellite or Red Hat Network Classic. This file does not exist otherwise. /etc/sysconfig/rhn/up2date The common configuration file used by RHN client programs. SEE ALSO
rhn_check(8), rhnreg_ks(8), rhnsd(8), rhn-profile-sync(8), rhnplugin(8), up2date(5). AUTHORS
See the AUTHORS file included with this software. This manual page was written by James Bowes <jbowes@redhat.com> BUGS
Report bugs to <http://bugzilla.redhat.com>. COPYRIGHT
Copyright (C) 1999-2011 Red Hat, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. Linux 2011 February 4 RHN_REGISTER(8)
All times are GMT -4. The time now is 06:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy