title: How can I run `gpg` as non-root user, from a Chef cookbook?
body: <p>I need to import via Chef [client, 13], a public key in all the users of a [Ubuntu 14.04] system.</p>
  
  <p>I'm finding, though, very strange ownership behaviors, and I can't figure out how to solve them; the following is a list of what happens with different approaches (all the snippets are blocks inside a <code>bash</code> resource`.</p>
  
  <p>1.This will execute gpg as <code>&lt;login&gt;</code>, but will try to write to /root/.gnupg:</p>
  
  <pre><code>code "gpg --import &lt;&lt; PUBKEY..."
  user login
  </code></pre>
  
  <p>2.This will (sometimes) create <code>/home/&lt;login&gt;/.gnupg</code> with  owner, then will create inside it the data files with root owner, then will try to write to them as <code>&lt;login&gt;</code>:</p>
  
  <pre><code>code "sudo -iu #{login} gpg --import &lt;&lt; PUBKEY..."
  </code></pre>
  
  <p>3.Executing #2 manually via terminal works as expected</p>