Flush DNS Cache

OS VersionCommand
macOS 12 (Monterey)sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
macOS 11 (Big Sur)sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
macOS 10.15 (Catalina)sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
macOS 10.14 (Mojave)sudo killall -HUP mDNSResponder
macOS 10.13 (High Sierra)sudo killall -HUP mDNSResponder
macOS 10.12 (Sierra)sudo killall -HUP mDNSResponder
OS X 10.11 (El Capitan)sudo killall -HUP mDNSResponder
OS X 10.10 (Yosemite)sudo discoveryutil udnsflushcaches
OS X 10.9 (Mavericks)sudo killall -HUP mDNSResponder
OS X 10.8 (Mountain Lion)sudo killall -HUP mDNSResponder
Mac OS X 10.7 (Lion)sudo killall -HUP mDNSResponder
Mac OS X 10.6 (Snow Leopard)sudo dscacheutil -flushcache
Mac OS X 10.5 (Leopard)sudo lookupd -flushcache
Mac OS X 10.4 (Tiger)lookupd -flushcache
ipconfig /flushdns

Create bootable macOS install media

sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/UNTITLED

To avoid getting a ‘Installation Failed’ message, you need to change the date before installing :

date {month}{day}{hour}{minute}{year}

Set the Mac’s date to a date right around the time of release of the OS, e.g.

  • 10.7 : Mac OS X Lion was released on July 20, 2011.
  • 10.8 : OS X Mountain Lion was released on July 25, 2012.
  • 10.9 : OS X Mavericks was released on October 22, 2013.
  • 10.10 : OS X Yosemite was released on October 16, 2014.
  • 10.11 : OS X El Capitan was released on September 30, 2015.
  • 10.12 : macOS Sierra was released on September 20, 2016.
  • 10.13 : macOS High Sierra was released on September 25, 2017.
  • 10.14 : macOS Mojave was released on September 24, 2018.
  • 10.15 : macOS Catalina was released on October 7, 2019.
  • 11 : macOS Big Sur was released November 12, 2020.
  • 12 : macOS Monterey was released on October 25, 2021.

When creating an Intel install media on an ARM-based Mac, the OS expects the createinstallmedia executable to be signed before running, but the Apple-made program isn’t.
You’ll encounter a zsh : killed. error otherwise.
Sign the program with the following :

codesign -s - -f createinstallmedia

Permanently add SSH private key to Keychain

On OSX, the native ssh-add client has a special argument to save the private key’s passphrase in the OSX keychain, which means that your normal login will unlock it for use with ssh. On OSX Sierra and later, you also need to configure SSH to always use the keychain (see Step 2 below).

Alternatively you can use a key without a passphrase, but if you prefer the security that’s certainly acceptable with this workflow.

Step 1 – Store the key in the keychain

Just do this once:

ssh-add -K ~/.ssh/[your-private-key]

Enter your key passphrase, and you won’t be asked for it again.

(If you’re on a pre-Sierra version of OS X, you’re done, Step 2 is not required. In versions of macOS before Monterey, use --apple-use-keychain instead of -K)


Step 2 – Configure SSH to always use the keychain

It seems that OSX Sierra removed the convenient behavior of persisting your keys between logins, and the update to ssh no longer uses the keychain by default. Because of this, you will get prompted to enter the passphrase for a key after you upgrade, and again after each restart.

The solution is fairly simple, and is outlined in this github thread comment. Here’s how you set it up:

Ensure you’ve completed Step 1 above to store the key in the keychain.

If you haven’t already, create an ~/.ssh/config file. In other words, in the .ssh directory in your home dir, make a file called config.

In that .ssh/config file, add the following lines:

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

Change ~/.ssh/id_rsa to the actual filename of your private key. If you have other private keys in your ~.ssh directory, also add an IdentityFile line for each of them. For example, I have one additional line that reads IdentityFile ~/.ssh/id_ed25519 for a 2nd private key.

The UseKeychain yes is the key part, which tells SSH to look in your OSX keychain for the key passphrase.

That’s it! Next time you load any ssh connection, it will try the private keys you’ve specified, and it will look for their passphrase in the OSX keychain. No passphrase typing required.

Prevent creation of .DS_Store files on network shares

One thing that can be problematic when working with any shared storage is the existence of .DS_Store files on the network share, since these are intended for a single workstation’s use.

Enabling a policy to prevent the creation of .DS_Store files on network shares can speed up directory browsing (as described in this article) and prevent permission errors when moving/deleting files.

To prevent the Mac workstation from creating .DS_Store files on network shares, as well as instruct it to ignore existing .DS_Stores, open Terminal and enter:

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

and then log out/log in the macOS user account, or simply reboot the workstation.

To check the current policy in place, enter:

defaults read com.apple.desktopservices

If .DS_Store files are disallowed for network shares, “DSDontWriteNetworkStores = 1” should be displayed.

Note: To remove this policy and restore the default behavior, enter

defaults delete com.apple.desktopservices DSDontWriteNetworkStores

How to prevent the creation of .DS_Store files on network volumes

