Skip to content

Instantly share code, notes, and snippets.

@justinpawela
Created October 9, 2016 04:10
Show Gist options
  • Save justinpawela/8a924f36f86bac2b563bf6832eefff25 to your computer and use it in GitHub Desktop.
Save justinpawela/8a924f36f86bac2b563bf6832eefff25 to your computer and use it in GitHub Desktop.
Disable macOS Guest user account script
#!/usr/bin/osascript
-- License: https://justinpawela.github.io/default-gist-license/
(*
1) Disables signing in as Guest from the login screen.
2) Disables Guest access to file shares over AFP.
3) Disables Guest access to file shares over SMB.
Commands are chained together so that the user only needs to authorize once.
*)
set shellCommands to ¬
"sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow GuestEnabled -bool NO; " & ¬
"sudo /usr/bin/defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server AllowGuestAccess -bool NO; " & ¬
"sudo /usr/bin/defaults write /Library/Preferences/com.apple.AppleFileServer guestAccess -bool NO"
try
-- Run the shell commands, after requesting user authorization.
do shell script shellCommands ¬
with prompt "Attempting to disable the Guest user account." ¬
with administrator privileges
on error number -128
-- User cancelled. No further action required.
end try
@justinpawela
Copy link
Author

justinpawela commented Oct 9, 2016

Disable Guest Account

This script will disable the macOS "Guest" user account, including login and file sharing privileges.

The Users & Groups System Preferences pane is buggy in macOS 10.10 and 10.11 (and probably other versions). It does not accurately report whether the Guest account is enabled in part or full. Instead of clicking and guessing, it's easier to just run this script and be done with it.

This script requires Administrator privileges to run.

Installation

This script can be installed and run in a variety of ways:

From the Script Menu (Recommended)

Enable the Script menu from the Script Editor app, found in /Applications/Utilities. In the General tab of Script Editor's preferences, turn on the Show Script menu in menu bar option. You'll probably want to disable Show Computer scripts to reduce clutter in the menu.

To install, save a copy of the script in one of the following folders:

Who has access? Installation folder
Just the current user (default) ~/Library/Scripts
All users of this Mac /Library/Scripts

You can access either folder by selecting Go to Folder ... from the Finder's Go menu. Just type in directory as shown in the table above (don't forget the ~ character when installing for the current user).

If you install for all users, make sure to enable the Script menu's Show Computer scripts option.

As an Executable (Advanced)

This script can be run as an executable in Terminal after appropriate permissions have been set. First, save a copy of the script to /usr/local/bin/. Then, mark the script executable by running chmod 555 /usr/local/bin/DisableGuestAccount.applescript in a Terminal. Using sudo will be required.

Remove Guest from Boot Menu

Run sudo fdesetup remove -user Guest then restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment