简体   繁体   中英

gpg commands to extract key information inside python script

I have a python script to check for gpg public key and gpg private keys expiration. So far I was managed to get the keys expiration information using gpg commands inside os.system('gpg...') commands.

This works fine for both public and private keys but when I run that python script from nrpe server the gpg command unable to get the private key information

Public key:

os.system('gpg -n key.gpg > key_info.txt')

Private key:

os.system('gpg --batch --import key.gpg > /dev/null 2>&1')
os.system('gpg --list-secret-keys > key_info.txt')

Is there any way to get the private key information using any other commands.

Also any way to use gnupg module to get the keys information, I see we can use gnup module only to do some operations such as encrypt/decrypt etc.

Finally I was able to run the script and get the private key information from another nrpe server using this gpg command

gpg -n --with-fingerprint --keyid-format=long --show-keys keys.gpg > keys_info.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM