TechEarl

How to Find a Saved Wi-Fi Password From the macOS Terminal

Print a saved Wi-Fi password from the macOS Terminal with the built-in security command: no third-party tool, no install. Reads your own login keychain, with the auth prompt that is supposed to appear.

Ishan Karunaratne⏱️ 8 min readUpdated
Share thisCopied
Print a saved Wi-Fi password from the macOS Terminal with the built-in security find-generic-password command, no third-party download needed.

The fast answer: macOS already ships the tool, so you do not need to download anything. Open Terminal and run one command, swapping in your network name:

bash
security find-generic-password -wa "MyNetworkSSID"

That prints the saved password and nothing else. macOS will pop a Keychain prompt asking you to allow access (Touch ID or your login password); that prompt is correct and expected, and I explain why below. If your SSID has spaces or punctuation, keep the quotes.

A lot of older write-ups, including the one I was correcting when I revisited this, send you off to clone a third-party wifi-password script from GitHub. You do not need it. That tool is unmaintained, and under the hood it is just a wrapper around the very command above. The built-in security binary does the whole job natively, on every macOS version, with nothing to install and nothing to keep updated.

What the flags mean

security is the command-line front end to the macOS Keychain. A stored Wi-Fi password lives there as a "generic password" item, keyed by the network name, which is why the subcommand is find-generic-password:

bash
security find-generic-password -wa "MyNetworkSSID"
  • -a "MyNetworkSSID" is the account, and for Wi-Fi items the account is the network name (SSID). This is the network whose password you want.
  • -w means print the password only, on its own line, with no surrounding metadata. That is what makes the output copy-paste clean.

Drop the -w and use -g instead if you want the full keychain record, including the password line:

bash
security find-generic-password -ga "MyNetworkSSID"

-g dumps the item's attributes (creation date, the item class, the keychain it lives in) and prints the password on a password: line near the bottom. To pull just that one line out:

bash
security find-generic-password -ga "MyNetworkSSID" 2>&1 | grep "password:"

The 2>&1 is there because security writes the password line to standard error, not standard output, so you have to redirect it before grep can see it. With -w you do not need any of that, which is why -wa is the form I reach for.

The Keychain prompt is supposed to happen

The first time you run this for a given network, macOS interrupts with a dialog: "security wants to use your confidential information stored in [SSID] in your keychain." It wants Touch ID or your login password before it hands the secret over.

Do not treat that prompt as a problem to route around. It is the security model working exactly as designed: a stored password should not leave the keychain just because a process asked nicely. Click Allow (or Always Allow if you would rather not be asked again for that item) and authenticate. If you run the command in a script and nothing appears, check that Terminal is in the foreground; the dialog is modal and needs a visible app to attach to.

You will only ever be prompted for your own login keychain, unlocked by your own credentials. There is no flag that bypasses this. If you could read a password without authenticating, so could anything else running as your user, which is the whole point of the keychain existing.

Finding the current network name

If you are connected and just want this network's password, you need the SSID to pass to -a. Click the Wi-Fi icon in the menu bar and the connected network is checked at the top. From the Terminal, recent macOS exposes it through networksetup:

bash
networksetup -getairportnetwork en0

That prints Current Wi-Fi Network: MyNetworkSSID for the interface, and en0 is the Wi-Fi interface on most Macs (run networksetup -listallhardwareports if yours differs). Older guides reach for airport -I, but Apple deprecated the airport utility and removed it in macOS Sonoma 14.4, so networksetup is the form that keeps working.

If you have read about wdutil info or system_profiler SPAirPortDataType as the modern replacements, be aware that since 14.4 both of those redact the live network name (the SSID shows as <redacted> unless the calling app holds a Location Services grant). networksetup -getairportnetwork is the one that still prints the SSID in plain text, which is why I lean on it here.

You do not have to be connected to the network to read its password. The keychain stores every network you have ever joined, so you can pull the password for the coffee shop you visited last month while sitting at home on a completely different connection. To browse what is stored, open Keychain Access (or, on macOS Sequoia and Tahoe, the Passwords app, which has a dedicated Wi-Fi section listing every saved network) and search; each Wi-Fi entry's name is the SSID you would feed to -a.

A note on what this does and does not do

This is worth being plain about, because "get a Wi-Fi password from the Terminal" is a phrase that sounds like an attack and is not one.

The security command only reveals passwords your own Mac has already joined and saved, gated behind your own keychain authentication. It cannot read a network you have never connected to, it cannot read another user's keychain, and it does nothing to a network you are not authorized on. It is the command-line equivalent of opening Keychain Access and clicking "Show Password," which has always required your login password too. Reaching for it to recover the password to your own home network so you can type it into a new phone is the normal case; there is no privilege escalation hiding in here.

See also

No. The security command is part of macOS and has been for years, so security find-generic-password -wa "SSID" works out of the box. The third-party wifi-password scripts that older guides recommend are unnecessary and unmaintained; they only wrap this same built-in command.

Because the password lives in your login keychain, and macOS will not release a stored secret without authenticating you first. The prompt is the security model working correctly. Click Allow and authenticate; choose Always Allow if you do not want to be asked again for that network.

-w prints only the password, on its own line, ready to copy. -g prints the full keychain record (attributes plus the password on a password: line). Use -wa when you just want the password, and -ga when you want the surrounding metadata.

No. Your keychain stores the password for every Wi-Fi network you have ever joined, so you can read the password for a network you are nowhere near, while connected to a different one. You only need to have joined and saved it at some point on that Mac.

No. It only reads networks your own Mac has saved, unlocked by your own keychain authentication. It cannot read a network you have never joined or another user's keychain. It is the Terminal equivalent of the "Show Password" button in Keychain Access, which has always required your login password.

Sources

Authoritative references this article was fact-checked against.

TagsmacOSWi-Fi passwordsecurity commandkeychainTerminalCLI

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Capture the handshake or PMKID with hcxdumptool, convert with hcxpcapngtool, crack with hashcat -m 22000 and a wordlist, realistic expectations, and why WPA3 changes the game.

How to Crack a WPA/WPA2 Wi-Fi Password with Hashcat

How to recover your own WPA/WPA2 Wi-Fi password: capture the handshake or PMKID, convert it to the hashcat 22000 format, and crack it with a wordlist. I cover the full toolchain, realistic expectations for this slow hash, and why WPA3 resists the whole approach. Lab use only. Tested on hashcat 7.1.2.

Convert a PSD to PNG from the command line with ImageMagick using the [0] composite-layer trick, extract individual layers, batch a folder, and the Maximize Compatibility caveat.

How to Convert a PSD to PNG From the Command Line

Convert a PSD to PNG from the command line with ImageMagick. The one trick that matters: design.psd[0] selects the flattened composite, so you get one PNG instead of a folder full of separate layers.