Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Change password via shell

Change password via shell
Thread Tools
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
May 31, 2003, 04:45 PM
 
I need to batch change passwords.

How can it be done using shell.

Want to create a perl script that allows users to enter their old password... and a new one.
I always use protection when fscking my Mac... Do you?
     
Dedicated MacNNer
Join Date: May 2002
Status: Offline
Reply With Quote
May 31, 2003, 06:58 PM
 
Try
/user/bin/passwd
That is the standard unix way of doing
it
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
May 31, 2003, 07:33 PM
 
I would advise against using that though, because it will not update your keychain password.. only your login, so you will run into problems, and many, many annoying password request windows

use the preference pane

and ya, passwd does exactly what your perl script would do
     
Mac Enthusiast
Join Date: Nov 2001
Location: Arizona
Status: Offline
Reply With Quote
May 31, 2003, 07:38 PM
 
I strongly suspect (I haven't tried this) that using the Unix passwd command won't update the password on the user's Keychain at the same time, however.

This will mean the Keychain will still have the old password and won't open automatically at login (user will have to open it with old password the first time it gets used per login until the user changes it or creates a new keychain.)

I don't know if the Unix command line can access the keychain. I doubt it.

(Edit: 11011001 types faster than I do.)

BTW, if you are changing all these passwords yourself, a sudo -s (to root) before running passwd will let you change the password without entering the old one (definitely won't update the keychain password.)
     
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jun 1, 2003, 10:39 AM
 
Originally posted by 11011001:
I would advise against using that though, because it will not update your keychain password.. only your login, so you will run into problems, and many, many annoying password request windows

use the preference pane

and ya, passwd does exactly what your perl script would do
Users only connect via AppleShare, and shell.

So they never see the keychain stuff anyway.

It's for file storage.
I always use protection when fscking my Mac... Do you?
     
Clinically Insane
Join Date: Apr 2000
Status: Offline
Reply With Quote
Jun 1, 2003, 10:59 AM
 
passwd user

Will work fine, but yeah, Keychain won't be updated. If that's a non-issue, passwd will work fine.
     
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jun 1, 2003, 11:02 AM
 
Originally posted by Cipher13:
passwd user

Will work fine, but yeah, Keychain won't be updated. If that's a non-issue, passwd will work fine.
Thanks Cipher!

I personally don't use Keychain period. Especially on this box.

It's a file server. The only passwords I'm concerned with are the main password (shell, ftp, AppleShare) and Samba.
I always use protection when fscking my Mac... Do you?
     
Dedicated MacNNer
Join Date: Dec 2002
Location: someplace
Status: Offline
Reply With Quote
Jun 1, 2003, 12:26 PM
 
sudo niutil -createprop . /users/$theUsername passwd "`openssl passwd $thePassword`"
     
Dedicated MacNNer
Join Date: May 2002
Status: Offline
Reply With Quote
Jun 1, 2003, 05:32 PM
 
Hey gatorparrots

Will niutil also change the the keychain
password
     
Mac Elite
Join Date: Sep 2001
Location: Chile
Status: Offline
Reply With Quote
Jun 1, 2003, 10:17 PM
 
Originally posted by gatorparrots:
sudo niutil -createprop . /users/$theUsername passwd "`openssl passwd $thePassword`"
can you explain that ?
right from ... . / users ... onwards

thx
:: frankenstein / lcd-less TiBook / 1GHz / radeon 9000 64MB / 1GB RAM / w/ext. 250GB fw drive / noname usb bluetooth dongle / d-link usb 2.0 pcmcia card / X.5.8
:: unibody macbook pro / 2.4 Ghz C2D / 6GB RAM / dell 2407wfp - X.6.3
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jun 1, 2003, 11:20 PM
 
Originally posted by Sarc:
can you explain that ?
right from ... . / users ... onwards

thx
From the man page for niutil...

Code:
niutil lets you to do arbitrary reads and writes on the given NetInfo domain. In order to perform writes, niutil must be run as root on the NetInfo master for the database, unless the -p, -P, or -u options are given. The directory specified by path is separated by "/"s, similar to the filesystem. The property names may be given in the path using a "=", but will default to the property name "name". For example, the following refers to a user with the user ID 3. "/name=users/uid=3" The following shorter form would also be sufficient: "/users/uid=3" You may specify a numeric ID for the directory instead of the string path. ... -createprop domain path key [ val... ] Create a new property in the directory path. key refers to the name of the property; 0 or more prop- erty values may be specified. If the named prop- erty already exists, it's overwritten.
     
Dedicated MacNNer
Join Date: Dec 2002
Location: someplace
Status: Offline
Reply With Quote
Jun 2, 2003, 10:38 AM
 
Originally posted by Sarc:
can you explain that ?
right from ... . / users ... onwards

thx
sudo niutil -createprop . /users/$theUsername passwd "`openssl passwd $thePassword`"
This command arbitrarily assigns a user's password. We're saying, "with root privileges, use niutil to create a property in the default domain at this path: /users/theUsername under the property key passwd, using the results of openssl passwd thePassword" for the value to be inserted...

Basic niutil usage:
niutil -createprop [opts] <domain> <path> <propkey> [<val>...]
     
Senior User
Join Date: Jul 2000
Status: Offline
Reply With Quote
Jun 2, 2003, 12:58 PM
 
Originally posted by theory:
Will niutil also change the the keychain password
No, no it will not. What gatorparrots posted is exactly the same thing as using the 'passwd' command.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 2, 2003, 04:01 PM
 
Hmm, interesting. Perhaps someone should add support to change the keychain password to passwd, if anyone can be bothered. The source for Security and passwd are both there
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2