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
You can put your project in local. Then using pycharm to develop it with a remote python interpreter, instead of a local interpreter.
As you can see, the interpreter is at a remote server.
Then you'll see a connection in In "Tools" -> "Deployment" -> "Configuration".
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.
In "Tools" -> "Deployment" -> "Options", select a way to sync your file:
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 | { |
Change color theme:
- Go to Gruvbox Theme
- To install it, you need to:
- In VS Code, open the Color Theme picker with File > Preferences (Code > Preferences or *Code* > *Settings* on macOS) > Theme > Color Theme.
- You can also use the keyboard shortcut ⌘K ⌘T to display the picker.
- Use the cursor keys to preview the colors of the theme.
- Select the theme you want and press Enter.
Debug:
Step: F10
Step into: F11.
disable Mac's F11 behavior:
- Go to System Preferences -> Keyboard -> Shortcuts
- 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:
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>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:
- Originating IP: 105.68.76.85 (we’ll call this
host_local
). - Jump Server IP (we’ll call this
host_jump
):173.82.232.55
. It can (only) be connected via port=22. - 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
Make sure that we haveve Passwordless SSH Login between all three machines.
Make sure that
host_jump
is in the same private network withhost_destination
, i.e.,host_jump
can reachhost_destination
.Make sure that
host_local
is in the same private network withhost_jump
, i.e.,host_local
can reachhost_jump
. This can be achieved by some VPN.Edit
~/.ssh/config
, append1
2
3
4
5
6
7
8
9
10Host 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-serverto setup the alias for connecting with
173.82.227.89
.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
In the server, install ngork.
In the server, start ngork and listen to port
22
.1
ngrok tcp 22
Now in the Endpoints page of Ngork, you can see the server is listed as an "endpoint":
The endpint is identified as
1
tcp://<hostname>:<port>
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.