Sub topic 11
Verifying your settings from Terminal
This chapter assumes you can open Terminal, run a command, and use sudo. It also assumes you have already turned on FileVault and the firewall in System Settings. Here you will confirm those settings from the command line and combine the checks into one script.
Why check from Terminal
System Settings shows the current state, but a command gives you text you can read, copy into a note, or run again later. It also works over SSH and in scripts. The checks below only read settings. None of them changes anything.
Check FileVault with fdesetup
The fdesetup tool manages FileVault. Its status option reports whether the startup disk is encrypted.
fdesetup statusYou will see one of these results:
FileVault is On.Encryption is finished.FileVault is Off.The disk is not encrypted.Encryption in progress: Percent completed = 42.5Encryption is still running. Your data is protected only after it finishes.
A newly enabled FileVault can take a while to finish, and you can keep using the Mac in the meantime. Run the command again later to see the progress.
Check the application firewall with socketfilterfw
The firewall is controlled by socketfilterfw. It is stored in a system folder that is not on your PATH, so type the full path.
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstateThe reply tells you whether the firewall is enabled. A typical reply is Firewall is enabled. (State = 1). If the firewall is off, the reply says it is disabled.
Next, check two further options.
/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode
/usr/libexec/ApplicationFirewall/socketfilterfw --getblockallThe first command reports stealth mode, where the Mac does not answer probing requests such as ping. The second reports whether the Mac blocks all incoming connections, even for apps you have allowed. Both can be off while the firewall is on. That is a valid configuration, so a reply of "off" is not an error. It only means you chose not to use that option.
Turn the firewall on from Terminal
If the check shows the firewall is off, you can turn it on. This is the only command in the chapter that changes a setting, so it needs administrator rights.
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onTerminal asks for your password and shows nothing while you type. Run --getglobalstate again afterward to confirm the change.
Combine the checks into a script
Running three commands each time is tedious. A short script prints them together.
#!/bin/bash
# Print a quick security status summary for this Mac.
echo "FileVault: $(fdesetup status)"
echo "Firewall: $(/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate)"
echo "Stealth: $(/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode)"Save it as security-check.sh, then run it with bash security-check.sh. If you want to run it as ./security-check.sh, make it executable first with chmod +x security-check.sh.
The script is read-only, so you can run it as often as you like, and you do not need sudo for it.
What Terminal cannot tell you
Find My has no documented command-line check. To confirm it, open System Settings, select your Apple Account, choose iCloud, and look for Find My Mac. The script therefore covers two of the three protections. Treat a manual look at Find My as part of the same routine.
A status check also shows only the setting, not the whole picture. For example, FileVault is On. does not tell you that you have stored your recovery key safely. Verify that separately.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `command not found` for `socketfilterfw` | You typed only the program name | Use the full path starting with `/usr/libexec/` |
| `Permission denied` when turning the firewall on | The command ran without `sudo` | Add `sudo` and use an administrator account |
| `./security-check.sh: Permission denied` | The script is not executable | Run `chmod +x security-check.sh`, or use `bash security-check.sh` |
| Firewall reports enabled but stealth mode is off | Stealth mode is a separate option | Turn it on in System Settings under Network, Firewall, Options, if you want it |
A suggested routine
Exercise
You run fdesetup status and see "Encryption in progress: Percent completed = 60.0". Is the disk fully protected yet, and what should you do?
Show answer
No. Encryption has not finished, so the disk is not fully protected. You can keep using the Mac, then run fdesetup status again later until it reports "FileVault is On."
Exercise
Why does the status script not include a check for Find My, and how do you check it instead?
Show answer
Find My has no documented command-line check. Open System Settings, select your Apple Account, choose iCloud, and confirm that Find My Mac is on.