21

For my job, before I deploy a new Mac laptop, I need to enable these two settings:

  1. System Preferences - Sharing - Remote Login. Once enabled I also need to add the admin account that previously I have created by selecting the little + symbol under Only these users:

  2. System Preferences - Sharing - Remote Management - (the little pop up windows comes out) and I select all the features

How do I achieve the above two process via command line?

2
  • Which deployment solution do you use? DeployStudio, Casper or scripts?
    – klanomath
    Commented Apr 5, 2017 at 18:50
  • neither. i just ssh into the machine to do stuff. But I need to enable the two steps above before I do that for different reasons.
    – Fabio
    Commented Apr 5, 2017 at 19:32

2 Answers 2

26

Modifying remote login and remote management settings is done with two different commands - both executed as root:

  • systemsetup
  • kickstart

To enable remote login for members of the admin group enter:

sudo systemsetup -setremotelogin on

To restrict access use dseditgroup. First check if it exists and add it if necessary:

dseditgroup com.apple.access_ssh
dseditgroup -o create -q com.apple.access_ssh

and add a user group:

sudo dseditgroup -o edit -a admin -t group com.apple.access_ssh

To enable remote management for admin users enter:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent -menu

To check other options enter:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart --help
1
  • 3
    since 10.14 you cannot enable via ssh. If Yo connect via ssh, You got: Warning: macos 10.14 and later only allows control if Screen Sharing is enabled through System Preferences.
    – ingconti
    Commented Mar 25, 2020 at 7:00
17

Enabling SSH:

$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Disabling SSH:

$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist

(the alternative, systemsetup is deprecated)

This command still works, but it is deprecated. Please use launchctl(8) instead.
3
  • 1
    Very helpful. I had a script, running as root, that used the systemsetup command. However, in Catalina, it was not working, as it needed Full Disk Access (SystemPolicyAllFiles) but did not have a way to prompt the user for it. Using the launchctl command worked perfectly. Commented Jun 18, 2020 at 21:07
  • exactly @TimDearborn - also that "Full Disk Access" needed for on off that function, I consider as flaw
    – Bruno
    Commented Apr 28, 2022 at 20:36
  • systemsetup is not deprecated anymore as far as I can tell (I cannot find dep in the man page anywhere) and don't receive any message like that when running it. Also, don't see a prompt for Full Disk Access being needed (this is on Big Sur and Monterey at least). Also, launchctl load is considered legacy as of 'Yosemite'. Instead, should be using sudo launchctl bootstrap system ....
    – thaimin
    Commented Aug 2, 2022 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .