4

I am trying to install Tor Browser following this guide:

https://2019.www.torproject.org/docs/debian.html.en on Ubuntu 18.04.3 TLS.

When running the following command:

gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -

I get the error message below:

E: This command can only be used by root.

When I run the same command using sudo, I get the following message:

gpg: WARNING: unsafe ownership on homedir '/home/user/.gnupg'
E: This command can only be used by root.

Does anyone know how to fix it and why it is happening?

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84

1 Answers1

6

How exactly did you try to use it with sudo?

My guess is:

sudo gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -

If so, gpg will run as root, and apt-key will run as your normal user.

In this particular case you should add sudo infront of apt-key:

gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -

Since you ran gpg with sudo and not using the -H flag the permissions on ~/.gnupg probably changed.

From man sudo:

-H' The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.

To check permissions and ownership:

ls -l ~/.gnupg

If the directory (.) or any files in the directory is owned by root, fix the permissions with:

sudo chown -R $USER:$USER ~/.gnupg
sudo find ~/.gnupg -type d -exec chmod 700 {} \;
sudo find ~/.gnupg -type f -exec chmod 600 {} \;
mgor
  • 1,231