Solved

gpg - failed to create temporary file

Posted on 2008-10-21
8
1,367 Views
Last Modified: 2012-08-13
I have written a Perl script on CentOS 4.4 to read the contents of a directory and then encrypt the files using gpg.  the command is:

gpg -r 'username' --batch --encrypt-files 'filename.ext'

I created the script as root.  When I run it interactively from the console, it works just fine.  However, if I try to run it from cron or start it from another process (running as root), I receive the following error:

gpg: failed to create temporary file `~/.gnupg/.#lk0x9804868.xxxxxxxxx.31811': No such file or directory
gpg: fatal: ~/.gnupg: can't create directory: No such file or directory

I've echoed the tilde (~) from within the script and it translates to "/root".  The directory "/root/.gnupg" does exist and has proper owner permissions.  

Any ideas would be appreciated.  Thanks.
0
Comment
Question by:asrobins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 22771763
So your perl script does:
    system("gpg -r 'username' --batch --encrypt-files 'filename.ext'");

0
 
LVL 1

Author Comment

by:asrobins
ID: 22775966
Yes, that it correct.  It works fine from the console as root, but not from cron as root.  I've tried changing the permissions on the /root/.gnupg directory to 777, but it still does not work.  That leads me to believe that it is not trying to place the file there, but somewhere else.  I see nothing in the conf file that would let me change the location of temp files.  Thanks.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22776812
Is gpg something you created?  Is it a shell script?

When you echo ~ in the script, you mean in the gpg script, not your perl script?
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 1

Author Comment

by:asrobins
ID: 22776886
no, gpg is the linux command to run gnupg, the encryption program.  It came with the CentOS distribution.
/usr/bin/gpg is an executable.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22785627
Is your perl script setuid to make it run as root, or are you actually logging in as root?
0
 
LVL 1

Author Comment

by:asrobins
ID: 22785647
I am actually logged in as root
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22791313
Does the perl script change the environment at all before calling system to start gpg?
0
 
LVL 1

Accepted Solution

by:
asrobins earned 0 total points
ID: 22814736
Problem has been independently resolved.

Solution was to add parameter:  --homedir '/root/.gnupg' to the gpg command line.

Thanks for trying.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Ransomware is a growing menace to anyone using a computer or mobile device. Here are answers to some common questions about this vicious new form of malware.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Six Sigma Control Plans

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question