Skip to main content

Disable guest file sharing over AFP

Apply Now
Works with any MacWorks with any Mac running macOS/OS X on Intel or Apple Silicon.
  • macOS onlyThis script improves your privacy on macOS
  • Single actionThis page belongs to a script, containing basic changes to achieve a task.
  • Impact: Medium

    System Functionality / Data Loss Risk: Moderate

    This action improves privacy with minimal impact when you run the recommended script.

    This action improves privacy with some impact when you run the recommended script.
  • Bash (Shell script)These changes use macOS system commands to update your settings.
  • Administrative (sudo) access requiredThis script requires privilege access to do the system changes
  • Fully reversible

    You can fully restore this action (revert back to the original behavior) using this website.

    The restore/revert methods provided here can help you fix issues.

Overview

This script prevents anonymous users from accessing shared files through the Apple Filing Protocol (AFP).

AFP (Apple Filing Protocol) is a file-sharing protocol designed for Macs to facilitate network file sharing 1.

By default, macOS enables guest access to sharing services 2 3. It allows you to share files and folders with others on your network 4. This configuration allows anyone to access specific shared folders without requiring permission 5 6.

This script improves your privacy by preventing unauthorized users from accessing your shared files through AFP sharing. It also protects your Mac from potential attacks where malicious users can store data in your system 5 or gain increased system access through guest sharing vulnerabilities 7.

Guest access introduces multiple security risks:

  • Unauthorized users may access shared files 7
  • Attackers may fill your hard drive by writing excessive data to guest-accessible folders, potentially causing system crashes 5
  • The system may be vulnerable to reconnaissance and privilege escalation attacks 7

This script exclusively affects AFP file sharing 7 and does not impact:

  • File sharing through other protocols 1 8
  • Local guest user account functionality 9
  • The Find My app's ability to locate your Mac 9
  • FileVault encryption 9

This security measure is recommended by:

  • The U.S. National Institute of Standards and Technology (NIST) 8
  • The Center for Internet Security (CIS), that provides best practices for securing IT systems 7

After running this script, configure access via System Settings to share files with specific users.

Caution

After running this script, users on your network will require explicit permission to access files shared from your Mac.

Technical Details

The script:

  • Disables guest access in AFP server preferences: /Library/Preferences/com.apple.AppleFileServer!guestAccess 5 6 7 8 10.
  • Disables AFP guest access using the sysadminctl utility with the -afpGuestAccess off option 11 sysadminctl is a tool used to administer system user accounts 11.
  • Restarts the file sharing service (AppleFileServer) to apply changes 5 10
Use with Caution

This script is only recommended if you understand its implications.

Some non-critical or features may no longer function correctly after running this script.

This script can be fully reversed to restore changes if something goes wrong.

Sources
PrivacyLearn.com maintains strict sourcing standards for accuracy, integrity and up-to-date content. Our content relies on authoritative sources including vendor documentation, industry standards, and verified research. Learn more about our verification process and quality standards in our editorial standards page.

Apply Now

Choose one of three ways to apply:

Download script

Download and run the script directly
  • No app needed
  • Offline usage
  • Free
  • Open-source
Help

How to apply or restore "Disable guest file sharing over AFP" using script

  • ≈ 3 min to complete
  • Tools: Web Browser
  • Difficulty: Medium
  • ≈ 5 instructions
  1. 1

    Download

    Download the script file by clicking on the   Apply protection  button above.
    Use   Undo protection button above to restore changes.
  2. 2

    Keep the file

    If warned by your browser, keep the file.
  3. 3

    Open

    Open the downloaded file.
  4. 4

    Exit

    Once it's done, press any key to exit the window.
  5. 5

    Restart

    Restart your computer for all changes to take effect.

Apply with privacy.sexy

Guided, automated application with safety checks
  • Recommended for most users
  • Includes safety checks
  • Free
  • Open-source
  • Popular
  • Offline/Online usage
Open privacy.sexy
Help

How to apply or restore "Disable guest file sharing over AFP" using privacy.sexy

  • ≈ 3 min to complete
  • Tools: privacy.sexy
  • Difficulty: Simple
  • ≈ 4 instructions
privacy.sexy is free and open-source application that lets securely apply this action easily with more advanced options.
  1. 1

    Open or download

    Open or download the desktop application
  2. 2

    Choose script

    1. Search for the script name: Disable guest file sharing over AFP
    2. Check the script by clicking on the checkbox.
  3. 3

    Run

    Click on ▶️ Run button at the bottom of the page.

    This button only appears on desktop version (recommended). On browser, use 💾 Save button.

Run commands

Copy and run commands manually Requires technical knowledge
Apply changes
sudo defaults write '/Library/Preferences/com.apple.AppleFileServer' 'guestAccess' -bool NO
if ! command -v 'sysadminctl' &> /dev/null; then
echo 'Skipping because "sysadminctl" is not found.'
else
sudo sysadminctl -afpGuestAccess off
fi
sudo killall -HUP AppleFileServer
Help

How to apply or restore "Disable guest file sharing over AFP" using commands

  • ≈ 2 min to complete
  • Tools: Terminal app
  • Difficulty: undefined
  • ≈ 3 instructions
  1. 1

    Open terminal

    Open Terminal app.
  2. 2

    Copy code

  3. 3

    Paste & run

    Paste the code into Terminal and press Enter to run.

    Some changes require a system restart to take effect

Similar Guides

Wider Goal

Guides below includes this guide to achieve a wider goal.

See other more general settings that includes this one as one of its actions.

These plans combine multiple privacy settings, including this one, for stronger protection.

These scripts control guest access on macOS to protect your system's security and privacy. Guest access lets anyone use your Mac without a password or account. Thi...

Same Goal

Other guides in Disable guest accounts 

See settings that are in the same category as this guide.

Using other actions in the same category may help you achieve your goal better.


About the Creators

These people have authored this documentation and written its scripts:

  • Avatar of undergroundwires. The creator of PrivacyLearn and privacy.sexy. Black and white portrait showing a person wearing a polka dot tie and suit jacket, reflecting the professional expertise behind the privacy protection tools.
    • Certified security professional
    • 7+ years experience securing banks
    • Open-source developer since 2005
    • EU advisor, Public Speaker, Moderator
    • Hundreds across the globe
    • Testers, reviewers, developers
    • Companies, military agencies
    • Community since 2017

Reviewed By

This guide has undergone comprehensive auditing and peer review:
  • Expert review by undergroundwires

    • Verified technical accuracy and editorial standards
    • Assessed system impact and user privacy risks
  • Public review by large community

    • Privacy enthusiasts and professionals peer-reviewed
    • Millions of end-users tested across different environments

History

We continually monitor our guides, their impact and all other privacy options. We update our guides when new information becomes available. On every update, we publicly store who made the change, what has been changed, why the change was made and when the change was made.