LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2005, 03:48 AM   #1
krishvij
Member
 
Registered: Feb 2005
Location: India
Distribution: RHEL 3
Posts: 108

Rep: Reputation: 15
Setting password for users in a shell script??


Hi,

I am currently writing a shell script that asks for the starting and ending sequence of users. Based on that, my shell script is able to create the users. This part is working perfectly well. let me put down the code of the script for you:-

echo "Please enter starting student number"
read sno
echo "Please enter ending student number"
read eno
while [ $sno -le $eno ]
do
tmpusr=`echo j2ee$sno`
useradd $tmpusr
sno=`expr $sno + 1`
done


I want to modify this script in such a way that the user's password should be set to elmaqedu. I tried to put the code passwd $tmpusr elmaqedu but it did not work. could somebody help me with this small piece of code?
 
Old 03-09-2005, 10:45 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
You could do this via the -p option in useradd. You'll have to find out what the crypt'd password is in order to use it, but you can do it that was as well.

man useradd
 
Old 03-09-2005, 11:21 PM   #3
krishvij
Member
 
Registered: Feb 2005
Location: India
Distribution: RHEL 3
Posts: 108

Original Poster
Rep: Reputation: 15
Hi,

I tried the useradd with the -p option. It was putting it in clear text in the /etc/shadow file. then i went thru the man pages. it told me that the -p option requires the password generated by crypt. so, i tried the command grub-md5-crypt and gave my password. It gave me an encrypted form of the password. When i tried to copy and paste it into my code, it further got encrypted into something else. probably it is not usng md5 but something else. Please do let me know.
 
Old 03-10-2005, 10:17 AM   #4
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Well, I already said that it required it to be cyprted, although you did read the man page, so that's a plus! :-)

Here's a sneaky tricky way to do it.

At the command prompt, type passwd Enter the password you want the other users to have. Look in /etc/shadow at what the newly crypted password is, copy the entire string ( of the password, not the entire /etc/shadow string for the user ), then type passwd again, change the password back to your old password, and you now have the crypted string in which to put with the -p option.

Ta-Da

There may be some utility out there that gives you an md5 string/crypted/thing-a-ma-jig, but it's just as easy to do it the way I just suggested.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding new users via Shell script coolfrog Linux - General 10 12-05-2010 11:47 AM
Shell script to change password kamal_aitin Linux - General 6 07-25-2007 01:09 AM
Shell Script For Password cpope67 Programming 4 01-10-2005 03:16 AM
Password Shell Script Solaris 9 cpope67 Solaris / OpenSolaris 1 12-30-2004 04:15 PM
how to assign password for a user in shell script mtest Programming 10 10-29-2003 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration