Score:0

Trying to enable Tor Package repository on Ubuntu 22.04 - permission denied error when adding gpg key

pa flag

I'm trying to enable the Tor Package Repository on my Ubuntu 22.04 following these steps: https://support.torproject.org/apt/tor-deb-repo/

Everything worked fine until step 3. When I run

wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null

I get a permission denied error:

tee: /usr/share/keyrings/tor-archive-keyring.gpg: Permission denied

My architecture is amd64, lsb_release -c gives Codename: jammy and cat /etc/debian_version gives bookworm/sid. In step 2 I tried filling in both jammy and bookworm/sid for <DISTRIBUTION>, but with both I get the same error in step 3. I did not try any experimental packages, neither did I add the lines for focal, as I'm not running on focal.

Can anyone help me fix this?

Thanks in advance!

Score:3
de flag

You need to be root to write to system directories. So you need to prepend sudo to the tee command or run the whole thing as root For example:

wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | sudo tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null
Score:2
cn flag

The tutorial you're working with assumes that your user has root privileges:

Note: The symbol # refers to running the code as root. This means you should have access to a user account with system administration privileges, e.g your user should be in the sudo group.

On Ubuntu, you mostly work with "normal", unprivileged accounts, and get additional privileges with sudo in case you need them. One of the things you need additional privileges for is to write outside of your $HOME directory (meaning outside for example /home/myusername/).

This is exactly what the third part of the pipeline in question tries to do. tee tries to create a file in /usr/share/keyrings/, where your "normal" user account has no business murking around ;) So, you need to get privileged for this part by prefixing sudo to this part of the pipeline:

wget -qO- ... | gpg --dearmor | sudo tee ... >/dev/null

Note: The pipeline above is shortened to better illustrate the idea.

The first and second parts of the pipeline, wget and pgp, can work without additional privileges, so you don't need sudo there.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.