Scripts for macOS endpoint management. These run via NinjaOne RMM or directly from a terminal session.
See HOWTO.md for guidance on downloading and running scripts.
| Script | Description |
|---|---|
| Install BitDefender GravityZone.sh | Installs the BitDefender GravityZone endpoint agent on macOS |
| Install ConnectSecure Agent.sh | Installs the ConnectSecure (CyberCNS) vulnerability scanning agent on macOS |
| Install Huntress Agent.sh | Installs the Huntress agent on macOS via NinjaOne |
| Uninstall Webroot.sh | Removes the Webroot SecureAnywhere agent from macOS |
| Script | Description |
|---|---|
| Configure Automatic Updates.sh | Enables or disables automatic macOS software updates |
| Create Admin User.sh | Creates a local administrator account on macOS |
| Create Desktop Shortcut.sh | Creates a URL shortcut on the user's Desktop |
| Get Apple IDs.sh | Reports Apple IDs associated with accounts on the device |
| Set User Password.sh | Sets the password for a specified local user account |
| Script | Description |
|---|---|
| Audit Admin Users.sh | Reports all users with administrator privileges on the device |
| Detect Antivirus.sh | Detects installed/active third-party antivirus or EDR products and falls back to Apple XProtect status; reports to NinjaOne installedAntivirus field |
| Detect CVE CloudMensis.sh | Checks for indicators of the CloudMensis macOS spyware |
| Detect MDM Enrollment.sh | Reports whether the device is enrolled in an MDM platform |
| Get FileVault Key.sh | Retrieves the FileVault recovery key for the device |
| Get FileVault Status.sh | Reports the current FileVault encryption status and publishes it to the diskEncryptionStatus Ninja custom field |
macOS uses the Bash or Zsh shell (Zsh is the default since macOS Catalina). Most Linux/POSIX commands work as-is. This section covers the overlap and highlights what's different or macOS-specific.
Any text after a # in an example is a comment explaining what the command does.
Note: macOS uses forward slashes like Linux. The user home directory is /Users/username (not /home/username).
Invoke the Terminal
⌘ + Space → type Term → Enter
Change Directory
cd ~ # Go to current user's home directory
cd /Users # macOS home directories live here (not /home like Linux)
cd /Applications
cd .. # Go up one levelCreate / delete directory
mkdir foldername # Create a directory
rmdir foldername # Remove an empty directory
rm -rf foldername # Remove a directory and all its contents (use with care)Print working directory
pwd # Show current pathList Files
ls # List files
ls -a # Include hidden dot-files
ls -l # Long format with permissions and sizes
ls -lh # Long format with human-readable sizes
ls -G # Colorized output (macOS default ls flag for color)View file contents
cat filename # Print file to terminal
less filename # Paginate: ↑/↓ to scroll, q to quit
tail -f logfile # Follow a log file in real timeFind
find / -name "filename" # Find a file by name from root
find /Users -name "*.plist" # Find .plist files under /Users
grep -Ri "search term" /path/ # Case-insensitive content search, recursiveEdit
nano filename # Simple terminal editor: Ctrl+O to save, Ctrl+X to exit
vim filename # Advanced editor: i to insert, Esc then :wq to save and quit
open filename # Open file with its default app (macOS-specific)
open -a TextEdit filename # Open with a specific applicationCopy, Move, Delete
cp source.txt dest.txt # Copy file
cp -R sourcefolder destfolder # Copy folder recursively
mv source.txt /path/dest.txt # Move or rename a file
rm filename # Delete file
rm -rf foldername # Delete folder and contentsCopy output to clipboard (macOS-specific)
command | pbcopy # Copy command output to clipboard
pbpaste # Paste clipboard contents to terminal
cat file.txt | pbcopy # Copy file contents to clipboarddiskutil list # List all disks and partitions
diskutil info /dev/disk0 # Details for a specific disk
diskutil eraseDisk APFS NewName /dev/disk2 # Erase and reformat a disk
df -h # Disk space usage (human-readable)
du -sh /path/to/folder # Size of a specific foldersw_vers # macOS version (ProductName, ProductVersion, BuildVersion)
sw_vers -productVersion # Just the version number, e.g. 14.4.1
system_profiler SPSoftwareDataType # Detailed OS info
uname -a # Kernel version and architecturesystem_profiler SPHardwareDataType # Hardware overview: model, CPU, RAM, serial number
system_profiler SPMemoryDataType # Memory slots and installed RAM
sysctl -n machdep.cpu.brand_string # CPU model
sysctl -n hw.memsize | awk '{print $1/1073741824 " GB"}' # Total RAM in GBsudo command # Run with elevated privileges (prompts for admin password)
sudo !! # Re-run the last command with sudo
open -a App.app # Launch an application from the terminallaunchctl list # List all loaded launch agents/daemons
launchctl list | grep -i servicename # Search for a specific service
launchctl load /Library/LaunchDaemons/com.example.plist # Load a service
launchctl unload /Library/LaunchDaemons/com.example.plist # Unload a service
launchctl start com.example.service # Start a loaded service
launchctl stop com.example.service # Stop a loaded serviceps aux # All processes for all users
ps aux | grep chrome # Filter for a specific process
top # Real-time process viewer (q to quit)
activity monitor # GUI equivalent: open /Applications/Utilities/Activity\ Monitor.appkill {pid} # Gracefully stop a process by ID
kill -9 {pid} # Force-kill a process by ID
killall Finder # Kill all processes matching a name (restarts Finder)
pkill -i "chrome" # Case-insensitive process name killcaffeinate # Keep the Mac awake while the terminal is open
caffeinate -t 3600 # Stay awake for 3600 seconds (1 hour)ipconfig getifaddr en0 # IP of the primary Wi-Fi adapter
ipconfig getifaddr en1 # IP of the Ethernet adapter
ifconfig | grep "inet " # All IPv4 addressescurl -s https://ifconfig.me
curl -s https://api.ipify.orgdig google.com # DNS A record lookup
dig google.com MX # MX records
dig google.com TXT # TXT/SPF records
dig -x 8.8.8.8 # Reverse lookup (PTR)
nslookup google.com # Simple forward lookupwhois 8.8.8.8 # IP ownership and registration info
whois google.com # Domain registration infocurl -s https://ipinfo.io/8.8.8.8 # JSON: city, region, org
curl -s https://ipinfo.io/8.8.8.8/country # Country code onlyping 192.168.1.1 # Basic ping
ping -c 4 192.168.1.1 # Send exactly 4 pings
arp -a # ARP table — known LAN IPs and MACs
# Ping broadcast to discover LAN hosts, then check ARP table
ping 192.168.1.255 &; sleep 5; kill %1; arp -anc -zw3 192.168.1.1 443 && echo "open" || echo "closed" # Test a TCP port
nmap -p 22,80,443 192.168.1.1 # Scan specific ports (requires nmap)ssh user@server.address # Connect to remote host
ssh user@server.address -p 2222 # Specify a non-standard port
ssh user@server.address 'uptime' # Run a command and exit
ssh -L 4433:192.168.1.1:443 user@jumphost # SSH tunnel: proxy WAN → LAN resource
# Passwordless login (key-based auth)
ssh-keygen -t ed25519 # Generate an SSH key pair (leave passphrase blank for automation)
ssh-copy-id user@server.address # Install your public key on the remote hostwhoami # Current username
id # Username, UID, and group membershipswho # Users currently logged in and their consoles
w # Logged-in users with activity infopasswd # Change the current user's password
passwd username # Change another user's password (requires sudo)
sudo passwd usernamesu username # Switch to another user
sudo -i # Open a root shell
sudo -u username bash # Open a shell as another userdscl . list /Users # List all local users
dscl . list /Users | grep -v "^_" # Exclude system accounts
dscl . read /Users/username # Detailed info on a user
dscl . list /Groups # List all groups
dscacheutil -q group -a name admin # Members of the admin group
id username # Groups a user belongs tosudo dscl . -create /Users/newuser
sudo dscl . -create /Users/newuser UserShell /bin/zsh
sudo dscl . -create /Users/newuser RealName "Full Name"
sudo dscl . -create /Users/newuser UniqueID 502
sudo dscl . -create /Users/newuser PrimaryGroupID 20
sudo dscl . -passwd /Users/newuser password123
# Add user to the admin group (grants local admin)
sudo dscl . -append /Groups/admin GroupMembership newusersoftwareupdate -l # List available updates
softwareupdate -ia # Install all available updates
softwareupdate -i "Update Name-1.0" # Install a specific updatebrew install nmap # Install a package
brew uninstall nmap # Remove a package
brew update # Update Homebrew itself
brew upgrade # Upgrade all installed packages
brew list # List installed packages
brew search nmap # Search for a packageprofiles show -type enrollment # Show MDM enrollment profile
sudo profiles -e -path /path/to/profile.mobileconfig # Install a configuration profile
profiles list # List all installed profilessecurity list-keychains # List keychains
security find-certificate -a -p /path/keys.keychain # List certs in a keychain
security import cert.p12 -k login.keychain # Import a certificate# Enable/disable remote login (SSH)
sudo systemsetup -setremotelogin on
sudo systemsetup -setremotelogin off
# Set computer name
sudo scutil --set ComputerName "NewName"
sudo scutil --set HostName "NewName"
sudo scutil --set LocalHostName "NewName"
# Time zone
sudo systemsetup -settimezone "America/New_York"
sudo systemsetup -setusingnetworktime on- https://ss64.com/mac/ — macOS command reference
- https://www.explainshell.com/ — Parses complex command strings
man command— Built-in manual pages for any command- https://support.apple.com/guide/terminal/welcome/mac — Apple Terminal User Guide