How to Find Wi-Fi Network Passwords from Command Line on Mac
Given the complexity of some wi-fi network passwords combined with the general infrequency of entering them and that they’re typically saved on use, it’s not terribly unusual to forget what a specific routers wireless password is. Fortunately, if you’re on a Mac, there are a few ways to go about finding those lost or forgotten wi-fi router login details.
Perhaps the easiest method is recovering forgotten wireless passwords with KeyChain Access in OS X, but if you’re an advanced Mac user you may wish to retrieve the same data from the command line, and that’s what we’re going to demonstrate here.
Find & Show Wi-Fi Network Passwords from the Command Line in OS X
To get started with this trick, open the Terminal app from /Applications/Utilities/, then use the following command syntax to find and display the password for a specific wireless network:
security find-generic-password -ga "ROUTERNAME" | grep "password:"
Replace “ROUTERNAME” with the exact name of the wireless router you want to retrieve the password for. You do not need to be connected to that network to recover the password for that network, you only need to have joined it once, and saved the password for it when you connected at that time.
For example, let’s say the wireless router name is “YOUR-ROUTER”, the command would look like the following:
security find-generic-password -ga "YOUR-ROUTER" |grep "password:"
Hitting return and running that command string will request an administrator login (or you can prefix with sudo), which will then return the password for the given router, looking like the following:
$ security find-generic-password -ga "YOUR-ROUTER" |grep "password:"
In this example, the password for ‘YOUR-ROUTER” is “osxdailysecretpassword”, minus the quotations.
This command can be particularly helpful if you combine it with the ability to list all wireless networks a Mac has connected to before, particularly if you can’t remember the exact name or spelling of a specific router.
You can also leave off the pipe to grep, which will report back additional details about the queried router, most of the added data reported isn’t particularly useful though, thus why we’re cleaning up the output and shortening it with grep. For those curious, the command return without the grep pipe would look something like the following:
$ security find-generic-password -ga "YOUR-ROUTER-NAME"
"desc"blob="AirPort network password"
In this case, the wi-fi password for ‘Your-Router-Name’ with ‘password: “osxdaily”‘ is at the very bottom of the returned command.
As mentioned already, you can find the same wi-fi login details from KeyChain Access tool in OS X, and you don’t even need to be connected to the wi-fi network you are retrieving the password for, which is extremely helpful for those times you get a phone call from a friend or family member asking “hey what’s the password for the router at so-and-so house” (maybe I’m the only one who gets those calls). Whether you go the command line route as described here, which is ultimately just a terminal approach to the keychain anyway, or through the more user friendly KeyChain Access application, is up to you.
Thanks to LifeHacker for pointing out this great trick, we cleaned it up a bit with grep but for PC users, Lifehacker goes further to demonstrate how to perform the same wi-fi router password finding from a Windows PC too, which could be undoubtedly helpful to many users, based primarily on Macs or otherwise.