Howto::VScode: Difference between revisions

From Computer Science Wiki
Jump to navigation Jump to search
Carnold (talk | contribs)
Created page with "== Introduction == Visual Studio code (vscode) is an increasing popular way of developing software on rlogin.cs.vt.edu. With the appropriate plugin, it will allow you directl..."
 
Carnold (talk | contribs)
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Introduction ==
== Introduction ==
Visual Studio code (vscode) is an increasing popular way of developing software on rlogin.cs.vt.edu.  With the appropriate plugin, it will allow you directly edit your files on rlogin.cs.vt.edu and make it easy to get a terminal to run and test your code.
Visual Studio Code (vscode) is an increasing popular way of developing software on rlogin.cs.vt.edu.  With the appropriate plugin, it will allow you directly edit your files on rlogin.cs.vt.edu and make it easy to get a terminal to run and test your code.  These instructions are geared toward the Windows version of vscode, but should be easily adaptable to other operation systems.  These instruction also assume that you already have the latest version of vscode installed locally.
 
== Plugin installation and configuration ==
* Make sure you also have an SSH client: https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client
* Click on the "Gear" icon and select "Extensions" OR push <ctr>-<shift>-x
* Search for "Remote - SSH"
* Click the "Install" button
* This should give you a small green button (bottom left) with "><" icon
* Click on the green button and select "Connect to host..."
* Select "+ Add New SSH Host..."
* Type in "<username>@rlogin.cs.vt.edu -A" change <username> to your CS username.  Your username should be all lowercase.
* It should give you a dialog saying the host was added and a button to "Connect"
* When you first connect it will ask you what platform the host is, select "Linux"
* It will also likely ask for your password unless you already have a SSH key set up
* Once connected, the green button should update with "SSH: rlogin.cs.vt.edu" letting you know you are connected remotely
 
== Set up SSH key authentication ==
* Setting up a public/private key will save you from having to enter your password so many times while using vscode
* While inside VS Code, hit <ctrl>-o to open a file, open the '''local''' file: "c:\Users\<username>\.ssh\id_rsa.pub"  If this file does not exist, then you can run "ssh-keygen" from the command to generate the file
* Copy the whole contents of this file
* Use VS code to edit the '''remote''' file: ~/.ssh/authorized_keys (if this is your first time, then you might have to create it as a new text file)
** Alternately, you can use the command line to SSH into rlogin.cs.vt.edu and edit the file directly using the command `nano ~/.ssh/authorized_keys`
 
== Troubleshooting ==
* It is common to run into issues with vscode and remote SSH
* The first step to identifying the problem is to determine if the problem is with VS Code and it's server component or an SSH connectivity problem
** You can do this by opening a command prompt and run the command <code>ssh <username>@rlogin.cs.vt.edu</code> replace <username> with your CS username
** If you can successfully connect this way, then the problem is likely a configuration issue with VS Code
** If this does not work, then the problem is likely SSH.
 
