Skip to Content

vscode: Remote Access and Code Editing

Published on November 12, 2024

Time to read: 12 minutes

vscode logo

In addition to these instructions, you can find a video tutorial here: Video: vscode: Remote Access and Code Editing

Step 1: Install vscode

The first thing you need to do is install vscode on your local device (person computer). We won’t go into the details of installing it here as it varies depending on your device (Linux, Windows, iOS). The install is usually straight-forward.
The vscode download for various platforms can be found here: vscode download

Step 2: Install Remote-SSH Extension

vscode cannot make remote connections initially. The Remote-SSH extension is required

Open vscode and click on the Extensions panel button (see Red Box in the image below)

vscode extension menu

Click on the extension search bar (see Red Box in the image below) and start typing remote ssh.

The Remote – SSH extension should appear (see Green Box in the image below).

Click on the Install button (see Purple Box in the image below).

vscode install remote ssh extension

Step 3: Create Remote-SSH Connection

A new panel button called Remote Explorer should appear – you may have to close and reopen vscode (see Red Box in the image below). Click on the Remote Explorer button.

Expand the tree down until you see the SSH branch (see Green Box in the image below).

Click on the plus (+) button to begin adding a new SSH connection (see Purple Box in the image below).

vscode add ssh connection

In the SSH Connection box that opens (see Red Box in the image below)
Enter ssh student@134.117.130.199 – replacing the IP with you own 134.117.#.# IP address

vscode enter ssh target

It will ask you to save the connection information to an ssh config file. The default one will vary depending on what operating system you are running. In general you can select the first option (see Red Box in the image below)

vscode edit ssh config

A pop-up will appear saying the host was added. If you want, you can manually modify the ssh config file by clicking Open Config. However, this is not required, and in this case we will just click Connect (see Red Box in the image below)

vscode connect

You will then be prompted for the password for the student account (see Red Box in the image below).

vscode password prompt

It will then show a pop-up on the bottom right showing the vscode-server being added to the remote account. This make take a few moments to complete.

vscode initializing

And that should complete adding the connection. A new empty vscode workspace should open that is connected to that remote server.

Step 3 OPTIONAL: SSH with a Jump Host (No VPN) and Passkeys

As an alternative to VPN, you can ssh through the SCS access.scs.carleton.ca jump host. You can see this article for more information on using the access as a jump host.

We recommend you confirm with a regular ssh shell (terminal) application that you are able to use the access jump host to jump to your target server (eg: your openstack instance).

Once confirmed you can edit the vscode ssh config file manually and add the below config:
NOTE: If you are only connecting with a password, do NOT include the OPTIONAL IdentityFile and AddKeysToAgent options below, as they do not apply. If you wish to use the public/private key IdentityFile so that you do not need to types your password every time, then you should follow this article that explains how to set those up.

Host access-jump-host
  HostName access.scs.carleton.ca
  User cmail_username
  # OPTIONAL use of identify file (so you do not have to use a password)
  IdentityFile /Path/To/Private/Key/privatekey.ed25519
  # OPTIONAL add key to your local computer's ssh agent if you use a key with a passphrase.  You will need to research how to setup the ssh agent on your particular operating system (beyond the scope of this article)
  AddKeysToAgent yes

Host my-openstack-instance
  # The below IP must be your openstack IP or other destination server
  HostName 134.117.128.32
  User student
  ProxyJump access-jump-host
  # OPTIONAL use of identify file (so you do not have to use a password)
  IdentityFile /Path/To/Private/Key/
  # OPTIONAL add key to your local computer's ssh agent if you use a key with a passphrase.  You will need to research how to setup the ssh agent on your particular operating system (beyond the scope of this article)
  AddKeysToAgent yes

Once you have saved the above ssh config in vscode, replacing usernames, IPs, etc as required for your particular situation, you will now see my-openstack-instance as a connection option when you open a new remote ssh connection in vscode.

Step 4: Open Folder on Remote Server

Now that the vscode workspace is connected to the remote server, we need to open a folder. Click the Explorer navigation button (see Red Box in the image below) and click Open Folder (see Green Box in the image below)

vscode open folder

The open folder search box will automatically start in the home directory (/home/student) of the student account, so simply click OK (see Red Box in the image below) unless you want to open a specific sub-folder.

vscode select folder

You will again be asked to enter the password for the student account (see Red Box in the image below)

vscode enter password

A window will pop up asking if you trust the authors of files in this folder. If a check box is shown to trust all files in the folder ‘student’, check it (see Red Box in the image below), although this may not appear in all cases. Click Yes, I trust the authors (see Green Box in the image below)

vscode trust content

The Explorer view will now show all of the files and folders in the student account home directory (see Red Box in the image below).
NOTE: The exact content of the directory will vary depending on which course image you are connecting

vscode folder content list

Step 5: Open a terminal, edit some code, run some code!

It can be convenient to open a terminal window so we can run commands just like we would if we had ssh’d into the system. You can open a terminal window in many ways. Here are three easy ones:

Either of these actions will open a terminal, as seen in the Red Box in the image below

vscode terminal

Next, we can open a file to edit with vscode. In the example below, we have a folder called assignment-code, with a python file called hello-world.py (see Red Box in the image below). If you click on the hello-world.py file, it will open the file in the workspace so you can edit it (see Green Box in the image below).
NOTE: If this is the first time you have edited a python file, vscode may helpfully offer to install a python extension to help with you python coding (see Purple Box in the image below). It will often do this for any programming language that you open for the first time. It is up to you to decide if you want this extension. In some cases, your instructor may ask that you install specific extensions with certainly capabilities. So make sure to check your course notes.

vscode code edit and extension prompt

We can use the terminal window to conveniently run commands. In this example, we manually run the python program hello-world.py.

vscode running your code

Troubleshooting: Failed Login

vscode failed logins are most often caused by two things:

  1. New Openstack Instance with Expired Password: New openstack instances have a default username and password, and the password is expired and must be changed. This cannot be done through the vscode remote connection interface, so you must use a different Connection Tool to connect to your instance for the first time. Once you have set a new password, you can use vscode normally.
  2. Instance Disk Full: If an instance’s disk drive fills up, it will not be possible to login with vscode as the tool needs to setup temporary files to initialize. The indicator of this problem is (usually): when you enter the password, vscode will hang, sometimes showing an installing vscode server message that never goes away. If you see that behavior, it is likely that the disk is full. You must login with another Connection Tool, free up some disk space, and then return to using vscode.

Troubleshooting: Disk Full

vscode installs a lot of libraries and support tools to make you coding easier. It also stores a cache of all the original downloaded installers, which it keeps even after the tool has been successfully added to vscode. It is quite common for all of this to quickly fill an openstack instance’s disk drive. Check with your course instructor for instructions on how to clear the vscode cache as it can vary.