Quit gracefully on wrong password

Marco msteel00 at proton.me
Tue Oct 10 09:47:49 CEST 2023

I'm using GPG to decrypt an encrypted file. The command I'm using is the following:

$ gpg -a --decrypt --no-symkey-cache --batch --passphrase "correct_pw" --output file.txt file.txt.enc

This works fine when the password is correct. When I try using an incorrect password, however, gpg leaves me in a prompt waiting for further commands:

$ gpg -a --decrypt --no-symkey-cache --batch --passphrase "incorrect_pw" --output file.txt file.txt.enc
gpg: AES256.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key
gpg: signal Interrupt caught ... exiting

where I have to manually interrupt the process using ctrl + c.

So my question is: is there a way to just quit the program when the password is incorrect? I need to use this command inside a script which is supposed to be running in background, this behaviour would break the entire pipeline.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20231010/d50646d7/attachment.html>

More information about the Gnupg-users mailing list