- 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 based on VS Code 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, first write the SSH configuration 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 freely.
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 login with 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 set it the same as this. (Others are also possible)
IdentitiesOnly selects the method of using key-only authentication.
Finally, if you need to use a proxy, in the ProxyCommand, Windows users use connect.exe, which means you must install Git for Windows. (There is a bit of a pitfall here) First is the file directory address, it must be enclosed in double quotes, it is best to use '/', do not use '\'.
The -H option means the local HTTP proxy.
The -S option refers to the local socks5 proxy.
After that is the address and port that the proxy usually listens on.
The last '%h' and '%p' will be automatically replaced with the target hostname and the port specified by the SSH command, do not modify them.
-
Then, test it using cmd or powershell:
ssh ABCD
If everything is normal, it will prompt you 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 for now). After successful installation, restart VS Code. There will be a green remote connection icon in the lower left corner.
In the interface, press "F1" and enter "Remote-SSH: Open SSH Configuration file", then select the first option that appears in the menu: 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. 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 misleading for beginners.
That's it. 🤞
Additional notes:
- To log out of the remote host in the command line, press "Ctrl+D".
- In VS Code, you can use the file explorer to manage the remote host, but you need to enter the password again.
- To log out of the remote host, go to File -> Close Remote. Otherwise, it will attempt to log in every time you open VS Code.