How to access the Wi-Fi password through Terminal?

I am at my school and the computer I am currently using is connected to a Wi-Fi network. I want to know the Wi-Fi password and I am on a Mac. I know there is a way to do it through Terminal.

What I am using is:

security find-generic-password -ga  AirPort

I use that to find the password if it is in a keychain, but I know there is another way to do it. My friend who is a coder told me their is but they said they wont help me. All they told me was "generic" was a hint. I used "generic" in my command but I don't get it.

I tried your answer but it keeps asking my for the admin password. I am connected to the wifi but it still wont work. My coding friend looked at this and said I'm not looking for a AirPort password I'm looking for a regular password.


security find-generic-password -D "AirPort network password" -a $SSID -g | grep "password:"

Replace $SSID with the SSID (the network name) of the network that you wish to obtain the key of.
This command looks for all keys with a type of "AirPort network password" and searches for the key with the name of the SSID that you provide.


I think what you're actually looking for is this:

security find-generic-password -ga "ROUTERNAME" | grep "password:"

You'll get in response something like:

password: "ThePassword"

You can also use the flag -w to show only the raw password and avoid any extra grep, like so:

security find-generic-password -wga "ROUTERNAME"

Which in the above example would simply return:

ThePassword

Hope this helps!


I'm not sure what version of OS X the other answer or original question is for but it's not accurate on 10.10 Mavericks. You need this:

security find-generic-password -D "802.1X Password"

Maybe networks using actual Apple AirPort hardware are saved in the keychain Differently?


  1. get the SSID of current wireless network (use --getinfo)

    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
    
         agrCtlRSSI: -51
         agrExtRSSI: 0
        agrCtlNoise: -93
        agrExtNoise: 0
              state: running
            op mode: station 
         lastTxRate: 130
            maxRate: 217
    lastAssocStatus: 0
        802.11 auth: open
          link auth: wpa2-psk
              BSSID: 0:31:c2:41:53:14
               SSID: DansLeVille
                MCS: 15
            channel: 5
    

    But if you want to get all wifis in your area, (use --scan)

    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
                                SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                      America_Online 00:71:c2:9a:11:b0 -86  1       Y  US WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP) 
                         xfinitywifi 00:71:c2:9a:11:b2 -72  1       Y  US NONE
                         xfinitywifi 84:00:2d:78:ee:ea -56  11      Y  US NONE
                               amber 74:1b:b2:d5:93:a9 -53  104     Y  US WPA2(PSK/AES/AES) 
                         xfinitywifi 74:85:2a:a9:f3:4a -66  11      Y  US NONE
                       HOME-1A17-2.4 74:85:2a:a9:f3:48 -66  11      Y  US WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP) 
              Cooper Works Streaming 90:a7:c1:b9:6c:37 -50  11,-1   Y  -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP) 
                               amber 74:1b:b2:d5:93:a8 -49  11      Y  US WPA2(PSK/AES/AES) 
    
    1. get the password for wireless

      sudo security find-generic-password -D "AirPort network password" -a YOUR_SSID_NAME -g | grep password:
      password: "pseudononymous1234!!!"
      

    You see the password: at the end.