I have a server which has only access to the outer world via port 22 (for the use of ssh from the server to other computers).

I want to install some packages via apt-get on this server.

Can I achive this with a ssh-tunnel to my super-machine which has internet access on all ports?

If so, how? Because if I start a tunnel via ssh to my super-machine, the super-machine has its sshd waiting on port 22. I assume that I cannot reuse this same port 22 for the tunneling, can I?

Is there another solution?

2 Answers 2


Try to run it via ssh socks proxy:

echo 'Acquire::socks::proxy "socks://localhost:3128/";' | sudo tee -a /etc/apt/apt.conf
ssh -CND localhost:3128 [email protected]

in another terminal session:

sudo apt-get whatever you need
  • Why the compression? And how do you end the SSH if it's not running a shell to ctrl+d?
    – erikbstack
    Sep 17, 2015 at 15:32
  • 1
    compression helps on slow channels. though it's not necessary here. I use ctrl+c to close the connection.
    – rush
    Sep 17, 2015 at 17:02

I couldn't get the other answer to work.

I have a raspberry pi in the network of a customer who blocks port 80. So I installed polipo (a socks/http proxy) on my own maschine, connect with ssh on that raspberry pi and while doing so create a tunnel to polipo-proxy.

To install polipo (I use this on a Ubuntu 16.04 maschine):

sudo apt install polipo

This will serve on which is good enough for our needs. Connect to the remote maschine while also opening a tunnel:

ssh -R 8123:localhost:8123 myuser@client_maschine02

Now you need to tell apt to use the proxy. I do this with this command:

echo 'Acquire::http::proxy "http://localhost:8123";' | sudo tee -a /etc/apt/apt.conf.d/proxy.conf

Now you are ready to use apt as usual.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .