Help OS X script : password input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help OS X script : password input
# 1  
Old 01-02-2017
Help OS X script : password input

Hello

Sorry for the question..

i would like to make a script for OS X that allow me to change the password for a user account.
i have to use this script on several iMac with the same user/password.
i want to store the passwords inside the script, no security problems involved.

the command is :
Code:
dscl . passwd Users/account_name

When i run the command, the terminal asks me to enter :
Code:
- New Password :
- Permission denied. Please enter user's old password:

example : new password : test
old password : test2

Code:
dscl . passwd Users/account_name
- auto enter test
- auto enter test2

thank you
and sorry for my english Smilie

Last edited by Scrutinizer; 01-02-2017 at 12:13 PM.. Reason: code tags
# 2  
Old 01-02-2017
The script is okay. I suppose. One way to stop the password request for the users old password is to use sudo and /etc/sudoers file. You can also enable or disable the root user from the command line, which is not the preferred method.

Documentation here:
How to enable the root user on your Mac - Apple Support <- enabling/disabling root
sudo OSX Man Page | SS64.com <- sudo starting point.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 01-03-2017
You don't tell us which version of OSX you are using so be aware of this, the csrutil command:-

Root access in OSX 10.12.2.

This originated in El-Capitan, (OSX 10.11.x).

Thanks to '[MA]Flying_Meat' for pointing it out to me.
This User Gave Thanks to wisecracker For This Post:
# 4  
Old 01-03-2017
thank you for the help

Unfortunately i cannot enable the Root Account on all the iMac.

i try to give you more details :

i have 20 iMac with 2 User Account (both Administrators).
i have to change the password for both the accounts on all the iMac

All the iMac run the latest OS X version , 10.12.x?

i would like to make a script that i can send to every iMac using Apple remote tool, and that will make me save a lot of time.

I'm a beginner user of the OS X terminal...

this is an example of what i want to do:
- 20 iMac
- users account name : Administrator & SSH
- old psw for Administrator & SSH : "AAA"
- new psw to enter for both the accounts : "BBB"

#script to change password
Code:
dscl . passwd Users/Administrator 
<<a command that can enter automatically the new password stored in the script>>
<<a command that can enter automatically the old password stored in the script>>

dscl . passwd Users/SSH
<<a command that can enter automatically the new password stored in the script>>
<<a command that can enter automatically the old password stored in the script>>

thank you for any help


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-03-2017 at 07:04 AM.. Reason: Added CODE tags.
# 5  
Old 01-03-2017
This sort of operation is intentionally blocked in OSX and most UNIX in general. UNIX logins and login-related tools (and even remote tools, like ssh) accept passwords typed by a human being in realtime - not from files, scripts, variables, commandline options, CGI, or anything else. Nothing but an interactive terminal will do.

This is to prevent people from writing scripts which automatically escalate themselves into other people's privileges or especially into root privileges. Anyone could read such a script and discover the secret to subverting your systems. This also places another barrier in the way of an attacker trying to do the same sort of thing you are.

Not even root can really avoid this, it just cuts out the middleman since it doesn't actually need to login to anything to update anyone's password entries.

You may need to rethink what you're trying to do. Some sort of privileged login should be involved, either via sudo or root itself, not brute-forcing passwords into inputs meant to be typed into. (Which you could, with the third-party expect brute-forcing tool, but that shouldn't be done on a regular basis.)

Last edited by Corona688; 01-03-2017 at 05:14 PM..
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 01-04-2017
Quote:
Originally Posted by Corona688
This sort of operation is intentionally blocked in OSX and most UNIX in general. UNIX logins and login-related tools (and even remote tools, like ssh) accept passwords typed by a human being in realtime - not from files, scripts, variables, commandline options, CGI, or anything else. Nothing but an interactive terminal will do.

This is to prevent people from writing scripts which automatically escalate themselves into other people's privileges or especially into root privileges. Anyone could read such a script and discover the secret to subverting your systems. This also places another barrier in the way of an attacker trying to do the same sort of thing you are.

Not even root can really avoid this, it just cuts out the middleman since it doesn't actually need to login to anything to update anyone's password entries.

