Mac Snippets

January 11, 2023

Matt Hammond

Code Snippets

  • remove duplicates from $PATH
typeset -U PATH
  • link airport
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport
  • partition USB
sudo diskutil partitionDisk /dev/disk2 4 GPT ExFAT Tails 32G APFS Keys 10M ExFAT Drive 1G ExFAT Go\ Drive R
sudo diskutil apfs encryptVolume disk3s1 -user disk
  • format USB
diskutil erasedisk ExFAT GoDrive disk2 #format for Linux only
diskutil erasedisk MS-DOS GODRIVE disk2 #format for Mac/Linux
  • write image to usb
sudo gdd if=~/Downloads/debian.iso of=/dev/disk2 status=progress bs=4M
  • unload macfuse kernel
sudo kextunload -b io.macfuse.filesystems.macfuse

Password Snippets

Storing and retrieving passwords in bash scripts from the macOS keychain #password

  • Allow access to macOS keychain (use only if creating keychains remote)
security -i unlock-keychain
  • Set up password in macOS keychain
    • -T = immediately grant access without GUI confirmation
security add-generic-password -T /usr/bin/security -s "Keychain item name here" -a "username here" -w
  • Retrieve the password in a script like this:
PASSWORD=$(security find-generic-password -s "Keychain item name here" -a "username here" -w)
  • Error catching for passwords
pw_name="CLI Test"
pw_account="armin"
if ! cli_password=$(security find-generic-password -w -s "$pw_name" -a "$pw_account"); then
	echo "could not get password, error $?"
	exit 1
fi
echo "the password is $cli_password"

Sudo Password TouchID

  • edit /etc/pam.d/sudo
  • add following line to the top
auth       sufficient     pam_tid.so