For some reason, it is necessary to use one computer to develop the code of another computer remotely, so VSCode remote development is a good way, and both computers are Windows 10 system

Open the SSH

The Openssh Server service must be installed and enabled on the PC serving as the Server

Check whether the installation is Complete.

The purpose of this service is to allow you to use SSH commands from your terminal. Windows10 usually comes with OpenSSH and does not require installation.

Choose Windows in Win10 PoweShell (administrator), enter the following command: Get WindowsCapability – Online |? Name -like ‘OpenSSH*’ If OpenSSH is not installed, State will display NotPresent:

If both are NotPresent, you can skip the subsequent installation

Mouse operation installation

Mouse operation is relatively brainless, the mouse dot dot dot is good.

  • Click win and select the Settings button from the popup menu

  • In Windows Settings, click Apply

  • On the applications and Functions page that is displayed, tap Manage optional functions

  • Click add feature as shown

  • Under optional features locate OpenSSH Server and click

  • Click install as shown and wait for the installation to complete. The same method is used to install the OpenSSH Client

  • Restart the computer, open the command line tool, and enter SSH. The installation is successful as shown in the figure

The following figure shows the successful installation

Command line operation installation

Command-line operations are relatively simple

  • Install the server

Add - WindowsCapability - Online - the Name OpenSSH. Server ~ ~ ~ ~ 0.0.1.0

  • Install the client

Add - WindowsCapability - Online - the Name OpenSSH. Client ~ ~ ~ ~ 0.0.1.0

The configuration service starts by default

  • Click the search button on the toolbar to search for services in the pop-up search interface

  • On the OpenSSH Server page, right-click the OpenSSH Server properties

  • Set to auto start

  • Start the service

The network access

When the external network access, and did not assign IP to our server, this time either requires our network operator to assign us an IP address, if Intranet penetration.

Intranet through

Access the Intranet from the public network by technical means. For details, see the following two articles. Zhuanlan.zhihu.com/p/57477087 www.bilibili.com/video/BV1bi… \

VSCode configures the remote server

Install Remote – SSH

Remote-ssh is a plug-in for VScode. After installing VScode, you can search SSH in the plug-in directly to find remote-ssh and click Install

configuration

After remote-SSH is installed, a Remote resource management icon is displayed on the left. Select SSH Targets to access the Config configuration file

Set the server information in the configuration file. Enter HostName and User. The corresponding machine name is displayed on the left after saving the configuration file

To change Settings, go to File->Preferences->Settings->Extension-> remote-ssh, go to Show Login Terminal and check it.

VSCode uses a remote server

Click the button next to the server under SSH TARGETS to connect, select the platform of the server, and the popup asks you to enter your password

Successfully connected to the server, click the + on the right to create the terminal window of the server, it can be used normally!

We can also open the server’s folder

Open after you can see the server file directory, directly in the file directory to select the file for editing, real-time synchronization to the server, this time can start a happy development, development experience comparable to local development!

Connect to the server through a jumper

Sometimes we need a jumper to connect to the server, that is, to connect to a jumper server and then jump to the target server again through the Intranet where the jumper is located. The simplest way is to connect to the jumper in the above way, and then jump to the target server with SSH command on the terminal of the jumper. However, after this jump, we cannot open the file directory of the server in VScode, which is very inconvenient to operate.

We can set two servers in config, one is the jumper, the other is the Intranet server. First use VSCode to log in to the jumper, and then log in to the Intranet server

SSH Encryption-free login

Simplified login requires a password.

The client generates public and private keys

Enter ssh-kengen -t rsa -b 4096 or ssh-kengen in CMD and press Enter

Upload the public key to the server

The generated key id_rsa and public key id_rsa.pub files are saved in the (C:\User\ User /.ssh) folder by default.

Enter under CMD

SET REMOTEHOST=your-user-name-on-host@host-fqdn-or-ip-goes-here scp %USERPROFILE%\.ssh\id_rsa.pub %REMOTEHOST%:~/tmp.pub  ssh %REMOTEHOST% "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat ~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm -f ~/tmp.pub"Copy the code

For example, my username on the server is “lpy”, the IP address of the remote server is 49.52.10.120, So my first line of code is SET [email protected]

The SCP command is a secure remote file copy command based on SSH login in Linux. The first part is the location of the local public key file, and the second part is the file named tmp.pub in the current directory on the remote server. We need to copy the local public key to this temporary file.

%USERPROFILE% is the localhost username, found in C:\Users, %REMOTEHOST% is what we just SET, forget it.

Test encrypted login

SSH [email protected]Copy the code

reference

Blog.csdn.net/junbaba_/ar… Jingyan.baidu.com/article/a3a…