How can I retrieve my NAS password from Keychain using the terminal? Using security I can retrieve both application and internet passwords, but I've been unsuccessful for those where kind is set to network password.

Using the -D flag of find-generic-password doesn't do the trick.

1 Answer 1


After searching, it seems the case is important for the kind. The following worked for me with the following keychain config:

security find-internet-password -D "Network Password" -l "the_share" -w

enter image description here

Of course you can filter a bit more by indicating more element to your research

security find-internet-password -h
Usage: find-internet-password [-a account] [-s server] [options...] [-g] [keychain...]
    -a  Match "account" string
    -c  Match "creator" (four-character code)
    -C  Match "type" (four-character code)
    -d  Match "securityDomain" string
    -D  Match "kind" string
    -j  Match "comment" string
    -l  Match "label" string
    -p  Match "path" string
    -P  Match port number
    -r  Match "protocol" (four-character code)
    -s  Match "server" string
    -t  Match "authenticationType" (four-character code)
    -g  Display the password for the item found
    -w  Display only the password on stdout
If no keychains are specified to search, the default search list is used.
        Find an internet password item.

With the above results here's what are the fields (replace -w by -g)

security find-internet-password -D "Network Password" -l "the_share" -g
keychain: "/Users/bric3/Library/Keychains/login.keychain-db"
version: 512
class: "inet"
    0x00000007 <blob>="the_share"
    0x00000008 <blob>=<NULL>
    "cdat"<timedate>=0x32303139313233303133323534345A00  "20191230132544Z\000"
    "desc"<blob>="Network Password"
    "mdat"<timedate>=0x32303139313233303133323534345A00  "20191230132544Z\000"
    "ptcl"<uint32>="afp "
password: "the password"

E.g. specifying the protocol using -r "smb " will not result in any result for me as it is an afp share, but using -r "afp " will, for this particular (Note that the extra space is mandatory for this particular criteria to work). But it's also possible to search for the account using -a the_user. But for this password specifying other fields (as they are NULL) will not return anything.

macOs 10.15.2

You must log in to answer this question.