44

System: I am testing Linux Mint 19 Beta based on Ubuntu 18.04.

I got this warning while installing an unrelated package:

gpg: WARNING: unsafe ownership on homedir '/home/vlastimil/.gnupg'

This is the ls output the of the directory itself:

$ lld /home/vlastimil/.gnupg

drwx------ 4 vlastimil vlastimil 4,0K Jun 26 11:42 /home/vlastimil/.gnupg

That seems to be OK.

This is the ls output the contents of the directory:

$ ll /home/vlastimil/.gnupg/

total 24K
drwx------ 2 vlastimil vlastimil 4,0K Jun 26 11:36 crls.d
drwx------ 2 vlastimil vlastimil 4,0K Jun 26 05:28 private-keys-v1.d
-rw-r--r-- 1 vlastimil vlastimil 6,4K Jun 26 11:42 pubring.kbx
-rw-r--r-- 1 vlastimil vlastimil 3,2K Jun 26 11:37 pubring.kbx~
srwx------ 1 root      root         0 Jun 26 11:38 S.dirmngr
-rw------- 1 vlastimil vlastimil 1,2K Jun 26 11:37 trustdb.gpg

I am unsure if I can't just delete the seemingly offending directory named S.dirmngr.

I am also unsure if that would solve the issue or create another one.

I just remember that not long ago, I was instructed to install a package named like that, i.e. dirmngr, but I can't remember with what software installation it was connected.

EDIT1:

As StephenKitt pointed out, I really ran this line, I have found in the history:

sudo gpg --recv-keys ...

Will this have any consequences?

3
  • 4
    Was this after installing VS Code by chance?
    – Beltalowda
    May 7, 2019 at 4:15
  • 4
    @ThuggishNuggets I just encountered this warning, and this post, after installing VS Code.
    – aisflat439
    Aug 14, 2019 at 14:17
  • 3
    @aisflat439 Mark Hudson’s answer fixed this for me when I encountered it after installing VS Code on Ubuntu Mate 18.04 LTS
    – Beltalowda
    Aug 14, 2019 at 18:15

1 Answer 1

49

This is the result of running gpg with sudo: gpg then runs as root, but its home directory is still the user’s. This explains both the warning (gpg is running as root but another user owns the configuration directory) and dirmngr’s socket’s ownership.

To fix this up, you should stop dirmngr:

sudo gpgconf --kill dirmngr

(sudo just this once because dirmngr is running as root, as evidenced by its socket), then restore your ownership:

sudo chown -R $USER ~/.gnupg
4
  • Should I restore the killed process somehow? How do I go about doing that? Also, how do I sudo gpg without causing this problem in the first place? Apr 20, 2021 at 10:13
  • 3
    @leinaD you can’t restore a killed process. To run gpg as root without causing this problem, use sudo -H: sudo -H gpg. Apr 20, 2021 at 11:54
  • @StephenKitt After looking at the docs, what i was looking for is --launch, I guess, but really I meant to ask if doing something along the lines of gpgconf --launch dirmngr was necessary after killing it in the first place. Apr 20, 2021 at 14:49
  • 1
    @leinaD ah, right, gpg should launch dirmngr on its own if necessary. Apr 20, 2021 at 18:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.