[From the springboard machine ssh to the intranet target server] Configure vscode to achieve remote connection

1 Why use a springboard machine? Springboard -> target server problem

  • Some servers are deployed in the laboratory intranet environment, and we cannot directly connect with personal laptops. Therefore, generally, first connect to the springboard machine (which can be accessed by the external network environment) through ssh, and then jump to the target server (intranet environment) through ssh.
  • But here comes the problem! Programming can only be done through text editing tools such as vim, and command line operations are used during training, which causes a certain degree of inconvenience.
  • Before I summarized vscode’s remote connection to the server and how to log in without secrets ( [Complete process] vscode connects to a remote Linux server and login without secrets ), this is obviously a connection, if “springboard -> target server” can also configure vscode remote Connection, that will bring great convenience to our coding. So can it be achieved? The answer is yes!
  • Note: Because most of the operations are consistent with the direct remote operation of vscode connection, please refer to the link given above for specific operations, so here we only introduce the key operations from the springboard to the intranet target server.

2 configure config file

We have already configured the config from ssh to the springboard machine before, so now we only need to configure the config from the springboard machine to the intranet target server:
insert image description here
an example config is given below:

Host JumperSever
    HostName 1.1.1.1
    User student1
    Port 1001

Host TargetSever
    HostName 2.2.2.2
    User student2
    ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -W %h:%p JumperSever

3 Attention

  • There should be a password in the config, but here I asked the administrator to configure the password-free connection in advance, so there is no need to write the password in the config. The configuration of the secret-free connection is divided into two steps: ① write your local machine (notebook) into the file public keyof the springboard machine authorized_keys; ② write the file on your springboard machine into the file public keyof the target server authorized_keys.
    The two-step operation is almost the same. Keygen generates the public key (client-side local operation) and writes authorized_keys (admin operates on the server-side). You can still refer to this article: [ Complete process] vscode connects to a remote Linux server and logins without secrets
  • The key point of this cross-server configuration is: ProxyCommand ssh -W %h:%p JumpSeverthis line! By ProxyCommand sshpointing the springboard machine at the target server. Note that the ssh here needs to be replaced with ssh.exethe path of your local machine.

4 Remote connection, start experiment

Find the option of the target server directly on the left side of vscode, and make a remote connection:
insert image description here
Then select the folder you want to enter and start the experiment. The subsequent operation is exactly the same as directly using ssh for remote connection:
insert image description here
as you can see, I have remotely connected to the intranet target server through vscode (ssh again through the springboard machine), bingo! ! !

Guess you like

Origin blog.csdn.net/qq_16763983/article/details/126868473