Syntax Question on GPG2 on LINUX

Steve Butler sbutler at
Thu Oct 6 22:19:43 CEST 2016


I don't use modern but I do have a script for classic that works in unattended mode on a Linux box.  The caller knows the input file name and the script knows my passphrase -- default gpg_pass2.  Hope this helps with gpg2! --Steve

$ cat gpg_encrypt
usage="gpg_encrypt [ -a -b -e ext -n -s ] PK_ID source"
#   Interface script for edi and ftpexec to encrypt files vi GnuPG
#   -a  Use Ascii Armor (--armor switch)
#   -b  Use binary (e.g. opposite of -a)
#   -e  Use ext as value of file extension (defaults to pgp when not specified)
#   -n  Do not sign (e.g. opposite of -s)
#   -s  Sign using key for helpdesk at as signing key
# For conflicting options, the last one entered takes precedence.
#   PK_ID  Key ID to which the file is to be encrypted.
#   source Source file name to encrypt.
# Encryptes to a file of source.ext and name is echoed to stdlist

homedir=$($xrgbin/default gpg_home)


while getopts ":abe:ns" opt
  case $opt in
    a) ARMOR="--armor" ;;
    b) ARMOR="" ;;
    e) EXT=$OPTARG ;;
    n) SIGN="" ;;
    s) SIGN="--sign" ;;
    *) echo $usage
       exit 2

shift $(($OPTIND - 1))

if [[ $# -ne 2 ]]; then
  echo "gpg_encrypt:  Must supply 2 parameters" >&2
  echo " usage: $usage" >&2
  exit 99

rm -f "$2.$EXT" > /dev/null

if [[ -z $SIGN ]]; then
  gpg --batch --homedir $homedir --quiet --no-tty --always-trust $ARMOR \
      --no-permission-warning --recipient $1 --output "$2.$EXT" --encrypt "$2"
  $xrgbin/default gpg_pass2  | gpg \
     --batch --homedir $homedir --quiet --no-tty --always-trust $ARMOR \
      --sign --passphrase-fd 0 --default-key helpdesk at \
      --no-permission-warning --recipient $1 --output "$2.$EXT" --encrypt "$2"

if [ $x -ne 0 ]; then
  echo "gpg_encrypt: gpg failure code '$x'" >&2
echo "$2.$EXT"
exit $x

From: Gnupg-users [mailto:gnupg-users-bounces at] On Behalf Of Jim Ernst
Sent: Thursday, October 06, 2016 5:39 AM
To: gnupg-users at
Subject: Syntax Question on GPG2 on LINUX

Hello All -

I am working in a LINUX environment using GPG version 2.1.15

Can anyone give me the syntax to use gpg2  to create a signed, encrypted file using a passphrase in a LINUX shell script ?  This is being run from Oracle EBS on a schedule so there would not be a user interacting to answer prompts. With this mode, is there any terminal settings I would need to set ?

Thanks !!
Jim Ernst
NTT Data
NOTE: The sender of this email is an independent contractor of Invacare Corporation or one of its subsidiaries. CONFIDENTIALITY NOTICE: The information in this e-mail message and any attachments may contain privileged, confidential or proprietary information, including confidential health information, protected by applicable Federal or state laws. Such information is intended only for the recipient named above. If you are not the intended recipient, please notify the sender immediately, and take notice that any use, disclosure or distribution of such information is prohibited by law.

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, 
is for the sole use of the intended recipient(s) and may contain 
and privileged information. Any unauthorized review, use, disclosure or 
distribution is prohibited. If you are not the intended recipient, please 
contact the sender by reply e-mail and destroy all copies of the original 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20161006/705da483/attachment-0001.html>

More information about the Gnupg-users mailing list