Search code examples
gnupg

How to send the password automatically in gpg's symmetric encryption?


I want to make a symmetric encryption for the file /tmp/public.txt. To do this I can use gpg as following:

gpg --symmetric /tmp/public.txt

The command will invoke the enter passphrase window, but I would like to send the password automatically.

enter image description here

I have tried with:

echo "mylongpasswordhere"  | gpg --passphrase-fd 0   --symmetric /tmp/public.txt

but the Enter passphrase window still pop up.

How to send the password automatically in gpg's symmetric encryption?


Solution

  • Depending on your GnuPG version (>= 2.1.0 ) you need to add "--pinentry-mode loopback" to the command.

    For GnuPG version >= 2.1.0 but < 2.1.12 you also need to add: "allow-loopback-pinentry" to the ~/.gnupg/gpg-agent.conf

    Your command would then be:

    echo "mylongpasswordhere"  | gpg --pinentry-mode loopback --passphrase-fd 0   --symmetric /tmp/public.txt
    

    Alternatively you don't have to use passphrase-fd and the echo but can directly provide the passphrase:

    gpg --pinentry-mode loopback --passphrase "somepass" --symmetric /tmp/public.txt