Home>Article>Development Tools> A brief analysis of how to remotely connect to cloud servers in vscode

A brief analysis of how to remotely connect to cloud servers in vscode

青灯夜游
青灯夜游 forward
2022-06-06 19:07:46 2796browse

How to remotely connect to the cloud server in vscode? The following article will introduce to you how to connect to your own cloud server remotely invscode. I hope it will be helpful to you!

A brief analysis of how to remotely connect to cloud servers in vscode

Deployed a small node project on my own cloud server. When encountering small changes, it is a bit troublesome to modify them locally and then upload them to the server.

So I thought that vscode can achieve remote connection. [Recommended learning: "vscode introductory tutorial"]

Plug-in: remote

First ensure that the ssh tool is installed on your terminal.

  • Mac can enter: ssh in the terminal. If the following picture appears, the installation is successful:

A brief analysis of how to remotely connect to cloud servers in vscode

  • This is for Windows:

A brief analysis of how to remotely connect to cloud servers in vscode

My environment is: mac m1pro

Basic usage The specific steps

vscode installation remote plug-in

I have already installed it

A brief analysis of how to remotely connect to cloud servers in vscode

After the installation is successful, an icon will appear in the sidebar, ignoring the ecs I have configured

A brief analysis of how to remotely connect to cloud servers in vscode

Add your own server

First method:

  • Click the plus sign in the picture above

A brief analysis of how to remotely connect to cloud servers in vscode

Enter the IP address of your cloud server and press Enter

  • Use the mouse to select the first file in the picture below

A brief analysis of how to remotely connect to cloud servers in vscode

  • Then get the following picture

A brief analysis of how to remotely connect to cloud servers in vscode

  • At this time, the cloud server we added appears in the box on the left side of vscode

A brief analysis of how to remotely connect to cloud servers in vscode

  • This When we add two more configuration information: User user name, Port port number

A brief analysis of how to remotely connect to cloud servers in vscode

Then you can click the folder icon in the picture below to open the connection .

A brief analysis of how to remotely connect to cloud servers in vscode

  • Summary configuration information

    • Host xxxx: Host refers to the name of the cloud server, which can be customized. Write whatever you want
    • HostName xx.x.xx.x: As the name suggests, fill in the ip address of the cloud service
    • User xxx: The user name used when logging in, such as: root, admin, etc.
    • Port xx: The port number for ssh connection, usually port 22. You can also change it yourself.
    • ForwardAgent yes: generated by vscode itself, the problem is not big, don’t worry about it.

The second methodis to click on the small gear and then select the first file. After that, go back to the configuration file and configure it according to the configuration information in the picture above.

Advanced Configuration

What should I do if I don’t want to have to enter a password every time I connect? Answer: Create ssh key

  • First generate the private key and public key files encrypted by rsa.

  • In the terminal, cd to ~/.ssh first, and then enter: ssh-keygen -t rsa -b 4096 -f xxxx (name it yourself)

  • will ask you to enter the password passphrase twice. Enter everything and don’t enter anything. Otherwise, the connection cannot be successful

  • Then two files, the public key and the private key with your own defined name, are generated in the ~/.ssh directory.

  • Then copy the xxx.pub file to the .ssh folder of the server. If the server does not exist, create it yourself. Generally, centos is in the /root/ directory, that is, ~

  • and then execute the command: cat xxxx.pub > authorized_keys (xxx is above your own Customized file name)

  • Then an authorized_keys file will be generated in the current directory

  • Finally, configure the vscode configuration file That’s it

    • Add after the original configuration information:
      • IdentityFile ~/.ssh/xxx
  • Now You can develop as you like.

Ultimate Advanced

  • If you have several servers what to do?
  • Just copy the previous configuration, and then change the IP, nickname and ssh key file name.

Additional knowledge

  • The passphrase mentioned above: What does Enter passphrase (empty for no passphrase) mean?
  • Answer: rsa belongs to asymmetric encryption and has a public key and a private key. Under normal circumstances, this encryption method is theoretically almost foolproof. But it cannot prevent physical attacks. If the enemy intercepts the secret key or public key in some way, it will be GG. The existence of the passphrase is to wrap a layer of symmetric encryption outside the public key and private key. In this way, even if the enemy gets the public key and private key, he will not be able to attack. The safety level has been improved a lot, but it still cannot guarantee 100% safety.

For more knowledge about VSCode, please visit:vscode tutorial!

The above is the detailed content of A brief analysis of how to remotely connect to cloud servers in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete