| name | macos-security-hardening |
| description | Comprehensive guide for securing and hardening macOS systems with privacy-focused configurations, firewall rules, and security best practices |
| triggers | ["how do I secure my macOS system","improve privacy on Mac","harden macOS security settings","configure macOS firewall and encryption","setup secure macOS environment","macOS security best practices","lock down macOS for privacy","enterprise security for Mac"] |
macOS Security Hardening
Skill by ara.so — Security Skills collection.
This skill provides comprehensive guidance for securing macOS systems based on the community-maintained drduh/macOS-Security-and-Privacy-Guide. It covers system hardening, encryption, firewall configuration, DNS security, and privacy enhancements for both Apple silicon and Intel Macs.
Overview
The macOS Security and Privacy Guide is a collection of battle-tested techniques for:
- Full disk encryption with FileVault
- Firewall configuration (application-level and packet filtering)
- DNS security with DNSCrypt and encrypted DNS profiles
- Privacy hardening by disabling telemetry and tracking
- Secure browsing configurations for Firefox, Chrome, and Safari
- System monitoring with OpenBSM and DTrace
- Physical security measures and admin account separation
Important: Apple silicon Macs are strongly recommended over Intel Macs due to hardware-level security vulnerabilities in Intel CPUs that cannot be patched.
Threat Modeling Framework
Before applying any security measures, create a threat model:
Asset Identification
Adversary Analysis Template
| Adversary | Motivation | Capabilities | Mitigation |
|---|
| Roommate | Curiosity | Physical access, screen viewing | Use FileVault, auto-lock screen, privacy filters |
| Thief | Financial gain | Device theft, shoulder surfing | Find My Mac, strong passwords, remote wipe |
| Criminal | Data theft | Malware, phishing, exploits | Gatekeeper, firewall, updated software |
| Corporation | Data collection | Telemetry, tracking | Block telemetry, DNS filtering, VPN |
| Nation State | Surveillance | Advanced exploits, traffic analysis | Full encryption, Tor, air-gapped backups |
System Updates
Keep macOS and all software current:
softwareupdate --list
sudo softwareupdate --install --all
sudo softwareupdate --schedule on
sudo softwareupdate --install --recommended
FileVault Full Disk Encryption
FileVault encrypts your entire disk using XTS-AES-128 with a 256-bit key.
sudo fdesetup status
sudo fdesetup enable
sudo fdesetup list
sudo fdesetup add -usertoadd username
sudo fdesetup changerecovery -personal
Important: Store your recovery key in a secure location separate from your Mac (e.g., password manager, safe).
Hibernation Mode for Enhanced Security
pmset -g | grep hibernatemode
sudo pmset -a hibernatemode 25
sudo pmset -a destroyfvkeyonstandby 1
sudo pmset -a standby 0
sudo pmset -a autopoweroff 0
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
Admin and User Account Separation
Create separate admin and standard user accounts for daily use:
sudo dscl . -create /Users/standarduser
sudo dscl . -create /Users/standarduser UserShell /bin/bash
sudo dscl . -create /Users/standarduser RealName "Standard User"
sudo dscl . -create /Users/standarduser UniqueID 503
sudo dscl . -create /Users/standarduser PrimaryGroupID 20
sudo dscl . -create /Users/standarduser NFSHomeDirectory /Users/standarduser
sudo dscl . -passwd /Users/standarduser
dsmemberutil checkmembership -U standarduser -G admin
sudo dsenableroot -d
Firmware Security
sudo firmwarepasswd -check
sudo firmwarepasswd -setpasswd
csrutil status
csrutil status
csrutil authenticated-root status
Firewall Configuration
Application Layer Firewall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setloggingmode on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setblockall on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsigned on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
Packet Filtering with pf
Create /etc/pf.conf:
wifi = "en0"
lan = "en1"
set block-policy drop
set skip on lo0
scrub in all no-df
block log all
pass out quick on $wifi inet keep state
pass out quick on $lan inet keep state
pass in quick on $wifi proto icmp icmp-type { echoreq, unreach }
pass in quick on $wifi proto tcp from any to any port 22 keep state
pass in quick on $wifi proto { tcp, udp } from any to any keep state
Enable and load pf:
sudo pfctl -nf /etc/pf.conf
sudo pfctl -ef /etc/pf.conf
sudo pfctl -s all
sudo pfctl -s info
sudo pfctl -f /etc/pf.conf
sudo pfctl -d
DNS Security
Encrypted DNS Profiles
Install DNS over HTTPS/TLS profile:
curl -o ~/Downloads/Cloudflare-1.1.1.1.mobileconfig \
https://1.1.1.1/Cloudflare-1.1.1.1.mobileconfig
curl -o ~/Downloads/Quad9-DoH.mobileconfig \
https://www.quad9.net/support/set-up-guides/macos/Quad9-DoH.mobileconfig
open ~/Downloads/Cloudflare-1.1.1.1.mobileconfig
Hosts File Blocking
sudo cp /etc/hosts /etc/hosts.backup
curl -o /tmp/hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
sudo cp /tmp/hosts /etc/hosts
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
DNSCrypt Proxy
brew install dnscrypt-proxy
cat > /usr/local/etc/dnscrypt-proxy.toml << 'EOF'
server_names = ['cloudflare', 'quad9-dnscrypt-ip4-nofilter-pri']
listen_addresses = ['127.0.0.1:53']
max_clients = 250
ipv4_servers = true
ipv6_servers = false
dnscrypt_servers = true
doh_servers = true
require_dnssec = true
require_nolog = true
require_nofilter = false
force_tcp = false
timeout = 2500
keepalive = 30
log_level = 2
use_syslog = true
cache = true
cache_size = 512
cache_min_ttl = 600
cache_max_ttl = 86400
cache_neg_ttl = 60
EOF
sudo brew services start dnscrypt-proxy
networksetup -setdnsservers Wi-Fi 127.0.0.1
networksetup -setdnsservers Ethernet 127.0.0.1
scutil --dns | grep "nameserver"
Privacy Hardening
Disable Telemetry and Tracking
defaults write com.apple.safari UniversalSearchEnabled -bool false
defaults write com.apple.safari SuppressSearchSuggestions -bool true
defaults write com.apple.assistant.support "Assistant Enabled" -bool false
launchctl disable "user/$UID/com.apple.assistantd"
defaults write com.apple.AdLib allowApplePersonalizedAdvertising -bool false
defaults write com.apple.CrashReporter DialogType none
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.SubmitDiagInfo.plist
defaults write com.apple.coreservices.useractivityd ActivityAdvertisingAllowed -bool false
defaults write com.apple.coreservices.useractivityd ActivityReceivingAllowed -bool false
sudo defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd \
LocationServicesEnabled -bool false
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
defaults write com.apple.Safari WebKitStorageBlockingPolicy -int 1
defaults write com.apple.Safari BlockStoragePolicy -int 2
Disable Unnecessary Services
sudo dscl . -delete /Users/Guest
sudo defaults write /Library/Preferences/com.apple.AppleFileServer guestAccess -bool false
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server AllowGuestAccess -bool false
sudo systemsetup -setremoteappleevents off
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict Enabled -int 0
sudo launchctl disable system/com.apple.screensharing
cupsctl --no-share-printers
sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 0
Browser Hardening
Firefox Configuration
Create user.js in Firefox profile directory (~/Library/Application Support/Firefox/Profiles/*.default-release/):
user_pref("privacy.trackingprotection.enabled", true);
user_pref("privacy.trackingprotection.socialtracking.enabled", true);
user_pref("privacy.donottrackheader.enabled", true);
user_pref("privacy.resistFingerprinting", true);
user_pref("privacy.firstparty.isolate", true);
user_pref("toolkit.telemetry.enabled", false);
user_pref("toolkit.telemetry.unified", false);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("network.trr.mode", 2);
user_pref("network.trr.uri", "https://cloudflare-dns.com/dns-query");
user_pref("security.ssl.require_safe_negotiation", true);
user_pref("security.tls.version.min", 3);
user_pref("security.cert_pinning.enforcement_level", 2);
user_pref("media.peerconnection.enabled", false);
(, );
Safari Hardening
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true
defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically -bool false
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
defaults write com.apple.Safari AutoFillPasswords -bool false
defaults write com.apple.Safari AutoFillCreditCardData -bool false
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
System Monitoring
OpenBSM Audit
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.auditd.plist
sudo vi /etc/security/audit_control
sudo praudit -l /var/audit/* | grep "authentication"
sudo praudit -l /var/audit/* | grep "file"
sudo tail -f /var/audit/current | praudit -l
Network Monitoring
netstat -an | grep ESTABLISHED
sudo lsof -iTCP -sTCP:LISTEN -n -P
sudo tcpdump -i en0 -n
sudo tcpdump -i en0 port 53
nettop -m tcp
sudo fs_usage -w -f network | grep -v "mdnsresponder"
Process Monitoring
sudo fs_usage -w -f exec
sudo fs_usage -w -f filesys
sudo dtrace -n 'proc:::exec-success { printf("%s %s\n", execname, curpsinfo->pr_psargs); }'
sudo dtrace -n 'syscall::connect:entry { printf("%s[%d] connecting\n", execname, pid); }'
SSH Hardening
Edit /etc/ssh/sshd_config:
Protocol 2
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
UsePAM yes
X11Forwarding no
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
ClientAliveInterval 300
ClientAliveCountMax 2
MaxAuthTries 3
MaxSessions 2
AllowUsers yourusername
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
HostKeyAlgorithms ssh-ed25519,rsa-sha2-512,rsa-sha2-256
Generate strong SSH keys:
ssh-keygen -t ed25519 -a 100 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -o -a 100 -C "your_email@example.com"
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/authorized_keys
Metadata Removal
exiftool -all= image.jpg
brew install --cask imageoptim
open -a ImageOptim image.jpg
xattr -cr /path/to/file
rm -P sensitive_file.txt
srm -vz sensitive_file.txt
Password Management
openssl rand -base64 32
brew install diceware
diceware -n 6
security find-generic-password -ga "account_name"
security add-generic-password -a "account_name" -s "service_name" -w
security dump-keychain -d login.keychain-db
security lock-keychain login.keychain-db
Backup Security
tmutil setdestination -a /Volumes/BackupDrive
diskutil apfs enableFileVault /Volumes/BackupDrive -user disk
tmutil listbackups
tmutil verify
hdiutil create -size 50g -encryption AES-256 -type SPARSEBUNDLE \
-fs "APFS" -volname "SecureBackup" ~/SecureBackup.sparsebundle
hdiutil attach ~/SecureBackup.sparsebundle
rsync -avh --delete ~/Documents/ /Volumes/SecureBackup/
hdiutil detach /Volumes/SecureBackup
Lockdown Mode
For high-risk users facing targeted attacks:
defaults read com.apple.Security LockdownModeEnabled
sudo defaults write /Library/Preferences/com.apple.Security LockdownModeEnabled -bool true
Physical Security
defaults write com.apple.screensaver idleTime -int 300
sudo defaults write /Library/Preferences/com.apple.loginwindow \
LoginwindowText "If found, please contact: your@email.com"
sudo defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser
defaults write com.apple.Terminal SecureKeyboardEntry -bool true
sudo sed -i.bak 's/^auth.*pam_tid.so/#&/' /etc/pam.d/sudo
Quick Security Audit Script
#!/bin/bash
echo "=== macOS Security Audit ==="
echo -n "FileVault: "
fdesetup status
echo -n "Firewall: "
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
echo -n "Gatekeeper: "
spctl --status
echo -n "System Integrity Protection: "
csrutil status
echo -n "Firmware Password: "
sudo firmwarepasswd -check
echo -n "Pending Updates: "
softwareupdate -l 2>&1 | grep -q "No new software" && echo "None" || echo "Available"
echo "Admin users:"
dscl . -read /Groups/admin GroupMembership
echo -n "Screensaver password delay: "
defaults read com.apple.screensaver askForPasswordDelay
echo -n "SSH Status: "
sudo systemsetup -getremotelogin
echo "=== Audit Complete ==="
Troubleshooting
Firewall Issues
sudo pfctl -d
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
log show --predicate 'process == "socketfilterfw"' --last 1h
sudo pfctl -F all -f /etc/pf.conf
DNS Problems
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
scutil --dns
nslookup example.com
sudo dnscrypt-proxy -config /usr/local/etc/dnscrypt-proxy.toml -check
FileVault Recovery
diskutil apfs unlockVolume disk1s1
Performance Issues
sudo mdutil -i off /
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
sudo mdutil -i on /
Environment Variables
export GPG_TTY=$(tty)
export DNSCRYPT_PROXY_CONFIG="/usr/local/etc/dnscrypt-proxy.toml"
eval "$(/opt/homebrew/bin/brew shellenv)"
Additional Resources
Related Tools
brew install gnupg yubikey-personalization pinentry-mac
brew install --cask lulu little-snitch knockknock oversight
brew install --cask blockblock lulu knockknock ransomwhere oversight
This skill provides comprehensive macOS security hardening suitable for both individual users and enterprise deployments. Always test configurations in a safe environment before applying to production systems.