MacOS – Can Gatekeeper be disabled via terminal in OS X 10.8 Mountain Lion

gatekeepermacosSecurityterminal

How can you disable Gatekeeper via Terminal Commands in OS X 10.8 Mountain Lion? I am looking to replicate the Security & Privacy preference pane selection to allow applications downloaded from Anywhere to run:

enter image description here

By having a terminal command, I can write a script to do this task remotely rather than manually going to each Mac and changing these settings with a mouse and several clicks.

Best Answer

The spctl tool should do the job.

sudo spctl --master-disable will turn off the Gatekeeper checks, and sudo spctl --master-enable will re-enable them (to the default setting of App Store and signed apps — it doesn't appear that setting it to App Store-only is possible).

Note that it will not throw any error if you run it without sudo permissions, but sudo is in fact required.