Back to Resources
Level
Script
Security
When a macOS device is lost, stolen, decommissioned, or repurposed, IT professionals need a reliable way to erase sensitive data. Manually wiping a device is time-consuming and prone to human error. This script automates secure device erasure, reducing the risk of unauthorized access to corporate or personal information while ensuring compliance with security policies.
This script securely wipes critical user and system data, including:
This script is highly destructive and should only be used when full data removal is necessary.
#!/bin/bash
# This resource is provided as a convenience for Level users. We cannot
# guarantee it will work in all environments. Please test before deploying
# to your production environment. We welcome contributions to our community
# library
# Level Library
# https://level.io/library/script-macos-device-erase-script
# WARNING: Dangerous operation - Recursively delete files and directories for all users
rm -rf /Users/*
rm -rf /Applications/*
rm -rf /Library/*
# Clear Browser Data (Example for Chrome, modify for other browsers as needed)
rm -rf ~/Library/Application\ Support/Google/Chrome/*
# Clear Outlook Data (Modify the path if different)
rm -rf ~/Library/Application\ Support/Microsoft/Outlook/*
# Remove VPN Credentials (Example for a specific VPN client, modify as needed)
rm -f Path/To/VPN/Credentials/Store
# Remove Saved Wi-Fi Networks
# Requires administrator password
networksetup -removeallpreferredwirelessnetworks en0
# Remove macOS Keychain (Stores passwords and account information)
# WARNING: This will delete ALL saved passwords and cannot be undone
security delete-keychain login.keychain
# Remove SSH Keys (if applicable)
rm -rf ~/.ssh/*
macOS - Erase Device
This macOS script performs a comprehensive remote device wipe, removing user data, applications, credentials, and system files to protect sensitive information when a device is lost or stolen.
Bash
1200
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.