How to View Saved Wi-Fi Passwords Using the macOS Terminal

If you need to connect a new device to your home or office Wi-Fi network but have forgotten the password, you don’t necessarily need to reset your router. As long as your Mac is currently connected to the network, or has been connected to it in the past, the password is securely saved within the macOS Keychain.

While you can retrieve these passwords using the graphical Keychain Access application, many advanced users find it much faster to retrieve them directly through the macOS Terminal using a built-in security command.

How to Find a Wi-Fi Password Using the security Command

macOS stores all saved Wi-Fi passwords in the System Keychain. We can query this database directly using the security command-line utility.

  1. Open the Terminal application. You can find it by pressing Command + Space to open Spotlight, typing “Terminal”, and hitting Return.
  2. Type the following command, replacing "NETWORK_NAME" with the exact name (SSID) of your Wi-Fi network. Keep the quotation marks if the network name contains spaces.
security find-generic-password -wa "NETWORK_NAME"
  1. Press Return.
  2. macOS will immediately present a security prompt asking for your credentials. This is because the Keychain is highly encrypted, and the system must verify that an administrator is requesting access to a plaintext password.
  3. Enter your Mac’s administrator Username and Password, and click Allow.

The Terminal will output the Wi-Fi password in plaintext on the very next line. If the command returns an error or no output, double-check that you have spelled the network name exactly as it appears in your Wi-Fi menu, including exact capitalization and spaces.

How to List All Previously Connected Wi-Fi Networks

If you cannot remember the exact name of the network, you can use a different command to list every Wi-Fi network your Mac has ever connected to. This requires querying the system configuration files using the networksetup utility.

Run the following command in the Terminal:

networksetup -listpreferredwirelessnetworks en0

Note: en0 is typically the Wi-Fi interface on modern Macs. If this returns an error, your Wi-Fi interface might be en1, which you can check by running networksetup -listallhardwareports.

The Terminal will output a list of Preferred Networks. Scroll through this list to find the exact name of the network you need the password for. Once you have the exact name, you can use the security find-generic-password command detailed above to reveal the password.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.