Linux Encrypt Files/Decrypt Files – GPG Interactive/Non Interactive Modes - Comment Page: 1

GNU Privacy Guard (GnuPG or GPG) is a free software alternative to the PGP suite of cryptographic software. This is quick guide, howto Encrypt and Decrypt files on Linux with password using GPG. This guide deals with both the interactive mode and the non interactive mode. Interactive mode is useful when the purpose is encrypt some files on the command line. Non interactive mode is useful when the purpose is encrypt files using scripts. This guide also deals with single file encryption/decryption and multiple files encryption/decryption simultaneously. Linux Encrypt/Decrypt File on Linux using GPG Encrypt File on Linux using GPG Interactive Mode gpg -c filename.txt ## OR...

8 comments on “Linux Encrypt Files/Decrypt Files – GPG Interactive/Non Interactive Modes - Comment Page: 1

    1. gpg –yes –passphrase=$PASSPHRASE -c $OUTPUT_FILE
      does still want manual passphrase.
      Use
      gpg –yes –batch –passphrase $PASSPHRASE -c $OUTPUT_FILE
      instead. Look into the man pages for further details.

      Reply
      • Hi,

        Thanks for this information.

        This is interesting, just tried this on Fedora and it works without –batch, but to make this work on all systems, I added –batch to this guide. Thanks!

        Reply
    2. I have run into problems using the above methods due to many distributions wrapping the GPG with a more secure password prompt (FreeBSD & Gentoo Linux both compile GPG with the pinentry package as a requirement).

      This has served me well in these cases…

      read -sp "Enter passphrase: " pass
      echo "${pass}" | gpg --yes --no-tty --batch --passphrase-fd 0 -o /path/to/cipher/file.ext.gpg /path/to/plaintext/file.ext

      Or to decrypt…
      read -sp "Enter passphrase: " pass
      echo "${pass}" | gpg --yes --no-tty --batch --passphrase-fd 0 -o /path/to/decrypted/file.ext /path/to/encrypted/file.ext.gpg

      Hope that helps some others that run into this

      Reply
      • Interesting, thanks for sharing jas.

        Reply
    3. The Non Interactive Mode doesn’t work in Ubuntu

      Reply
    4. A most useful page, thanks !

      Reply
      • Also worth noting : the suggestion above to use “–passphrase-fd 0” is a good one, since it prevents the passphrase being visible if someone else on the host runs “ps” to list the processes.

        Reply
    5. Actually, to make that true, run via open2 / open3 in perl, so you can write to the command’s STDIN

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close