MacOS – How to access the Wi-Fi password through Terminal

keychainmacosterminalwifi

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.

Best Answer

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

Replace $SSID with the SSID 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.