terminal command with password

Joined
Oct 9, 2009
Messages
2
Reaction score
0
Points
1
Hi, I'm new the development in Mac. I need to call a command line as following using C++ with system() function:
"sudo rm /private/var/db/.AccessibilityAPIEnabled"
I'm expecting this line being executed in background, however in my C++ console application, it would prompt for a password, I need to eliminate this step. Is there something like "sudo rm /private/var/db/.AccessibilityAPIEnabled -p MyPassword" in Mac?
Thanks a lot!
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,734
Reaction score
2,059
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
To run a SUDO command without using your password, you can configure SUDO to allow a particular (or all) commands to be run without the password.

So do
sudo visudo
which will take you to a file that controls how SUDO functions. Towards the bottom you'll see something like #
%wheel ALL=(ALL) NOPASSWD: ALL
so you could add something like the following
<username> ALL=(ALL) NOPASSWD: rm
and it will allow you to do the rm as SUDO without requiring a password.

Note that this means ANY rm you do will no longer require a password, so it might be dangerous..

Regards
 
OP
V
Joined
Oct 9, 2009
Messages
2
Reaction score
0
Points
1
thanks Raz0rEdge, i tried it, it works. however this might not be a perfect solution to my problem. i'm using a C++ app to call a command as such: "sudo rm /private/var/db/.AccessibilityAPIEnabled". i'm looking for a way to in-build the admin password into the command. i agree with you that adding "<username> ALL=(ALL) NOPASSWD: rm" would be dangerous, therefore i think this way is not a good approach to my problem. is there a way that i can skip the password prompt only in my app?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top