You are not logged in.

#1 2015-10-13 19:13:47

cribbageSTARSHIP
Member
Registered: 2015-07-31
Posts: 21

GnuPG not working within a script

Good day,

I have a scripte that I'm working on that will rsync a bunch of files and dirs into a temp folder. Then it is supposed to tar the temp dir, encrypt it using gpg, and copy it to my dropbox before erasing all the temp material.

The script hits an error at the gpg portion. If I type "gpg --encrypt --recipient USER /path/to/my/dir.tar.gz" into the terminal it works. However, inside the script it returns:

gpg: USER: skipped: No public key
gpg: /path/to/my/dir.tar.gz: encryption failed: No public key

I've even tried setting "gpg --encrypt --recipient USER /path/to/my/dir.tar.gz" as a bash alias, which will work alone in the terminal but in the script is comes back as command unknown.

Is this a problem as a result of this script being run outside of the scope of where the public key is? I know where the public key is stored on in my system.

Offline

#2 2015-10-13 19:35:06

mpan
Member
Registered: 2012-08-01
Posts: 1,206
Website

Re: GnuPG not working within a script

Are you using the same user for both tests? I mean: terminal and script? Keep in mind that GnuPG keyring is per–user.

Unrelated to your problem: it's worth signing (--sign) the package too.


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#3 2015-10-13 20:51:11

cribbageSTARSHIP
Member
Registered: 2015-07-31
Posts: 21

Re: GnuPG not working within a script

Yes I am using the same user. Why is signing an issue?

Thanks for answering

Offline

#4 2015-10-13 22:06:06

mpan
Member
Registered: 2012-08-01
Posts: 1,206
Website

Re: GnuPG not working within a script

cribbageSTARSHIP wrote:

Yes I am using the same user.

What happens when you call gpg2 --list-keys from within the script? Does it print the proper location of the keyring (should be at the top)? Does gpg2 --list-keys YOUR_KEY list your key?

cribbageSTARSHIP wrote:

Why is signing an issue?

You're sending data via untrusted medium. Encryption protects data from being read, not from being written. The latter is covered by signing, so you should also sign the package, not only encrypt it. Until you don't care about the adversary modifying contents, of course, but this is a rare case for filesets.


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#5 2015-10-14 01:53:06

cribbageSTARSHIP
Member
Registered: 2015-07-31
Posts: 21

Re: GnuPG not working within a script

Thank you for clarifying the singing issue, I'll look into that afterwards.

As for gpg2 --list-keys, they are listed when I input the command into the terminal, but when inserted into my script nothing shows up. Should it?

Offline

#6 2015-10-14 11:18:17

mpan
Member
Registered: 2012-08-01
Posts: 1,206
Website

Re: GnuPG not working within a script

IMHO it should show the key the same way as it shows it in the terminal. And it does for me.

Does --batch option change anything? Shouldn't, but maybe an attempt to read something is the issue. Does using --debug-level or --debug-all provide any useful information?


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#7 2015-10-14 14:20:54

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,772

Re: GnuPG not working within a script

How are you starting this script?  From the command line of your shell, or is it bound to a key or started from a menu someplace?
What shell do you use for your CLI?
Do you have a crunch-bang on the first line of the script that identifies which shell to use for the script:  Something like:

#! /usr/bin/bash

I am wondering if the script is not finding itself in the same environment as your cli shell.   In other words, are your shell and your script sourcing the same configuration?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2015-10-14 22:15:52

mpan
Member
Registered: 2012-08-01
Posts: 1,206
Website

Re: GnuPG not working within a script

cribbageSTARSHIP:
One more question: are you sure that the user id is valid? Since you're using it within a script, I suspect that maybe you're performing some operations on it. Possibly GnuPG receives some other parameter for --recipient than expected. Or maybe spaces in an unquoted argument? Anything like that?

*:
By the way:

#!/usr/bin/env bash

instead of

#!/usr/bin/bash

Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

Board footer

Powered by FluxBB