How to access internet and run apt-get through a middle server?

Open a terminal and start ssh dynamic port forwarding:

ssh -D 1080 [email protected]

This will start a socks proxy on your computer on port 1080.

Add this line to your /etc/apt/apt.conf file:

Acquire::socks::Proxy "socks5h://localhost:1080";

Then you can run your apt update / apt install commands. When you're done, you can close the ssh connection and revert the changes in apt.conf.

You can also tell your Browser or other applications to use that Socks proxy and access the Internet.


The easiest way would be that you set up a proxy server on the middle server/gateway and set up your apt to use this proxy:

sudo vi /etc/apt/apt.conf.d/proxy.conf

And add this line:

Acquire::http::Proxy "http://user:[email protected]:port/";