Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GnuPG Shell Script - Refuses to read password

The script below used to work on Mac OS X, but, since moving it to Ubuntu, it doesn't seem to read from the password file at all. Even when I run it from the command line, no matter what I do, I get a popup prompt asking me for the password. As this will run via cron, I don't want this to happen... I want it to read the password from the file with no prompt. To note, I did try using passphrase-fd and passphrase-file, neither of which worked...

#!/bin/sh
p=$(<pass.txt)
set -- $p
pass_phrase=$1
destination="/var/www/decrypted"
cd /var/sl_bin/
for FILE in *.pgp;
do
    FILENAME=${FILE%.pgp}
    gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE"
    rm -f $FILE
done
like image 450
OopsForgotMyOtherUserName Avatar asked Mar 27 '10 18:03

OopsForgotMyOtherUserName


People also ask

Why does gpg not ask for passphrase?

gpg caches the passphrase used for symmetric encryption so that a decrypt operation may not require that the user needs to enter the passphrase.

How do I use gpg passphrase?

Open the terminal application. Get a list of GPG keys by running the gpg --list-keys command. Run gpg --edit-key your-key-id command. At the gpg> prompt enter the passwd to change the passphrase.

How can I know my gpg password?

For me the simplistic way to check the passphrase is to use gpg --passwd shorthand. It tries to change the passphrase and the step is to confirm the old passphrase, and then you can click 'cancel' on the new passphrase prompt and this keeps the passphrase intact. which is even better.


2 Answers

This works:

gpg --no-use-agent --batch --passphrase-file pass.txt --output kkkk.tar.bz2  --decrypt kkk-data.tar.bz2.gpg
like image 179
jiangjianbo Avatar answered Oct 03 '22 07:10

jiangjianbo


The --passphrase-file option seems to be broken / not honored. I had to use --passphrase-fd 0 instead, like so:

cat .password | gpg --passphrase-fd 0 --output foo --decrypt foo.gpg
like image 45
bukzor Avatar answered Oct 03 '22 07:10

bukzor