Solved

gpg - failed to create temporary file

Posted on 2008-10-21
8
1,263 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
  • 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
 
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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 …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now