# Server Hardening
Template for Part 2 of the setup script. All sudo commands.
## FileVault (MUST DISABLE)
FileVault disk encryption blocks unattended boot — the machine sits
at a pre-boot unlock screen waiting for a password before macOS even
loads. This is incompatible with headless server operation.
```bash
# Check status
fdesetup status
# Disable non-interactively (for MCP/scripted use)
printf '
UsernameUSERNAME
PasswordPASSWORD
' | sudo fdesetup disable -inputplist
# Monitor decryption progress (runs in background, machine stays usable)
fdesetup status
```
## Auto-Login
Required for headless operation — ensures the GUI session starts on
boot so user-level LaunchAgents (Tailscale, Signet, etc.) can run.
Cannot work while FileVault is enabled.
```bash
# Set auto-login user
sudo defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser "USERNAME"
# Create kcpassword (XOR-obfuscated password file)
python3 -c "
password = 'PASSWORD'
key = [0x7d, 0x89, 0x52, 0x23, 0xd2, 0xbc, 0xdd, 0xea, 0xa3, 0xb9, 0x1f]
encoded = bytearray()
for i, c in enumerate(password + chr(0)):
encoded.append(ord(c) ^ key[i % len(key)])
while len(encoded) % 12 != 0:
encoded.append(0)
with open('/etc/kcpassword', 'wb') as f:
f.write(encoded)
"
sudo chmod 600 /etc/kcpassword
```
## Power Management
```bash
sudo pmset -a displaysleep 0 disksleep 0 sleep 0 \
powernap 0 autorestart 1 networkoversleep 1
```
## Application Firewall
```bash
FW=/usr/libexec/ApplicationFirewall/socketfilterfw
sudo $FW --setglobalstate on
sudo $FW --setallowsigned on
sudo $FW --setstealthmode on
```
## SMB Guest Access
**WARNING**: Never hardcode share names. macOS uses Unicode curly
quotes (`'` U+2019) in default names like "Mac's Public Folder",
which silently breaks `sharing -r` with straight quotes. Always
parse dynamically:
```bash
# Remove ALL share points dynamically
sharing -l | grep "^name:" | sed 's/name:[[:space:]]*//' | \
while read -r name; do
sudo sharing -r "$name" 2>/dev/null && \
echo "removed: $name" || echo "skip: $name"
done
SMBPREF=/Library/Preferences/SystemConfiguration/com.apple.smb.server
sudo defaults write $SMBPREF AllowGuestAccess -bool false
```
## Consumer Launch Agents
Disable via `launchctl disable gui/$UID/