gws_core

Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version

Connect local VsCode

How to use local VSCode to connect to Codelab and develop remotely


This section explains how to connect your local Visual Studio Code (VSCode) to Codelab to develop remotely. By using the "Connect to Host" feature of VSCode, you can gain the same functionalities as in Codelab, such as running the dev server and debugging. Additionally, connecting remotely allows you more control over your VSCode configuration and enables you to use any extension from the VSCode marketplace, while Codelab has access only to extensions from open-vsx.org.


Configuring remote VSCode


Requirements


  1. Have a running data lab and access to Codelab.
    1. Use version 1.19.0 or more of Lab Manager.
      1. Use version 0.14.0 or more of gws_core.


        To use VSCode remotely, you must first configure an SSH connection between your computer and Codelab. Follow these steps:


        Configure SSH connection



        1. Generate SSH Key: On your computer, run the ssh-keygen command to generate an SSH key. In Windows, the key is created by default in C:\Users\[USER]\.ssh.
          1. Create SSH Config File: Navigate to the C:\Users\[USER]\.ssh directory. Create a file named config (without any extension), if it doesn't exist. Open the configfile with a text editor and add the following configuration for the Codelab host. View an example of the file bellow. Replace [HOST_NAME] with your lab's host name. Open Codelab and copy the URL part after https:// and before the first /. It should look like codelab.mylab.constellab.app. Replace [PATH_TO_PRIVATE_KEY] with the path of your previously generated SSH key (usually in C:\Users\[USER]\.ssh).
            1. Add Public Key to Codelab: Copy your SSH public key (the file ending with .pub).Connect to your destination Codelab. Add your public key to the authorized keys of Codelab: echo '[PUBLIC_KEY]' > /root/.ssh/authorized_keys
              1. Test SSH Connection: Open a terminal and try to connect to Codelab: ssh codelab.[HOST_NAME]Use the same host as defined in your config file. If the connection works, proceed to the next section. Otherwise, see troubleshoot section.

                Config file: 


                Host codelab.[HOST_NAME]
                	IdentityFile [PATH_TO_PRIVATE_SSH_KEY]
                	User root
                	Port 2222

                Connect VSCode to Codelab


                Now that the SSH connection is working and the config file is set up, you can connect your VSCode to Codelab by following these steps:


                1. Open VSCode on your computer. Download it if necessary.
                  1. Download the Remote - SSH Extension:Go to Remote - SSH extension and install it on VSCode.
                    1. Choose Your Host: Choose codelab.[HOST_NAME] from the host list. Choose the host type as 'Linux'.
                      1. Open Remote VSCode: It will open a new VSCode window in the remote host. Verify the host name in the bottom left corner of the VSCode window.
                        1. Install Recommended Extensions: You are ready to work! You can install any recommended extensions or other extensions you need from the VSCode marketplace.

                          By following these steps, you have successfully configured your local VSCode to develop remotely on Codelab, making the most of both local and Codelab development environments.



                          Troubleshoot


                          SSH connection doesn't work in the terminal


                          If you're experiencing issues with SSH connections in the terminal, follow these steps to troubleshoot:


                          1. Check SSH Service Status. Ensure that the SSH service is running by executing the following command in the Codelab terminal: service ssh status.
                            1. Verify Public Key Configuration. Confirm that your public key (not the private key) is correctly defined in the /root/.ssh/authorized_keys file within the Codelab environment.
                              1. Use Verbose Mode for SSH Command. Run the SSH command with the -v option to enable verbose mode. Check that the correct configuration file is being used and that it contains the appropriate settings.

                                Error: remote host identification has changed


                                When connecting to a Docker container, you may encounter the error "Remote Host Identification has changed." To resolve this:


                                1. Clear Codelab Host from Known Hosts. Access the known_hosts file in your SSH folder located at C:\Users\[USER]\.ssh.
                                  1. Remove the Codelab Host Entry. Clear the entry related to the Codelab from the known_hosts file. This will prompt the system to reestablish a fresh identification for the host on your next connection attempt.