Why System keychain prompt is not displayed on macOS

Hello everyone from Go newbie.

I’m trying to make simple Go program that’d reveal the password of Wifi network user is connected to.

When I enter this command manually, through the terminal I got prompt that ask me for user credentials, and after I fill them password is displayed with few other infos.

security find-generic-password -D 'AirPort network password' -ga my_super_cool_ssid

However, when I try to execute this inside Go program keychain prompt isn’t displayed, and I just got weird stuff being displayed such as:

keychain: "/Users/bb/Library/Keychains/login.keychain-db"
version: 512
class: "genp"
attributes: ... ...

Here is the simple Go function that is responsible for this part

func getPassword(ssid string) {

  cmd := exec.Command("bash", "-c", "security find-generic-password", "-D", "'AirPort network password'", "-ga", ssid)

  cmd.Stdin = os.Stdin

  out, err := cmd.Output()

  if err != nil {

    log.Fatalf("cmd.Run() failed with %s\n", err)




Thanks in advance.


You have an error in your exec.Command “security find-generic-password” is two arguments and not one and also you don’t need to quote AirPort network password because then the quotes will be sent into the program. You can also call security directly without using bash. Like this:

cmd := exec.Command("/usr/bin/security", "find-generic-password", "-D", "AirPort network password", "-ga", ssid)

Hope this will help you :slight_smile:

1 Like

Thank you for help :slight_smile:

It almost works - keychain prompt is displayed, but after I enter credentials there are no WiFi network password printed out in terminal.

However, If I run this command manually form terminal, everything is same, except WiFi password is here, as It should be.

Any idea why this is happening ?

For some reason is the password outputed to stderr so you can use out, err := cmd.CombinedOutput() to get it.

1 Like

Thank you very much, that solved problem :slight_smile:


1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.