How to Automate gpg?

6,188

If you pull up gpg's man page, you'll see that there are helpful command-line options:

--passphrase-file file reads the passphrase from a file

--passphrase string uses string as the passphrase

You'll also want to add --batch, which prevents gpg from using interactive commands, and --no-tty, which makes sure that the terminal isn't used for any output.

Please keep in mind that using these options is a security risk. If the passphrase is in a file, then a hacker could get to it. If the passphrase is being supplied to a script, then there are ways a hacker could intercept it. So please study the security implications, and don't use these options lightly.

Share:
6,188

Related videos on Youtube

Tom meteor
Author by

Tom meteor

Updated on September 18, 2022

Comments

  • Tom meteor
    Tom meteor over 1 year

    I am using gpg in the Bash shell on Ubuntu 14.04. I am trying to automate the password input when encrypting and decrypting large chunks of files. I have a long string of

    gpg -c Filename.doc 
    

    but for every one of those lines I am prompted for a password. How do I solve this (in simple terms please)?

  • Tom meteor
    Tom meteor over 7 years
    Ok, I ran a line to test it and I was given the message "usage: gpg options --symetric [filename]" My line was as follows, what have I done wrong? gpg filename.doc.gpg --passphrase string
  • rclocher3
    rclocher3 over 7 years
    You'll need to learn how to use the documentation to get along on the Linux command line. Use man gpg for the complete version, which can be long and hard to read, or use a search engine to find one of the many web pages with cheat-sheet-style documentation. You need something like gpg --output filename.doc --decrypt filename.doc.gpg --passphrase "string" --batch --no-tty, where "string" is your passphrase. Leave the quotes in, in case you have spaces or special characters in your passphrase.