Monday, December 3, 2018

Using tsocks with apt to bypass proxy

Recently, I encountered an error while trying to update ubuntu server 16.04. The error is as below:

E: Failed to fetch  Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)

It seems there is a proxy somewhere in the network, that I do not know. Asking around, even the owner of the server does not even know any proxy server inside their network. So, what I did was, create a socks proxy on my own, to a server outside of the network, and tunnel the apt connection using an application called tsocks.

First, you need to install tsocks. This is a bit tricky since we cannot use the apt command to download and install it from the internet. So I downloaded the deb file, using wget.
$ wget -c

Once downloaded, install using apt on the local file.
$ sudo apt install ./tsocks*.deb

Once installed, create a socks proxy to a server outside of the network, on localhost port 8888 (this is just my favorite number for socks proxy, you can use any number above 1000). You need to be able to ssh to the outside server for this to be possible.
$ ssh foo@server.outside -D 8888

Change the tsocks config file, to suite your new socks proxy
$ sudo cat /etc/tsocks.conf
# You just need to change these 3 lines
server =
server_type = 5
server_port = 8888

$ sudo -i 
# tsocks apt update
# tsocks apt upgrade

P/S: You can also set an environment variable called http_proxy, if you do not want to install tsocks, but this setting will be only active on your current bash session. This can be accomplished by:
# export http_proxy='socks5://localhost:8888'
# apt update && apt upgrade

No comments: