Solved

gpg - failed to create temporary file

Posted on 2008-10-21
8
1,310 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

829 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