=== Troubleshooting VS Code ===
* First try resetting the remote side by issuing the VS code command (ctrl-shift-p): "Remote-SSH: Kill VS Code Server on Host..."
* Make sure you are running the latest version of "Remote -SSH" extension (ctrl-shift-x) and that it is reloaded
* Check the extension settings by hitting (ctrl-shift-x) and click on the "gear" icon under "Remote - SSH" and select "Extension Settings"
* Make sure your account is not over disk quota.  SSH into rlogin outside of VS Code and try the following commands:
** <code>touch ~/test</code> - This command will attempt to write the file ~/test  It will give an error if you are over your quota.
** <code>du -sh ~</code> - This command will give you your total disk usage.
** <code>du -shx ~/*</code> - This command will breakdown your disk usage for each directory and file in your home directory.  Note: this will not include top level "." hidden files.  This will help you track down files that are taking up your disk space.
* Common settings:
** Make sure that "Remote Platform" is set to linux for rlogin.cs.vt.edu
** Make sure that "Config File" is set to a valid value, this is generally left blank
** Make sure that "Path" is set to a valid value, this is generally left blank which means it will use the Windows SSH client
* Lastly, you can try using SSH to connect rlogin.cs.vt.edu and manually remove the VS Code server directory by running the command <code>rm -rf ~/.vscode-server</code>
* If you still are unable to connect VS Code to rlogin.cs.vt.edu, then [[Contact Techstaff]] Sometimes a VS Code server component will get stuck and need to be killed
 
=== Troubleshooting SSH ===
* If you get an error such as "''not recognized as an internal or external command...''" then make sure you have the Windows SSH client installed
* If you get an error such as "''Permission denied, please try again''" then make sure you are using your CS username and that it is all lowercase.  You can test your CS password online at https://admin.cs.vt.edu and reset the password at https://admin.cs.vt.edu/reset/
* If SSH seems to accept your password but hangs for a while and then times out, then you there might be an issue with your bash init scripts (.bashrc and .bash_profile).  Try connecting again and hit <ctrl>-c while it hangs to break the loop.  This should let you in so that you can fix your bash init scripts.
* If you still are unable to SSH into rlogin.cs.vt.edu, then [[Contact Techstaff]]
* Windows Specific error: Bad Owner or Permissions on SSH Config
** See: https://www.virtualizationhowto.com/2022/02/bad-owner-or-permissions-on-ssh-config-windows-10
 
=== Other problems ===
* If you have modified your .bashrc file on rlogin, this could potentially cause an issue with VS Code being able to connect.  If your .bashrc file produces any kind of output or error messages then SSH will be unable to tunnel binary files which is used by VS Code. 
** Be careful about sourcing your .bash_profile inside .bashrc, as it can unknowingly create output.
** The system default .bashrc file can be found on rlogin at <code>/etc/skel/.bashrc</code>
* Rarely, you might be put onto an rlogin node that is not working correctly.  To resolve this, wait at least 5 minutes before reconnecting and the load balancer will put you onto a new node.

Latest revision as of 06:32, 1 November 2024

Introduction

Visual Studio Code (vscode) is an increasing popular way of developing software on rlogin.cs.vt.edu. With the appropriate plugin, it will allow you directly edit your files on rlogin.cs.vt.edu and make it easy to get a terminal to run and test your code. These instructions are geared toward the Windows version of vscode, but should be easily adaptable to other operation systems. These instruction also assume that you already have the latest version of vscode installed locally.

Plugin installation and configuration

  • Make sure you also have an SSH client: https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client
  • Click on the "Gear" icon and select "Extensions" OR push <ctr>-<shift>-x
  • Search for "Remote - SSH"
  • Click the "Install" button
  • This should give you a small green button (bottom left) with "><" icon
  • Click on the green button and select "Connect to host..."
  • Select "+ Add New SSH Host..."
  • Type in "<username>@rlogin.cs.vt.edu -A" change <username> to your CS username. Your username should be all lowercase.
  • It should give you a dialog saying the host was added and a button to "Connect"
  • When you first connect it will ask you what platform the host is, select "Linux"
  • It will also likely ask for your password unless you already have a SSH key set up
  • Once connected, the green button should update with "SSH: rlogin.cs.vt.edu" letting you know you are connected remotely

Set up SSH key authentication

  • Setting up a public/private key will save you from having to enter your password so many times while using vscode
  • While inside VS Code, hit <ctrl>-o to open a file, open the local file: "c:\Users\<username>\.ssh\id_rsa.pub" If this file does not exist, then you can run "ssh-keygen" from the command to generate the file
  • Copy the whole contents of this file
  • Use VS code to edit the remote file: ~/.ssh/authorized_keys (if this is your first time, then you might have to create it as a new text file)
    • Alternately, you can use the command line to SSH into rlogin.cs.vt.edu and edit the file directly using the command `nano ~/.ssh/authorized_keys`

Troubleshooting

  • It is common to run into issues with vscode and remote SSH
  • The first step to identifying the problem is to determine if the problem is with VS Code and it's server component or an SSH connectivity problem
    • You can do this by opening a command prompt and run the command ssh <username>@rlogin.cs.vt.edu replace <username> with your CS username
    • If you can successfully connect this way, then the problem is likely a configuration issue with VS Code
    • If this does not work, then the problem is likely SSH.

Troubleshooting VS Code

  • First try resetting the remote side by issuing the VS code command (ctrl-shift-p): "Remote-SSH: Kill VS Code Server on Host..."
  • Make sure you are running the latest version of "Remote -SSH" extension (ctrl-shift-x) and that it is reloaded
  • Check the extension settings by hitting (ctrl-shift-x) and click on the "gear" icon under "Remote - SSH" and select "Extension Settings"
  • Make sure your account is not over disk quota. SSH into rlogin outside of VS Code and try the following commands:
    • touch ~/test - This command will attempt to write the file ~/test It will give an error if you are over your quota.
    • du -sh ~ - This command will give you your total disk usage.
    • du -shx ~/* - This command will breakdown your disk usage for each directory and file in your home directory. Note: this will not include top level "." hidden files. This will help you track down files that are taking up your disk space.
  • Common settings:
    • Make sure that "Remote Platform" is set to linux for rlogin.cs.vt.edu
    • Make sure that "Config File" is set to a valid value, this is generally left blank
    • Make sure that "Path" is set to a valid value, this is generally left blank which means it will use the Windows SSH client
  • Lastly, you can try using SSH to connect rlogin.cs.vt.edu and manually remove the VS Code server directory by running the command rm -rf ~/.vscode-server
  • If you still are unable to connect VS Code to rlogin.cs.vt.edu, then Contact Techstaff Sometimes a VS Code server component will get stuck and need to be killed

Troubleshooting SSH

  • If you get an error such as "not recognized as an internal or external command..." then make sure you have the Windows SSH client installed
  • If you get an error such as "Permission denied, please try again" then make sure you are using your CS username and that it is all lowercase. You can test your CS password online at https://admin.cs.vt.edu and reset the password at https://admin.cs.vt.edu/reset/
  • If SSH seems to accept your password but hangs for a while and then times out, then you there might be an issue with your bash init scripts (.bashrc and .bash_profile). Try connecting again and hit <ctrl>-c while it hangs to break the loop. This should let you in so that you can fix your bash init scripts.
  • If you still are unable to SSH into rlogin.cs.vt.edu, then Contact Techstaff
  • Windows Specific error: Bad Owner or Permissions on SSH Config

Other problems

  • If you have modified your .bashrc file on rlogin, this could potentially cause an issue with VS Code being able to connect. If your .bashrc file produces any kind of output or error messages then SSH will be unable to tunnel binary files which is used by VS Code.
    • Be careful about sourcing your .bash_profile inside .bashrc, as it can unknowingly create output.
    • The system default .bashrc file can be found on rlogin at /etc/skel/.bashrc
  • Rarely, you might be put onto an rlogin node that is not working correctly. To resolve this, wait at least 5 minutes before reconnecting and the load balancer will put you onto a new node.