Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Situation: we plan on using PHP's GnuPG extension to encrypt/decrypt files.

Currently we've setup some test cases, using keys generated with GPG.

The generated files reside in:

/Users/username/.gnupg/

I am able to get keyinfo for the key I want to use to encrypt/decrypt, but when I attempt to use addencryptkey, I get:

(E_WARNING: 2): gnupg::addencryptkey() [gnupg.addencryptkey]: get_key failed

I think this is due to the permissions on the ~/.gnupg folder & enclosed files.

The files are owned by me - username, but apache runs as www.

A few days ago I did have this working, but it seems each time I use GPG Keychain Access to import / export a key, the folder's permissions are changed.

Question: What are the exact permissions required to allow PHP's GnuPG to add encrypt & decrypt keys?

share|improve this question

migrated from stackoverflow.com Jun 24 '11 at 12:40

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

Michael's '660' answer didn't do it for me. The only way I was able to have enough permissions without getting an "unsafe permissions" warning was to do 700. No more, no less.

Here are my commands (Ubuntu flavor)

sudo -i
cd /var/www/.gnupg
chown -R www-data:www-data .
chmod -R 700 .

Also, in my case, the problem was that gnupg_addencryptkey is meant to load key fingerprints that have already been imported. So, I used the gnupg_import function instead, according to the PHP documentation: http://php.net/manual/en/function.gnupg-import.php

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .