Be sure the client machine can ping server successfully. If request time out, server machine must be added a new rule in 'Windows Defender Firewall with Advanced Security' to permit 'ICMPv4' protocol for all ip addresses and ports1.
Likewise, the server machine also need to be added a new rule to allow TCP 22 port to be accessible.
Install OpenSSH on server machine2, and download OpenSSH's released compressed file e.g. OpenSSH-Win64.zip on a certain folder and uncompress it in this directory. Open Powershell in administrator and change directory to uncompressed folder, run this code to install OpenSSH server.
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
Configurate the SSH of client machine. Open PowerShell on client machine and input codes below, and tap enter key three times to continue.
Besides, a new file 'config' should be created in client machine's directory 'C:/Users/Administrator/.ssh' and input the information of remote server:
Host anyName(You can write a new in your mind) Hostname 18.104.22.168(input your remote ip) User xxx(input the account name of remote machine)
You need to change 'config' file's right configuration to meet the OpenSSH's require. Only your User account should be assigned a right to use 'config' file3.
Now, you can find files id_rsa and id_rsa.pub in directory 'C:/Users/Administrator/.ssh'(or 'C:/Users/xxx/.ssh'). Please copy the content of id_rsa.pub to server machine's directory 'C:/Users/Administrator/.ssh'(or 'C:/Users/xxx/.ssh') as authorized_keys file. And you need change server's work directory to 'C:/ProgramData/ssh', and edit the file 'sshd_config' .Be sure there is no comment sign at the head of these lines4:
PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication no (*** need change original 'yes' to no)
And be sure these lines have comment sign at the head of line.
#Match Group administrators #AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
Ok, if you have finished all above. you can have a try to use ssh connect with remote machine:
ssh firstname.lastname@example.org (note: email@example.com should be changed by you)
Also we can set the OpenSSH to auto start when we restart our server machine. Just change the attribute from 'manual' to 'auto' in 'Computer Management' - 'Services and Applications' - 'Services' - 'OpenSSH SSH Server'.
Now, you can install extension 'remote-SSH' on your client machine's Visual Studio Code. And tap the remote sign left to use remote server5.