Is there any way to reset Useraccount password in mac using shell script. I know we can take user input using dialogue box, but how can we send it to terminal app
-
Even my self looking for same solution – MacDeveloper Aug 06 '15 at 05:54
1 Answers
I can get you most of the way to the answer you need, but you'll have to do the actual implementation yourself.
1)
The first thing you need to do is to use the dscl
(Directory Service Command Line) tool.
Here's how to create a new user and here is how to change the password, which would be a command that looks like:
sudo dscl . passwd /Users/administrator thePassword
2)
Now that you know how to change the password using the command line, you need to embed that functionality into an AppleScript.
Here is a related Q&A on a different forum that shows dscl
embedded in an Applescript.
If you look in that above thread, you'll see you will need to prefix your dscl
commands with sudo
though. That means the password has to be entered in each time the Applescript is run.
If entering in the admin password each time doesn't work for you, you'll need to do some extra work, or run the script from a LanchAgent.
The above is a lot of information that you have to go through, and as you can see what you are asking for is not the most trivial task (and it should not be, since you really don't want passwords to be easily changeable via malicious scripts or bots or trojans). I hope I did point you in the right direction to get to a solution, though!

- 1
- 1

- 88,797
- 17
- 166
- 215
-
I am able to acomplish the task. How ca i get error thrown if i pass a password which does not reach password policy requirement – MacDeveloper Aug 06 '15 at 09:06
-
`dscl` throws error codes when problems happen and you may be able to handle those. – Michael Dautermann Aug 06 '15 at 09:15
-
How can i get that error codes of dscl. can you please tell me where can i look for it – MacDeveloper Aug 06 '15 at 09:20