How to Find Wi-Fi Network Passwords from Command Line on Mac

Jul 24, 2015 - 12 Comments

Find a wi-fi network router password from Mac command line

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 Mac 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.

You will need to know the router name of the wi-fi router password you wish to retrieve. The rest is pretty straight forward.

Find & Show Wi-Fi Network Passwords from the Command Line in Mac 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:"
password: "osxdailysecretpassword"

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"
keychain: "/Library/Keychains/System.keychain"
class: "genp"
0x00000007 blob="YOUR-ROUTER-NAME"
0x00000008 blob=NULL
"cdat"timedate=0x52192841772471472498124818A00 "20150723143649Z\000"
"desc"blob="AirPort network password"
"mdat"timedate=0x52192841772471472498124818A00 "20150723143649Z\000"
password: "osxdaily"

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 Mac 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.

If you’re a command line user, this should be handy for you to identify wi-fi passwords rather quickly. Let us know if you know of another method as well.


Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS


» Comments RSS Feed

  1. I says:

    Worked great for me!! Thanks!

  2. James says:

    how odd… trying to troubleshoot my sister’s computer, she has lost her wifi password. it doesn’t show up at all in keychain, which i cannot explain…. so i tried this after testing it on my mac, where it worked. on my sister’s mac all we get is “> ” after hitting enter. any ideas? i see someone has commented with a slightly different command, we’ll try that next. thanks, great article!

  3. Pluto Nium says:

    So if ever I give a Mac user “temporary” access to my network, I need to then change my network password lest they recover it from their mac.

    How monumentally broken is wireless security.

  4. Wharf Xanadu says:

    Works for me in OS X el captain Works quite well I am making a text file of the passwords now. Lol. Security.

  5. Anwar says:

    It doesn’t work for me. It gives an error –

    security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

    • Jeff says:

      I have the same problem, works if I use the Network name but not the Base Station (router) name.

    • julian jordan says:

      Did you ever figure it out? I am triying to get my school’s wifi password. they said it was for us but they changed their mind and put a password on it. & it dont come out on keychain

      • Damon Schultz says:

        If you use the wifi network’s SSID then this tip should work. Just remember to use the SSID, not the name of the router as was implied.

  6. Damon Schultz says:

    No need for the pipe to grep, use the -w switch instead of -g:

    $ security find-generic-password -wa “YOUR-ROUTER-NAME”

    From man security(1):

    -w Display the password(only) for the item found

    Works for me on 10.10.4

    • Paul says:

      Brilliant, thanks for finding a simpler version!

      • Brian says:

        You can also find wi-fi passwords stored on iPhone or iPad if you have the device jb’d by using the Cydia package called “WiFi Passwords”. Hopefully this feature will come native to iOS, it would be handy!

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site