Command Line - Enable Remote Login and Remote Management

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?


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

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.