You may need to rethink what you're trying to do. Some sort of privileged login should be involved, either via sudo or root itself, not brute-forcing passwords into inputs meant to be typed into. (Which you could, with the third-party expect brute-forcing tool, but that shouldn't be done on a regular basis.)

thank you for the accurate description
so basically there is not any way to avoid this problem ?
i would like to make an authomatism that allow me to make this massive task in a single click...
In your opinion , there is a way using any other workaround ?
like root account or anything else.

i've tried to make some research on the web, i've found a ssh key...
it should be a way to store a specific key (like a password) and to evoke it when needed.
Could it be used for my task ?
and if yes, what would be the code to store and evoke a key ?

i really appreciate all the help, thank you.
# 7  
Old 01-04-2017
Did you read my post #3 or am I wasting my time?

Research these two items first:-

Gatekeeper (macOS - Wikipedia)
System Integrity Protection - Wikipedia

Apple is a tough nut to crack externally even with _root_ access.

Even when you have terminal root access you are NOT able to write to many root owned areas.

Again research those two URLs above.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

2. Shell Programming and Scripting

Shell script password input

hy, I wrote a simple shell script to monitor (with Nagios) a SNX VPN function. Here the Code snippet: testing=`ssh user@IP-address 'ls /etc/sysconfig/network-scripts/ifcfg-eth0'` #echo $testing if ; then echo "VPN is working" exit 0 else snx -s server -u user ... (2 Replies)
Discussion started by: tomies
2 Replies

3. Shell Programming and Scripting

Script to input encrpyted password into htdigest (Apache)

Hey guys, This is my situation. I'm using the script to add a user account, however, i want the same details copied into the htdigest password list. the format is username:virtualservername:hashed/encrypted password. This is the command : sudo htdigest /etc/apache2/passwords... (0 Replies)
Discussion started by: xxxx
0 Replies

4. Shell Programming and Scripting

To make password/input text invisible?

All, My script is ----------- #cat pass.sh password=123 echo -n "Enter pass:" read pass if ; then echo "Correct password" else echo "Wrong password" fi When i run this script, text(password) which i'm entering is visible in screen... (4 Replies)
Discussion started by: thomasraj87
4 Replies

5. Shell Programming and Scripting

password file as std input to script

I'm a fairly new AIX admin (disclaimer). We have SQL scripts written by end users that use a userid and passwd to connect to our DB2 database. Is it possible to create an "input file" that contains the db2 connect parameters and yet secure the file from the SQL creator? i.e., they can "use"... (2 Replies)
Discussion started by: mpheine
2 Replies

6. Shell Programming and Scripting

input username and password interactively

Hi guys, I am using Solaris 10 and we install IBM OnDemand server there. there's a command called arsload that we use to load document and query document too. I need to write a script to query document but when querying document, this command prompt for username then password. My question is... (3 Replies)
Discussion started by: markthien
3 Replies

7. Shell Programming and Scripting

Input Password

I am writing a script that can automatically login to Storage CAM console. i use this command, ./sscs login -u user -h localhost. at that time it will prompt for password, is it possible for store password in a file and supply it when it waits for password. Thanks in advance. Regards SK (1 Reply)
Discussion started by: cutechaps
1 Replies

8. UNIX for Dummies Questions & Answers

To append \ in the input password

Hi I have the following issue i am going to ask from the user the password The password can have $ anywhere that is first last or in between but i have to append \ before the $ sign in the password can anyone please help For example o/p in the console will be like the... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

9. UNIX for Advanced & Expert Users

password required when using input redirection

Hello, I need to change user and run some commands by using a script. lets say, I'm using su - someuser << start password required -----> how can I enter the password here command 1 command 2 command 3 command 4 start While trying to run this I got the following message: "standard... (2 Replies)
Discussion started by: Alalush
2 Replies

10. Shell Programming and Scripting

Input Password

I have a script which connects to database. I want user to input user name and password but dont want the password characters to be displayed on screen. How can i accept input from user in encrypted form. (2 Replies)
Discussion started by: baglasumit21
2 Replies
Login or Register to Ask a Question