When working on network drives with Mac OS X every Mac user will by default create .DS_Store files. Those files are used by OS X to store custom attributes like icon positions. For more info on .DS_Store files read this article.

To prevent those files from being created:

  • Open up the Terminal
  • Run the following command
    defaults write com.apple.desktopservices DSDontWriteNetworkStores true
  • Restart your Mac or log out and back in.

Those .DS_Store files will now only be created on local volumes any you no longer have Windows users yelling at you about them. 😉

How to Change the Default Shell to Bash on macOS Catalina

With macOS Catalina, Apple is now using Zsh as the default shell. We love Zsh, but the trusty old Bash shell is still included with macOS, and you can quickly switch back to Bash if you prefer.

Zsh is only the default shell on newly created user accounts, so any existing accounts you have on an upgraded  Mac will still use Bash by default unless you change it. Each user account has its own default shell preference.

From the Terminal

To change a user account’s default shell on macOS, simply run the chsh -s (change shell) command in a Terminal window.

Change the default shell to Bash by running the following command:

chsh -s /bin/bash

You’ll have to enter your user account’s password. Finally, close the Terminal window and reopen it. You’ll be using Bash instead of Zsh.

Changing the default shell to Bash on macOS Catalina.

Change the default shell back to Zsh by running this command:

chsh -s /bin/zsh

Enter your password when prompted. After you close the terminal window and reopen it, you’ll be using Zsh.

Changing the default shell to Zsh on macOS Catalina.

You can see a list of included shells you can select by running the following command:

cat /etc/shells
Listing available shells in macOS Catalina's terminal.

From System Preferences

You can also change this option graphically from System Preferences if you prefer.

Head to System Preferences > Users & Groups on your Mac. Click the lock icon and enter your password. Hold the Ctrl key, click your user account’s name in the left pane, and select “Advanced Options.”

Opening Advanced Options in Users & Groups on macOS.

Click the “Login Shell” dropdown box and select “/bin/bash” to use Bash as your default shell or “/bin/zsh” to use Zsh as your default shell. Click “OK” to save your changes.

Changing the default login shell graphically in macOS Catalina.

Bash on macOS Is Still Outdated

Note that the version of Bash (Bourne Again SHell) included with macOS is still pretty outdated, however. If you run bash --version , you’ll see that Catalina includes Bash 3.2.57 when Bash 5.0 is the latest version. Newer versions are licensed under the GPLv3 license, while Apple still distributes a version licensed under GPLv2.

In contrast, the version of Zsh (Z shell) included with macOS (check with zsh --version ), is Zsh 5.7.2, which is the latest version at the time of Catalina’s release.

Viewing the versions of Bash and Zsh on macOS Catalina.

If you want the latest version of Bash, you can install it yourself via Homebrew.

How can I permanently add my SSH private key to Keychain so it is automatically available to ssh?

On OSX, the native ssh-add client has a special argument to save the private key’s passphrase in the OSX keychain, which means that your normal login will unlock it for use with ssh. On OSX Sierra and later, you also need to configure SSH to always use the keychain (see Step 2 below).

Alternatively you can use a key without a passphrase, but if you prefer the security that’s certainly acceptable with this workflow.

Step 1 – Store the key in the keychain

Just do this once:

ssh-add -K ~/.ssh/[your-private-key]

Enter your key passphrase, and you won’t be asked for it again.

(If you’re on a pre-Sierra version of OSX, you’re done, Step 2 is not required.)

Step 2 – Configure SSH to always use the keychain

It seems that OSX Sierra removed the convenient behavior of persisting your keys between logins, and the update to ssh no longer uses the keychain by default. Because of this, you will get prompted to enter the passphrase for a key after you upgrade, and again after each restart.

The solution is fairly simple, and is outlined in this github thread comment. Here’s how you set it up:

  1. Ensure you’ve completed Step 1 above to store the key in the keychain.
  2. If you haven’t already, create an ~/.ssh/config file. In other words, in the .ssh directory in your home dir, make a file called config.
  3. In that .ssh/config file, add the following lines:
    Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

    Change ~/.ssh/id_rsa to the actual filename of your private key. If you have other private keys in your ~.ssh directory, also add an IdentityFile line for each of them. For example, I have one additional line that reads IdentityFile ~/.ssh/id_ed25519 for a 2nd private key. The UseKeychain yes is the key part, which tells SSH to look in your OSX keychain for the key passphrase.
  4. That’s it! Next time you load any ssh connection, it will try the private keys you’ve specified, and it will look for their passphrase in the OSX keychain. No passphrase typing required.

Skip Mojave/Catalina Screenshot Delay

When you take a screenshot with Mojave or Catalina using Command+Shift+3, 4 or 5, you get a thumbnail of the image in the lower right corner for a few seconds.

This can be handy if you want to access the image by clicking it, without needing to find the file.

But if you’d rather not have the thumbnail, you can turn it off.

Use Command+Shift+5 and then click on the Options button that appears in the controls.

Then uncheck Show Floating Thumbnail.