macOS¶
Apple's Unix desktop operating system.
Useful Commands¶
caffeinate: prevent the system from sleeping on behalf of a utility.mdutil: manage the metadata stores used by Spotlight.networksetup: configuration tool for network settings in System Preferences.profile: used to handle various profile types on macOS.scutil: Manage system configuration parameters.sharing: create share points for smb services.tccutil: manage the privacy database.
Logout user from a shell¶
or
Fix sshd client timeout config¶
macOS has an /etc/ssh/sshd_config that will never disconnect idle clients. With sketchy wifi, or for a variety of other reasons, this can cause ssh connections to pile up, causing a DoS on the ssh server. When this happens, a client that is attempting to connect may see kex_exchange_identification: read: Connection reset by peer. To fix this, set the following config values to anything other than 0. See man 5 sshd_config for more info.
The following settings would allow an unresponsive ssh session 10 minutes before terminating it:
Using BSD sed, you can quickly set this:
sudo sed -i '' -E 's/^#?ClientAliveInterval [0-9]+/ClientAliveInterval 120/ ; s/^#?ClientAliveCountMax [0-9]+/ClientAliveCountMax 5/ ;' /etc/ssh/sshd_config
sudo bash -c "launchctl stop com.openssh.sshd ; launchctl start com.openssh.sshd ;"
Show hardware info¶
This command supports the -json argument.
Install package from CLI¶
Use brew.sh for most things. Otherwise:
Start FTP server¶
Check swap usage¶
Disable wifi disconnect when locking screen¶
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources airport en1 prefs DisconnectOnLogout=NO
Show some downloaded files¶
This shows a list of all the quarantine checked downloads:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select distinct LSQuarantineDataURLString from LSQuarantineEvent'
Send Notifications from Terminal¶
https://github.com/julienXX/terminal-notifier
Enable verbose eap logging¶
Show MDM enrollment status¶
Network¶
- gif0 - Generic Tunnel Interface. See
man gif. - stf0 - Six To Four tunnel. See
man stf.
Migration Assistant¶
Some files are not migrated using Migration Assistant. EG:
- /etc/hosts
- crontabs
- /etc/apache2/httpd.conf
Remap caps-lock to escape¶
This remaps using a different mechanism than what the Keyboard pref pane uses, so the change will not be reflected there, so you will want to make sure to save both of these functions so you can reset when you need normal behavior.
caps_to_esc_map(){
hidutil property --set \
'{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'
}
caps_to_esc_unmap(){
hidutil property --set '{"UserKeyMapping":[]}'
}
Links¶
- Significant Changes in macOS 10.15 Catalina of Interest to Mac Admins
- https://github.com/ruedigerp/awesome-osx-command-line
- https://support.apple.com/en-us/108900: How to revive or restore Mac firmware
- https://weiyen.net/articles/useful-macos-cmd-line-utilities
- https://dortania.github.io/OpenCore-Legacy-Patcher: Run newer macOS versions on older, unsupported Mac hardware.
- https://tonsky.me/blog/tahoe-icons
- https://noheger.at/blog/2026/01/11/the-struggle-of-resizing-windows-on-macos-tahoe
- https://igorstechnoclub.com/sandbox-exec