Skip to content
Menu

Turn Off Remote Login and Screen Sharing on a Mac

Turns off SSH, Screen Sharing and Remote Management (Apple Remote Desktop) on a Mac and checks each is off. High risk, so it is a dry run until you approve it.

Turn off Remote Login and Screen Sharing on a Mac is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Turn off Remote Login and Screen Sharing on a Mac. Tell other MSPs how it worked for you.

Write a Review

LanguageBash
Runs onmacOS 13+; runs as root
Needsbash 3.2, root, Full Disk Access for the agent to turn Remote Login off
Changes thingsChanges what it runs on

What It Does

This script changes nothing until you set DRY_RUN=false and APPROVE=disable-mac-remote-access. Before that it prints what it would turn off. It also refuses to make more than 25 changes in one run unless you raise MAX_CHANGES.

For each service that is on, and whose input is true, it turns the service off. Remote Login is turned off with systemsetup. Screen Sharing is disabled and stopped in launchd, so it stays off after a restart. Remote Management is deactivated and stopped with the Apple Remote Desktop kickstart tool. It then reads each service it changed and ends in ERROR if one is still on, for example when a configuration profile manages it. Nothing else is touched: no account, no firewall rule, no key.

Before a real change it copies launchd's override database (/var/db/com.apple.xpc.launchd/disabled.plist), if it exists, to /Library/Application Support/MSPOutpost/Backups/disable-mac-remote-access/.

Turning Remote Login off needs Full Disk Access for the program that runs the script, which is your RMM agent or MDM agent. When macOS refuses, the script ends in ERROR before it changes anything else. Screen Sharing and Remote Management do not need it. A run that came in over SSH never turns Remote Login off, because that would end the run itself. It warns, leaves it on, and ends SKIPPED if that was all there was to do. Screen Sharing and Remote Management can still be turned off on the same run.

Before You Run It

  • Run it once as a dry run and read the list of services it would turn off.
  • Make sure you have another way to reach the Mac, such as your RMM agent, before you turn off the service you use.
  • Grant Full Disk Access to your RMM agent with a PPPC profile from your MDM, or Remote Login cannot be turned off.
  • Run it from your RMM agent, not over SSH.
  • If a service comes back on, look for a configuration profile that manages it.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: High. It is a dry run unless you set both DRY_RUN=false and APPROVE=disable-mac-remote-access, and it stops before making more than 25 changes in one run unless you raise MAX_CHANGES. Run it once as a dry run and read the list first.
  • What it changes: Turns off Remote Login (SSH), Screen Sharing and Remote Management (ARD).
  • Restart: It never restarts the machine.
  • Typical run: Under 15 seconds.
  • Example answer: "Turned off Screen Sharing, Remote Management"
  • Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.

Inputs

Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.

  • DISABLE_REMOTE_LOGIN: Turn Remote Login (SSH) off when it is on. Default true.
  • DISABLE_SCREEN_SHARING: Turn Screen Sharing off when it is on. Default true.
  • DISABLE_REMOTE_MANAGEMENT: Turn Remote Management (ARD) off when it is on. Default true.

Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

disable-mac-remote-access.sh · 642 lines · 29.3 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.