LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   How to provide password from command prompt ? (https://www.linuxquestions.org/questions/solaris-opensolaris-20/how-to-provide-password-from-command-prompt-646675/)

p_s_shah 06-03-2008 09:43 AM

How to provide password from command prompt ?
 
Hello all,

I want to know solaris equivalent for providing password on command only without prompting for it.

In Redhat Linux,
Code:

echo $PASS | passwd $USER --stdin
works as a privileged user. This will change $USER's password to $PASS without prompting.

As per http://forum.java.sun.com/thread.jspa?threadID=5296716, There is no way to do the same on Solaris.

Thanks in advance,

jlliagre 06-04-2008 12:19 PM

Yes, the usual way to do it is by using an expect script. You'll have to install expect as it isn't part of Solaris though.

Alternatively, now that Solaris in open sourced, nothing forbids you to build your custom patched version of passwd http://src.opensolaris.org/source/xr...asswd/passwd.c and add the feature by calling a custom getpassphrase call.

p_s_shah 06-04-2008 07:08 PM

Thanks for the update.

I am to learn much before updating current passwd command :) so, definately not a good solution for right now.

Right now, I am already using expect script for achieving the same. But it is much slower & there are some problem with time synchronization also.

As an alternative, I found following perl script.
Code:

#!/usr/bin/perl
use Unix::PasswdFile;

$pw = new Unix::PasswdFile "/etc/passwd";
$pw->passwd("monk", $pw->encpass("My-New-Password"));
$pw->commit();
undef $pw;

Thanks again for the info.

jlliagre 06-05-2008 02:12 AM

That perl script won't work. The module doesn't handle /etc/shadow.

Perhaps the following one will do better. Anyway, directly accessing the shadow file is a bad practice.

http://search.cpan.org/~strzelec/Pas...Passwd/Unix.pm

vikas027 06-09-2008 05:19 AM

Quote:

Originally Posted by jlliagre (Post 3175237)
That perl script won't work. The module doesn't handle /etc/shadow.

Perhaps the following one will do better. Anyway, directly accessing the shadow file is a bad practice.

http://search.cpan.org/~strzelec/Pas...Passwd/Unix.pm

Thanks jlliagre, But I am nuts about perl. Can you please help me to call this script in a shell script.

p_s_shah 06-09-2008 07:59 AM

jlliagre,
Thanks for your reply.
I tried that one on linux machine and it worked. I am in process of installing solaris 10 in VMware and check the same.

Also, I agreed with your comment for working with shadow file, But I want to sync passwords between multiple servers using script only. In my environment it is not possible to implement NIS/LDAP.

I am replying to vikas with example script. Please update if anything is wrong.

vikas027,

Sample Shell Script:
Code:

#!/bin/bash
echo "Enter Username:"
read USER
echo "Enter New Password:"
read NEWPASS

/path/to/perl changepasswd.pl $USER $NEWPASS

Sample Perl Script:
Code:

#!/usr/bin/perl -w

use Passwd::Unix;
my $pu = Passwd::Unix->new();
$pu->passwd($ARGV[0], $pu->encpass($ARGV[1]));

Please install Passwd::Unix perl module first.
You can enhance it with no. of users ( using for loop ) and error checking.
Please try it at your end and update.


All times are GMT -5. The time now is 06:06 PM.