Install proxychains and tmux: you might have luck with something like:
sudo ssh -R 8080:us.archive.ubuntu.com:80 [email protected]
echo 'Acquire::http::Proxy "http://localhost:8080";' | sudo tee /etc/apt/apt.conf.d/proxy.conf
apt-get update
apt-get install proxychains tmux
sudo rm /etc/apt/apt.conf.d/proxy.conf
Notice the last line there undid the apt proxy configuration?
After you have proxychains and tmux, you can get much more reliable operation, and without funky apt configuration changes, and pip / curl etc works too.
First, start up tmux. (quick primer, uses CTRL-B
than another key, 'c' for another new shell, 'n/p' for cycling between shells, 'd' to detach and leave things running).
tmux
Next, we'll make a ssh connection from the isolated computer back to any computer it can SSH to which does have internet access, lets call it server
.
ssh -f -NT -M -S ~/.ssh/ssh_socket_for_proxychains -D 127.0.0.1:17471 server
This doesn't seem like it's done anything, because it's running in the back ground. You can see it with ps aux |grep ssh
or so.
Now, configure /etc/proxychains.conf
:
sudo nano /etc/proxychains.conf
Change the last line from socks4 127.0.0.1 9050
to socks5 127.0.0.1 17471
.
Finally, you can now run things like sudo proxychains apt upgrade -y
and proxychains pip install ...
without having them fail.
As a bonus, you can detach the tmux session (CTRL-b,d) and come back to it later (ssh back in, then tmux a
).
For raspberrypi's, it works if you change 'us.archive.ubuntu.com' to 'archive.raspberrypi.org', and for random debian you might have luck with 'ftp.us.debian.org'
For me, the use case is things like raspi's on a isolated static ip network, where I have another server with two network connections (one with internet access, another to the isolated lan) where it does not route: It's running trueNAS, and the lan is staying isolated.
But it does have opensshd that I can ssh into, and then ssh along to the pi.
In this case, its isolated lan ip address is the 'server' the pi connects back to. And its the pi that gets proxychains and tmux and can then be updated via apt.
Credit to James Mertz for the ssh -R
part, but it only works with http traffic, anything that has an https URL will fail; and it won't work for pip: where things get fetched from a bunch of different random servers. Still, it's good enough to use to get proxychains.
The proxychains howto part came curtesy of https://yuzhangbit.github.io/tools/use-apt-get-behind-socks5-proxy/