- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to change passwords in shellscript?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 05:57 PM
10-16-2001 05:57 PM
How to change passwords in shellscript?
How can i change password in shellscript.
I wrote following script, and execute it by root. But it doesn't work.
useradd -u 5001 -g 800 -m -k /etc/skel user01
passwd user01 newpasswd newpasswd
Regards,
KU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 06:25 PM
10-16-2001 06:25 PM
Re: How to change passwords in shellscript?
You may be able to use expect, but I'm not sure how it would work with passwd.
Scott.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 06:37 PM
10-16-2001 06:37 PM
Re: How to change passwords in shellscript?
cp /etc/passwd /etc/passwd.sed
sed -e "s/$zid:\*:/$zid:,..:/" < /etc/passwd.sed > /etc/passwd
Now what that does is matches the $zid:*: (where $zid is the user name - ours are z12345 for example) in the passwd file and replaces it with $zid:,..: The ,.. forces the user to change their passwd the the next time they login.
It takes the passwd.sed file as input and output the passwd file. It will only modify the line that matches the $zid:*: and nothing else.
This is the only thing I could come up with that would work. I researched passwd command and the useradd command to try to come up with something else and couldn't figure anything out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:04 PM
10-16-2001 07:04 PM
Re: How to change passwords in shellscript?
There is not solution in pure shell but if you know a little perl, it's very easy. The Unix::PasswdFile module which is available for www.perl.com/CPAN has everything you need.
The other method is just a few lines of C.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:12 PM
10-16-2001 07:12 PM
Re: How to change passwords in shellscript?
There is a way.
See the script by Robin
http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0xbdb6cf38d6bdd5118ff10090279cd0f9,00.html
Best of luck
Animesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:23 PM
10-16-2001 07:23 PM
Re: How to change passwords in shellscript?
But it is possible with a public software called "expect". YOu can download it from
http://hpux.asknet.de/hppd/hpux/Tcl/expect-5.31/
Once you get it loaded, you can use this simple script to change the password
#!/wherever/expect -f
set timeout 10
spawn passwd user
expect "*sword:"
send "some_password\r"
expect "*sword:"
send "some_password\r"
expect "$" #or whatever the prompt
send "exit\r"
You can automate any "interactive" program using expect. Check the dependencies before installing expect.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:24 PM
10-16-2001 07:24 PM
Re: How to change passwords in shellscript?
The attached perl script should help, you'll have to edit the path to where your perl is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:25 PM
10-16-2001 07:25 PM
Re: How to change passwords in shellscript?
The attached perl script should help, you'll have to edit the path to where your perl is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2002 01:25 PM
03-20-2002 01:25 PM
Re: How to change passwords in shellscript?
I am trying to do the same thing (find a batch way to change multiple unix passwords). I created a Perl script and used Unix::PasswdFile module to change multiple passwords in /etc/passwd test file and it seems to work. But I was wondering if you knew how Perl was actually changing the password behind the scenes. I tried looking in the Perl and C source code for the module and the 5.6.1 version, but I can't seem to find what unix or C commands Perl is ultimately using to replicate the "passwd" command (we would like to find out so we don't have to use Perl and can call the unix or C functions directly). Do you know how Perl is doing this or where in the Perl source code I could find out?
Also you mention on this and another post about coding a solution in C. Do you have any examples or know what C functions to use?
Will the Perl or C solution work if I am using a trusted environment or shadow file (since Perl looks like it is updating /etc/passwd directly)? If not how can I get the shadow file updated? My guess is that there has to be some way since the "passwd" interactive command itself has a way to update the shadow file. Any help is appreciated.
Thanks -
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2002 01:32 PM
03-20-2002 01:32 PM
Re: How to change passwords in shellscript?
The non-trusted library functions you need to examine are getpwent() and putpwent(). Man getpwent and putpwent for details. If you use NIS there is also a yppasswd() function.
The trusted equivalents are getprpwent() and putprpwent(). Man those entries as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2002 02:38 PM
03-20-2002 02:38 PM
Re: How to change passwords in shellscript?
Thanks for the quick response. I man'd the functions and they look like what I would need to write a C pgm. I will continue to look at them.
I grepped for them in the Perl source code to see if that's what Perl is using and I did find getpwent() and setpwent(), but no putpwent(). So I don't yet know how Perl is ultimately updating the file.
Would you say it is worth the effort to write a C pgm or just go with the Perl implementation for not-trusted env (it doesn't look like the Perl supports trusted so I would have to go with C pgm if I needed that)?
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2002 03:02 PM
03-20-2002 03:02 PM
Re: How to change passwords in shellscript?
If it were me, I would do the C version. The other piece of the puzzle is how to do the hashed passwd. Passwords are actually hashed rather than encrypted so that the process is not reversible.
To create a passwd:
Choose a random 2 character string from the set
[./A-Za-z0-9] this becomes the 'salt'. You then call the crypt() function like this:
char *hash,salt[3] = {"x9"},plaintext[16] = {"top_secret"};
hash = passwd(plaintext,salt);
hash points to a composite made up of the salt + the hashed key.
Man 3 crypt for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2002 01:29 PM
03-26-2002 01:29 PM
Re: How to change passwords in shellscript?
I'm not sure if you are still following thread
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1b970cb17a32d5118fef0090279cd0f9,00.html
but on that thread you offered the author "C" code that you developed as the repacement code for yppasswd command. Could you send me a copy? As you suggested I created a C pgm with calls to non-trusted functions and it is working fine, but we are running NIS so I am afraid that I cannot just update the local /etc/passwd file, but I need an equivalent to yppasswd instead.
Thanks again.