Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying to use /usr/bin/security rather than hard coding login/password information into scripts. For example, here's how you get the password for ''

security 2>&1 >/dev/null find-internet-password -gs |\
grep '^password: ' |\
sed 's#^password: "##g ; s#"$##'

(Note: Someone who is better at grep/awk can probably combine those last two lines, just be sure to consider for when a password may have a " in it — or a space.)

What I can't do is figure out how to retrieve the password for a Wi-Fi network if all I know is the SSID.

I have even tried specifying the kind of data I am looking for with -D:

security 2>&1 >/dev/null find-generic-password -D "AirPort network password" -s MySSIDhere

but all I get is this

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

All I have found via Google has been about adding SSID password information on the CLI, but I want to retrieve it.

share|improve this question
Are Wi-Fi passwords stored in the keychain? I don’t think so. – duci9y Sep 20 '12 at 17:05
Yes, they are... – Max Ried Sep 20 '12 at 17:41
You are not on Mountain Lion I assume, the sed doesn't work there anymore (at least not for Skype, different output format). To get rid of the grep use ... | sed '/^password: /s#^... – patrix Sep 20 '12 at 17:42

I got my password with

security find-generic-password -D "AirPort network password" -a YourSSIDhere -g

Main difference is -a SSID. I found that in which field it was stored by letting security take a dump:

security dump-keychain
share|improve this answer
That's not working for me. – TJ Luoma Sep 21 '12 at 17:29
@TJLuoma If you could add a little bit more details (what was the output of the command, did you run security dump-keychain first, etc.), someone may be able to help you. – Percival Ulysses Sep 21 '12 at 20:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.