banner
LiberalBlue

LiberalBlue

(●'◡'●)

Notes on avoiding pitfalls when using Remote SSH in VS Code on Windows environment

First, the basic principle is: install the openSSH client/server components on your local Windows. Then, you can access the remote host through the command line, and the Remote SSH plugin on the VS Code platform can provide a better unified editing and development environment.

The basic requirement is to enable the OpenSSH components on Windows, which can be found and installed in "Windows Settings -> Apps -> Optional Features".

Next, don't worry about VS Code for now, focus on configuring the SSH file. Usually, the default configuration file is located at "C:\Users\Yourname\.ssh".

You can refer to this configuration file:

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config

Host ABCD
  HostName mydomain.com/IP
  User root
  Port 22
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
  ProxyCommand "XYZ/Git/mingw64/bin/connect.exe" -H 127.0.0.1:4321 %h %p

Host is the alias or nickname of the remote server, you can choose any.

HostName is the address of the remote host, it can be a URL or an IP address.

Port is the port that SSH connects to the remote host, usually the default is 22, if modified, please keep it consistent.

IdentityFile is the storage location of the private key credential used for key pair authentication. There are details on generating, managing, and setting up remote server login methods, which will not be discussed here. Usually, the exported private key is stored in this directory and with this name, it is best to keep it consistent. (Others are also possible)

IdentitiesOnly selects the method of using key authentication only.

Finally, if you need to use a proxy, in the ProxyCommand, Windows users use connect.exe, which means you must install git for windows. (This can be a bit tricky) First is the directory address of the file, it must be enclosed in double quotes, it is best to use '/', do not use '\'. The -H option means the local HTTP proxy, and the -S option refers to the local socks5 proxy. The following is the address and port that the proxy usually listens to. The final '%h' and '%p' will be automatically replaced with the target hostname and the port specified by the SSH command, do not modify them.

Next, test it using cmd or powershell:
ssh ABCD
If everything is normal, you will be prompted to save the session and enter the password. Only when everything is OK, proceed to install the VS Code plugin.

After that, it's simple. Install the Remote SSH plugin in VS Code (there will be an accompanying plugin now). After successful installation, restart VS Code. There will be a green remote connection icon in the lower-left corner. Press "F1" in the interface, enter "Remote-SSH: Open SSH Configuration file" and select the first one in the menu that appears: c:\Users\YOURNAME.ssh\config. This is the configured and verified file from the previous steps. Then, the configured remote server will appear in the remote section on the left side. Click on it. Normally, there will be a prompt in the lower-right corner, and there will be a prompt to enter the password. Just log in.

This is the simplest and most direct way. The official documentation is a bit verbose and can be misleading for beginners.

That's it. 🤞

Additional notes:

  1. To log out of the remote host in the command line, press "Ctrl+D".
  2. In VS Code, you can use the file explorer to manage the remote host, but you need to enter the password again.
  3. To log out of the remote host, go to File -> Close Remote. Otherwise, VS Code will attempt to log in every time it is opened.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.