8

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?

erik
  • 16,959
  • 4
  • 32
  • 46

2 Answers2

11

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
rush
  • 27,055
  • 7
  • 87
  • 112
  • Why the compression? And how do you end the SSH if it's not running a shell to `ctrl+d`? – erikbstack Sep 17 '15 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 '15 at 17:02
1

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 127.0.0.8123 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.

MadMike
  • 193
  • 6
  • 1
    As of at least Ubuntu 20.04, `polipo` is no longer in the standard apt repositories. Folks can use `tinyproxy` instead. https://www.gypthecat.com/tinyproxy-a-quick-and-easy-proxy-server-on-ubuntu – Alison R. Sep 26 '21 at 02:50