Skip to main content

Use VSCode to SSH in Remote Systems

Prerequisite

Install the Remote SSH extension on VSCode. extension

Configuration

  1. Press Ctrl + Shift + P and search for Remote SSH - Connect to Hostconnect-host
  2. Once you click on Connect to Host, you will be prompted with the screen. add-host
  3. Click on Add New SSH Host and add the correct SSH Connection Command.
  4. In my case, the command was
    ssh mistryds@arcc.uc.edu
  5. Once you have added the command, save the config in C:/User/<your-name>/.ssh/config. save-config
  6. Once you have done that, your SSH config should now look like this.
    ssh-conf
  7. You are now ready to connect to the SSH server.

Connect to MSI server

  1. Follow steps 1 to 3 in the Configuration section.
  2. In this case, the terminal command should look like this.
    ssh gqc@192.168.94.40
  3. Once the command is added, follow the remaining steps in the above section and proceed to Connect to Host step.

Connect to Host

  1. Press Ctrl + Shift + P again in VSCode and search for Connect to Host.
danger

Note: Make sure you are connected to the internet through your organization's VPN.

  1. Select the config you just created.
  2. After you click on the option, VSCode will ask you enter the password to your.
  3. Enter the password.
  4. Ta-da! You have now logged into the SSH server using VSCode.
  5. Open the directory of your choice and use VSCode to its full potential.
info

Note:

  1. You might need to re-install some VSCode extensions on the remote server. Install them at your own discretion.
  2. You might want to ask someone from GQC, the password to the configured system

Setup SSH-keys to authenticate access to the remote machine

Instead of providing password each time we access a remote machine, we can authenticate through a SSH-key.

  • Setting up remote login to microcenter and MSI machines with SSH keys. Assuming your local machine is running on Windows. Similar commands are available for linux.

    1. In your local machine (Windows), open a terminal window and run ssh-keygen -t ed25519.

      1. Give a unique name to the file. For example, I'm using C:/Users/pavan/.ssh/id_ed25519_microcenter as the name.
      2. This will generate a private key (with no extension) and a public key (with .pub extension)
      3. We use the private key at our end and put the public key in the remote in the next steps.
    2. SSH to the remote machine using the password for this time. I used VSCode itself to connect. Copy the content of the generated .pub file to ~/<user>/.ssh/authorized_keys file in the remote machine (linux).

    3. In VSCode, Open SSH configuration file by pressing ctrl+shift+p and typing Remote-SSH: Open SSH Configuration File remote ssh

      • Select the User level configuration file (default) user level ssh config file
    4. If you already have a configuration for the same IP address, replace it with the following fields with the corresponding values. If not add these at the end of the file.

      Host MicroCenter
      HostName 192.168.50.57
      User gqc
      PreferredAuthentications publickey
      IdentityFile "/Users/pavan/.ssh/id_ed25519_microcenter"
      • Host: Put a unique name for the machine. Doesn't affect the connection
      • HostName: IP address of the machine
      • User: Username. Typically gqc
      • PreferredAuthentications: Keep this as publickey
      • IdentityFile: Path to the private key file. Follow the exact same syntax as shown in snippet above. Note that C:/ is omitted from the path.
    5. Configuration is now complete. You can test the connection either using VSCode itself or through any terminal with ssh support.

      1. VSCode: Follow the Connect to Host steps. But this time it won't ask for password.
      2. Windows Terminal: access through terminal