This is working in macOS < 10.13
via command line:
$ security find-generic-password -s "SSH" -a "/Users/<user>/.ssh/id_rsa"
Or using this go snippet (using https://github.com/keybase/go-keychain):
usr, _ := user.Current()
dir := usr.HomeDir
keyPath, err := filepath.Abs(filepath.Join(dir, ".ssh/id_rsa"))
if err != nil {
log.Fatal(err)
}
keyPassword, err := GetGenericPassword("SSH", keyPath, "", "")
if err != nil {
log.Fatal(err)
}
fmt.Printf("keyPassword = %s
", keyPassword)
In macOS High Sierra this has been changed, doesn't work via command line also can't make it to work trying this:
keyPassword, err := keychain.GetGenericPassword("OpenSSH", keyPath, "SSH: "+keyPath, "com.apple.ssh.passphrases")
if err != nil {
log.Fatal(err)
}
fmt.Printf("keyPassword = %s
", keyPassword)
I fund this post, could be related: https://apple.stackexchange.com/a/268175/104123.
Any ideas if this is possible in latest macOs versions?