pip install via ssh of two remote machines

Viewed 211

I'd like to install a package via pip in a machine not connected on internet. The problem is a little bit messy but I'll try to be clear as much as I can. There are two remote machines I use to work connecting on them via ssh, let's call them M1 and M2. M2 is not ssh reachable directly from my computer but I need to go through M1, so the architecture is something like:

My computer -----> M1 -----> M2
             ssh       ssh

M1 is connected on the internet, so I'm able to make installations via pip, whereas M2 is not. Is there any way to make a pip install on M2 exploiting M1 ? I could download the packages folder and make the installations but since there are some dependences, I was wondering if there are more efficient ways to do it.

Thanks a lot in advance!

Edit: Both remote machines run Linux

1 Answers

I propose the following broad lines of a solution:

  1. Configure pip on M2 to have it's index URL point to M2 itself.

  2. From M2 issue a port forward ssh command as follows:

    ssh -L 80:pip_server_on_the_internet:80 M1 ssh -L 443:pip_server_on_the_internet:443 M1

Replace pip_server_on_the_internet with the machine DNS name you found in the original pip config file.

When you run pip on M2 it will connect locally then go through ssh to M1 which will redirect the connection request to the target pip server.

If port 80 or 443 are already used on M2, then you can change these to any port number, day 4444 and 4445 and reflect that in the pip config file. You then need to ssh as follows:

ssh -L 4444:pip_server_on_the_internet:80 M1
ssh -L 4445:pip_server_on_the_internet:443 M1

Not sure if port 80 is used. Check pip URL.

Related