Score:0

torsocks in .bashrc breaks Tor Browser

bd flag

I activate torsocks in my .bashrc, so that every command I run by default gets routed through tor:

# ~/.bashrc: executed by bash(1) for non-login shells.
# ...
. torsocks on

This works fine, except that it causes the Tor Browser not to be able to connect to the Tor network anymore -- I now get the following error in the logs:

<Some timestamp> [WARN] Proxy Client: unable to connect OR connection (handshaking (proxy)) with <Some IP>:443 ID=<Some ID> RSA_ID=<Some ID> ("Connection refused")

If I remove the line from my .bashrc it works fine. I already tried opening a terminal, deactivating torsocks with . torsocks off and running the Tor Browser from there (either through the torbrowser-launcher, or directly by calling the executable), which didn't change anything.

Is there a way to have torsocks active in the terminal by default, while still being able to use the Tor Browser?

My torbrowser-launcher has the version 0.3.3-6, torsocks has 2.3.0-3, I use Debian GNU/Linux 11 (bullseye) x86_64 with the Kernel 5.10.0-23-amd64.

waltinator avatar
it flag
Your `~/.bashrc` is invoked whenever you start `bash`, not just at `login`. Read `man bash`, about `INVOCATION`.
Terrance avatar
id flag
Once you close your bash terminal, the running of torsocks will close since it was started when the terminal was opened and launched the shell at that time. Probably best if you add it as a crontab with something that calls it like `@reboot . /path/to/torsocks on` since crontab is not shell specific.
MetaColon avatar
bd flag
@waltinator I know how the `.bashrc` works, that wasn't the question. @Terrance thanks! However, isn't torsocks activated / deactivated "per shell"? To demonstrate, if I open two terminals, run `. torsocks on` in one, the commands of the one terminal are routed through Tor but the ones of the other aren't (validated with `rm index.html && wget check.torproject.org && head index.html`). So a Crontab wouldn't work, because it would only activate torsocks in the shell the crontab was executed in? Also, how would I then deactivate torsocks for Tor browser, so that it can connect itself?
Terrance avatar
id flag
Crontab is not bound to a shell. It is the script that can be tied to a shell. `.bashrc` is only launched when you open your terminal if your terminal defaults to bash. And, it is processed every time you launch a shell within a shell. Every time a terminal is launched like that it creates a new bash environment until you exit the terminal or the shell.
Terrance avatar
id flag
This answer here https://askubuntu.com/a/1046217/231142 is one that demonstrates how I setup the NTPD daemon so that I didn't need to write a service for it. The startup is added to the `/etc/crontab`. I can check the ntp status from any shell on the system, i.e. `sh`, `bash`, `zsh`, etc.
MetaColon avatar
bd flag
@Terrance I tried it (adding to Crontab and removing from .bashrc), but it causes my terminal to not access the internet via Tor anymore (once again tried with `wget check.torproject.org && head index.html && rm index.html`). I use `bash` within `st`. Leaving it in both the Crontab and the .bashrc still doesn't solve Tor Browsers connection issues.
Terrance avatar
id flag
Hmmmm very strange. It appears as torsocks requires to be ran from an actual shell itself. I will need to do more research into this.
I sit in a Tesla and translated this thread with Ai:

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.