Operating System - HP-UX
1752756 Members
4930 Online
108789 Solutions
New Discussion юеВ

passwd passing from script

 
SOLVED
Go to solution
Raisaab
Advisor

passwd passing from script

Hi All,

Any idea on passing password of a user through script.

username=Vijay
if user is already created than ...

inside the script i am checking for the user,
if the user exists, than i want to pass the passwd to the user.

Any idea on how to pass the passwd to users in script. I have heard of except(don't want to use it) but was looking for some mechanism which can allow passing of password to passwd command through pipe or something like so in the script.

With best regards,
Vijay
11 REPLIES 11
Mel Burslan
Honored Contributor

Re: passwd passing from script

if this is required to change or assign passwords to users in scripts, your only option is expect, nothing else will work.

if this is for an automated ftp or something, together with being a horrendous security risk, you can use .netrc (see man pages for more info), but the best way is to use ssh/scp with trusted public/private key pairs between hosts.

________________________________
UNIX because I majored in cryptology...
RAC_1
Honored Contributor
Solution

Re: passwd passing from script

There are three ways to do it. (As far as I know.)

Check user and exists, you can doone of the following.

1. User /usr/sam/lbin/usermod.sam -p "pass_word" -F "user_name"

-p option requires a encrypted password. so you can do as follows. the pass needs to be of 8 chars+2salt chars.

/usr/sam/lbin/usermod.sam -p $(echo "test123te"|/usr/lbin/makekey) user_name

Password will be test1234

2. Use expect tool

3. Replace the user password feild with sed/perl/awk etc. In any case, backup up the passwd file first.
There is no substitute to HARDWORK
Raisaab
Advisor

Re: passwd passing from script

Hi RAC,
Yes this was the type of solution I was looking for ...
Thank you very much ... and you deserve a total 10 points for this ...
With warm regards,
Vijay
Muthukumar_5
Honored Contributor

Re: passwd passing from script

You can do checking as,

id ${user} 1>/dev/null 2>&1
if [[ ${?} -eq 0 ]]
then
scripting
fi

You can use expect scripting to send passwd / sudo for local users also.

hth.

Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: passwd passing from script

If you are having perl then,

http://www.modperl.com/perl_networking/sample/ch6.html

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: passwd passing from script

Piping scripting with telnet + passwd command:

(
sleep 1
echo "muthu" # Telnet Account name
sleep 1
echo "muthu" # Telnet Passwd
sleep 1
echo "passwd muthu" # Passwd execution
sleep 1
echo "muthu" # Old Password
sleep 1
echo "muthu12" # New password. Use two alphanumeric character
sleep 1
echo "muthu12" # Confirm Passwd.
sleep 1
echo "exit 1" # Log out
) | telnet

# hostname to localhost if you are trying for local machine

Change sleep time based on system response.

hth.
Easy to suggest when don't know about the problem!
Raisaab
Advisor

Re: passwd passing from script

Hi I have found solution to this with RAC'S Answer
Muthukumar_5
Honored Contributor

Re: passwd passing from script

I hope you are new comer to this forum. Just view the thread and assign points in the relative reply. If you are not getting the way to assign, refer FAQ section.

hth.
Easy to suggest when don't know about the problem!
Raisaab
Advisor

Re: passwd passing from script

Yes I am a new bee here. But I though I assigned point's.
Anyway's in future i will take care ...
sorry for the inconvinence ...