1. Install OpenSSH on your local machine
Take window as an example.
1) Download openSSH
and download the corresponding OpenSSH file https://github.com/PowerShell/Win32-OpenSSH/releases
2) Unzip it to C:\Program Files\OpenSSH. Do not put it in other paths. This is the official requirement. 3
) cmd to the openSSH path
and execute
1) Install sshd service
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
2) Open port 22 (if you turn off the firewall in Windows and configure inbound rules, you do not need to execute the following command, multiple executions will not affect it)
netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport= twenty two
3) Configure the sshd service to start automatically at boot.
sc config sshd start= auto.
The installation is now complete.
4. Add C:\Program Files\OpenSSH to the path to avoid having to switch to C:\Program Files\OpenSSH every time to use ssh and start the ssh service
net start sshd
Configure ssh into environment variables
2. Install remote plug-in in vscode
Search Remote-SSH in vscode to install the Remote SSH plug-in. After finding the corresponding plug-in, click the green "Install" to start the installation.
3. Use the Remote-SSH plug-in to connect to the server
After the installation is complete, click the Remote-SSH tab on the left
Then move the mouse to the SSH TARGETS column, click the gear icon that appears, Configure
, select the first item in Select SSH configuration file to edit, and start editing the content inside:
the above picture is the initial .ssh The contents of the config file in the folder need to be modified to the required content. Don't forget to save it after modification (if the SSH port is not the default 22, you need to add a line of Port).
Note: The remote connection plug-in of VSCode is based on OpenSSH, so the OpenSSH client needs to be installed on the local machine, and the OpenSSH server must also be installed on the server.
4. Common mistakes
There are two possibilities for an SSH installation couldn't be found in VScode SSH Remote
:
The ssh service is not installed.
The ssh path is not configured
. Configure the ssh path. Open the setting.json of vscode and add it.
“remote.SSH.path”: “C:\Program Files\OpenSSH\ssh.exe”