2

I am using tsocks to socksify my connections. When I run the following commands, apt-get isn't socksified:

$ . tsocks -on
$ sudo apt-get update

However, when I run the whole thing in one line like the following, it works.

sudo tsocks apt-get update

I have verified that when I type . tsocks -on, my LD_PRELOAD environment variable is set to /usr/lib/libtsocks.so.

Why doesn't the former work?

muru
  • 207,228
Parham Doustdar
  • 151
  • 2
  • 9

3 Answers3

3

Although it's already given an answer I want to share what worked for me, using Ubuntu 14.04:

sudo apt-get install tsocks

Then open /etc/tsocks.conf and add your server to server and port to server_port, also add your socks server's range as local, like

Example if your ip address is 90.70.60.5 then write:

local = 90.70.60.0/255.255.255.0 (Note the .0 as the last part in ip address)

Now try:

sudo tsocks apt-get update (or whatever apt-get command)

If it doesn't work using sudo, log in directly as root like:

sudo su

Then try again:

tsocks apt-get update

I was behind a socks 5 server to reach a download link I didn't have access from my own computer, and it worked flawlessly.

Note: With this I didn't have to use "Acquire" stuff in /etc/apt/apt.conf

1

Per the answer given by @creveti-mihai, I looked at the sudoers man page. Unfortunately, as the man page says, it is not possible to preserve LD_* variables. Here is what the man page says:

 Note that the dynamic linker on most operating systems will remove
 variables that can control dynamic linking from the environment of setuid
 executables, including sudo.  Depending on the operating system this may
 include _RLD*, DYLD_*, LD_*, LDR_*, LIBPATH, SHLIB_PATH, and others.
 These type of variables are removed from the environment before sudo even
 begins execution and, as such, it is not possible for sudo to preserve
 them.

So, I'll have to look at specifying the proxy in apt's own configuration files using Acquire::http::proxy and Acquire::https::proxy.

Parham Doustdar
  • 151
  • 2
  • 9
0

Is the root's LD_PRELOAD also set to /usr/lib/libtsocks.so? Take a look at:

  • The -E (preserve environment) option for sudo. Ex: sudo -E bash -c 'echo $LD_PRELOAD' vs sudo echo $LD_PRELOAD;
  • The sudoers file: Defaults env_keep;