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

Jul 24, 2015 - 11 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 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:"
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"
attributes:
0x00000007 blob="YOUR-ROUTER-NAME"
0x00000008 blob=NULL
"acct"blob="YOUR-ROUTER-NAME"
"cdat"timedate=0x52192841772471472498124818A00 "20150723143649Z\000"
"crtr"uint32=NULL
"cusi"sint32=NULL
"desc"blob="AirPort network password"
"gena"blob=NULL
"icmt"blob=NULL
"invi"sint32=NULL
"mdat"timedate=0x52192841772471472498124818A00 "20150723143649Z\000"
"nega"sint32=NULL
"prot"blob=NULL
"scrp"sint32=NULL
"svce"blob="AirPort"
"type"uint32=NULL
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 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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X

11 Comments

» Comments RSS Feed

  1. 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!

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

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

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

  5. 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!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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