Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress the passphrase prompt in GPG command

Tags:

Edited Version

I have a question about GPG, but I write all of the process, maybe it will help someone.

I want to: Suppress the passphrase prompt in GPG command. I don't want to: use -c option (--symmetric).

I have 2 systems Linux and Windows. I want to send the data from Linux to Windows. I want to encrypt the data in Linux and decrypt in Windows.

  • myFileOnLinux.txt is a file on Linux that I want to encrypt.
  • [email protected] the UID of pair key.
  • myPasswordPhrase is the password phrase.

I installed GPG on both and did the steps:

  1. Generate a pair key in Windows:

    gpg --gen-key 
  2. Change the key parameter in Windows:

    gpg --edit-key [email protected] 
    trust 5 expire 0 
  3. Export the public keys:

    gpg -a --export [email protected] > public.key 
  4. Send the public key to the Linux machine.

  5. Import the public key in Linux.

    gpg --import public.key 
  6. Change the trust parameter in Linux

    gpg --edit-key [email protected] 
    trust 5 
  7. Encrypt a file in Linux

    gpg --output output.enc --encrypt --recipient [email protected] myFileOnLinux.txt 
  8. Send the encrypted file to Windows.

  9. Decrypt the file.

    gpg --batch --passphrase "myPasswordPhrase" -d -o test.dec output.enc 

In Windows with a popup window it asked me the Passphrase again. How can I avoid it?

like image 889
Malus Jan Avatar asked Mar 02 '18 15:03

Malus Jan


People also ask

What is passphrase in GPG?

You might forget your GPG private key's passphrase. You need your private key's passphrase in order to decrypt an encrypted message or document which is encrypted using your public key. So, if you lost or forgot it then you will not be able to decrypt the messages or documents sent to you.

Do you need a passphrase for GPG?

A good passphrase is absolutely critical when using GnuPG. Any attacker who gains access to your private key must bypass the encryption on the private key.


2 Answers

After a lot of digging I found this command which disables the entry prompt on windows(works also for *nix systems):

--pinentry-mode=loopback 

The full command would be:

gpg --pinentry-mode=loopback --passphrase  "PASSWORD" -d -o "PATH\TO\OUTPUT" "PATH\TO\FILE.gpg" 
like image 114
Marc Tifrea Avatar answered Sep 20 '22 08:09

Marc Tifrea


gpg --batch --import sec.key gpg -d --batch --passphrase mypassphrase encrypted_file.gpg 

the --batch flag supresses the passphrase prompt while importing keys as well as while decrypting the files.

like image 32
Jenison Gracious Avatar answered Sep 20 '22 08:09

Jenison Gracious