LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 06-03-2008, 09:43 AM   #1
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Rep: Reputation: 34
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,

Last edited by p_s_shah; 06-03-2008 at 07:48 PM. Reason: Info updated
 
Old 06-04-2008, 12:19 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
Old 06-04-2008, 07:08 PM   #3
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Original Poster
Rep: Reputation: 34
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.
 
Old 06-05-2008, 02:12 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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
 
Old 06-09-2008, 05:19 AM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,267

Rep: Reputation: 99
Unhappy

Quote:
Originally Posted by jlliagre View Post
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.
 
Old 06-09-2008, 07:59 AM   #6
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 228
Blog Entries: 1

Original Poster
Rep: Reputation: 34
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.

Last edited by p_s_shah; 06-09-2008 at 08:07 AM. Reason: Updated info
 
  


Reply

Tags
scripting, shell, solaris


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
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
How to provide password for pppd at runtime deepalalla Linux - Networking 0 12-29-2004 04:33 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
password prompt ? wr3ck3d Linux - General 5 03-20-2003 08:54 PM
remote command over ssh, password prompt linowes Linux - General 2 10-27-2002 08:22 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration