This is yet another tutorial/note to help you set up a VS Code that connects to a machine and allows you to work remotely in a LAN. Sure there are tons of video and documents, but I think they really complicated things, the connection setup is really easy, basically telling the remote machine:

hey, this is me, the real one.

Summarize the steps in a quick way as follows:

Generate the Identity

Generate an SSH key pair on your machine that runs the VSCode locally, for example, my case is on Windows. Open a powershell and type:

ssh-keygen -t rsa -b 2048  # or 4096

Go through the generation steps, specify the file path such as C:\User\<you>\<rsa_file>, after done, you will see <rsa_file> and a <rsa_file>.pub under the directory, the latter one is what you need to copy to your remote machine.

Let the Remote Know

SSH to your remote machine, look for `~/.ssh/authorized_keys, if not, create one with your favorite editor.

vim ~/.ssh/authorized_keys

Config VSCode

  1. Copy the <rsa_file>.pub to above file

  2. Config the VS code

    1. Install the Remote - SSH plugin

    2. Install the Remote - SSH Config plugin

    3. Click the left bottom corner button button

    4. add your remote hostname, e.g., foo@bar-machine add-host

    5. Configure the ssh file with below info config-hosts

    Host <whatever you like to call> 
    HostName <your remote host name>
    User <your login>
    IdentityFile "path to your rsa_file"  # no .pub!

Done!