Tips for Remote Development

Tutorial about using inversese proxy to connect a server in a private network which your machine don't have access to.

How to remotely evelop with pycharm

Here're two plans.

Plan 1

  1. You can put your project in local. Then using pycharm to develop it with a remote python interpreter, instead of a local interpreter.

    Figure1.1

    As you can see, the interpreter is at a remote server.

  2. Then you'll see a connection in In "Tools" -> "Deployment" -> "Configuration".

    Figure1.2
    Figure1.3
  3. In In "Tools" -> "Deployment" -> "Configuration" --> "Mapping", config a project mapping. So that your remote server will have a copy of your local project, and every local change will be synced to the remote server.

    Figure1.4
  4. In "Tools" -> "Deployment" -> "Options", select a way to sync your file:

    Figure1.5

Plan 2

Connect to a remote server from PyCharm

It's also simple. You can try it.

Plan 3

Use vscode since it supports remote development

Change font: modify the settings.json file

1
2
3
4
5
6
{
"terminal.integrated.fontFamily": "FiraCode Nerd Font Mono",
"workbench.colorTheme": "Gruvbox Dark Hard",
"editor.fontLigatures": true,
"editor.fontFamily": "'FiraCode Nerd Font Mono', Menlo, Monaco, 'Courier New', monospace"
}

Change color theme:

  1. Go to Gruvbox Theme
  2. To install it, you need to:
    1. In VS Code, open the Color Theme picker with File > Preferences (Code > Preferences or *Code* > *Settings* on macOS) > Theme > Color Theme.
    2. You can also use the keyboard shortcut ⌘K ⌘T to display the picker.
    3. Use the cursor keys to preview the colors of the theme.
    4. Select the theme you want and press Enter.

Debug:

  1. Step: F10

  2. Step into: F11.

    disable Mac's F11 behavior:

    1. Go to System Preferences -> Keyboard -> Shortcuts
    2. Uncheck the "Show Desktop F11" option

How to connect a remote Server in a private network

If the server is in a public network, i.e., has a public IP, then you can just use ssh to connect it.

But what if the server is in a private network, i.e., has a private IP, which is common because lots of servers are in campus network(like eduroam) or company's network etc

You can't use ssh to connect these private IPs, so you only have 2 ways:

  1. Using "inverse proxy", which means let the server connect to a "jump server" which has a public IP. This jump server can be connected by ssh and it can forward your requests to the server.

    1
    2
    3
    <Server in private network> -Connect-> <Jump Server on public nerwork> 

    <Your PC on public network> -> <Jump Server on public nerwork> -> <Server in private network>
  2. Ask your ISP to assign a static public IP to your server.

A common inverse proxy tool is ngork. It offers jump servers for free.

Setup a jumpserver

You can maually setup a server as your jump server, this is easy.

Note: It's recommented to have a dedicated SSH jump server, i.e. not host any other publicly accessible software on it.

Now, suppose you have:

  1. Originating IP: 105.68.76.85 (we’ll call this host_local).
  2. Jump Server IP (we’ll call this host_jump): 173.82.232.55. It can (only) be connected via port=22.
  3. Destination IP (we’ll call this host_destination): 173.82.227.89. It can (only) be connected via port=33000.

To setup host_jump as a jump server, we should

  1. Make sure that we haveve Passwordless SSH Login between all three machines.

  2. Make sure that host_jump is in the same private network with host_destination, i.e., host_jump can reach host_destination.

  3. Make sure that host_local is in the same private network with host_jump, i.e., host_local can reach host_jump. This can be achieved by some VPN.

  4. Edit ~/.ssh/config, append

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Host jump-server
    HostName 173.82.232.55
    User lyk
    Port 22

    Host 173.82.227.89
    HostName 173.82.227.89
    User lyk
    Port 33000
    ProxyJump jump-server

    to setup the alias for connecting with 173.82.227.89.

  5. Now you can connect using the alias

    1
    ssh 173.82.227.89 -p 33000

    The network process is like:

    1
    host_local --(port=22)--> host_jump --(port=33000)--> 173.82.227.89

Ngork

  1. In the server, install ngork.

  2. In the server, start ngork and listen to port 22.

    1
    ngrok tcp 22
  3. Now in the Endpoints page of Ngork, you can see the server is listed as an "endpoint":

    Ngork Endpoints page

    The endpint is identified as

    1
    tcp://<hostname>:<port>
  4. Now in the client machine, just use

    1
    ssh -p <port> <User>@<hostname>

Note: Each time you start the ngork process on the server, the hostname and port will be reset.

To avoid this, you can assign a static IP, which needs to pay money to ngork.