WARNING This method is now considered unreliable due to the load it places on CSE servers, and may be blocked by CSE’s System Support at any time. Check out this newer post instead. Do not use this on CSE.
Hi there! If you’re new here, welcome to CSE! We’re going to be setting up a text editor called Visual Studio Code, or VS Code, to remotely work on the CSE computers without needing a VNC client!
You’ve likely used a program called TigerVNC to connect to the School of CSE’s computers before, which provides you a visual interface with a full desktop environment, very similar to the experience you would get out of sitting in front of a physical computer on campus.
If you’re currently doing COMP1511, I would strongly advise you to use the provided desktop environment and gedit over TigerVNC for the first week, just to familiarise yourself with it. Don’t take your experience with it as a sign that Linux has to be ugly either - this subreddit has plenty of proof otherwise. (Despite the name, I promise it’s safe for work.)
More importantly, under normal circumstances, you would be doing your exams in front of a similarly configured physical computer on campus. As of the start of 2021 however, it seems you’re generally free to use whatever setup you wish.
The solution we’re about to go through provides a more seamless coding experience without having to load a full visual interface from CSE computers. This has the added benefits of not being affected by compression, especially if you have a poor connection, and other latency issues.
I don’t particularly recommend this for first years, but if you’re a more experienced user with your own local setup, you might want to checkout this more lightweight method here.
First of all, we’re going to acquaint ourselves with Visual Studio Code, or VS Code. You’ve likely been introduced to a tool called gedit which allows you to write files of text (including code), or what’s called a text editor. VS Code does th is, but it provides many more great features on top. To get started, you’ll need to install VS Code on your own computer, whether it be Windows, macOS or Linux.
You should now have VS Code installed! You can now edit files on your own computer, but that’s not quite what we want - our goal is to edit files on CSE machines.
Some cool computer scientists invented a way (or more specifically, a set of rules, or protocols) to allow you to communicate with remote computers over the internet, called SSH, or Secure Shell. This allows us to edit files on another computer, such as the CSE servers, and run commands through a terminal on CSE servers.
Luckily for us, VS Code has a way to use SSH to allow you to edit files and run commands on other computers.
If you’re on macOS, use Cmd instead of Ctrl.
Ctrl+Shift+X
.Not performing this step can make your CSE account accessible to anyone while you’re connected. Accounts that don’t enable this will not be able to use VS Code to connect to CSE computers in the future.
Ctrl+,
.Congrats! You’re now safer from nefarious hackers, or inadvertent intruders.
Note: If you’re coming here from the older version of my guide, please switch to using vscode.cse.unsw.edu.au, rather than login, wagner, weill or williams. If not you can ignore this.
Open the Remote-SSH menu. This can be done by clicking this button
in the bottom left. The menu should look like this:
z5555555@vscode.cse.unsw.edu.au
, using your zID instead. Hit Enter.
A new window will open.ls
to see your files!ssh z5555555@vscode.cse.unsw.edu.au
, replacing with your own zID again, and hit Enter. If prompted which configuration file to save to, select the first one.vscode.cse.unsw.edu.au connects you to a CSE server called corelli
, which works fine most of the time. However, the server software VS Code uses in order to form a connection is quite resource intensive, and can often eat up all the resources that corelli
has available.
Thankfully, CSE has set up a second server called mandolin
you can use in case you’re having issues with corelli.
To set up your VS Code to be able to connect to mandolin
, repeat Part 3, but replace all occurrences of z5555555@vscode.cse.unsw.edu.au
with z5555555@vscode2.cse.unsw.edu.au
. That’s right, you just need to stick a 2
after vscode
!
You can connect to mandolin
if corelli
ever feels slow, which it might during assignment season.
The COMP1511 style guide requires you to make sure your lines of code aren’t longer than 80 characters (and it’s good practice to do so!). You can make VS Code show a handy little ruler to make sure your lines aren’t too long.
}
. What we want to do is add a comma to the second last line. Then, create a new line after the comma, and paste this:
"[c]" :{
"editor.rulers" : [
80
]
}
The VS Code C/C++ extension will make your life a lot easier when coding. To install it,
Ctrl+Shift+X
.VS Code has heaps of themes and extensions. Some which I use:
Congrats! You made it to the bonus section. Following these instructions will mean you won’t be asked for a password each time you open a new SSH window, while still keep your connection secure, using magic in the form of mathematics.
cmd
in Search.ssh-keygen -t rsa -b 4096
.code "%userprofile%/.ssh/id_rsa.pub"
. This should open up a file in VS Code, starting with ssh-rsa and followed by a long mess of characters. 1 Don’t close this file, but use Ctrl+A Ctrl+C to copy the entire contents of this file.ssh-keygen -t rsa -b 4096
.Your computer has now generated two files: id_rsa
and id_rsa.pub
. The id_rsa.pub
file is what’s called a public key, while id_rsa
is a private key. Never share (or even open) your private key. It’s called a private key for a reason :P
Now, we need to tell the CSE computer that your computer is trustworthy, and you are who you claim to be. To do this, we need to give the CSE computer the public key you just generated. If you’re on Linux/macOS, this should be pretty easy, but if you’re on Windows 10, there’s a few more steps.
Using your existing SSH or VLAB connection, open a terminal on the CSE computers. Run the following command. 2
mkdir ~/.ssh;chmod 700 ~/.ssh;touch ~/.ssh/authorized_keys;chmod 600 ~/.ssh/authorized_keys;code ~/.ssh/authorized_keys
A window for a file called authorized_keys should open in VS Code. Paste your public key from earlier into this file, and save.
Run the following command, replacing with your own zID.
ssh-copy-id z5555555@cse.unsw.edu.au
Voila! You had it a bit easier here.
Host vscode.cse.unsw.edu.au
HostName vscode.cse.unsw.edu.au
User z5555555
Host vscode2.cse.unsw.edu.au
HostName vscode2.cse.unsw.edu.au
User z5555555
Windows: Make sure to enter your username. If you don’t know it, it’s the part after C:/Users/
when you open cmd
.
IdentityFile "C:/Users/[YOURUSERNAME]/.ssh/id_rsa"
Linux/macOS
IdentityFile ~/.ssh/id_rsa
A potential completed config might look like this:
Host vscode.cse.unsw.edu.au
HostName vscode.cse.unsw.edu.au
User z5555555
IdentityFile "C:/Users/Bob/.ssh/id_rsa
Host vscode2.cse.unsw.edu.au
HostName vscode2.cse.unsw.edu.au
User z5555555
IdentityFile "C:/Users/Bob/.ssh/id_rsa
Once you’ve done this, you should be able to open Remote-SSH in VS Code without requiring a password.
If you need to add another public key to authorized_keys (for another computer), you can enter it on a new line.
This guide was once part of a much larger guide which involved setting up to allow you to code on your own computer. However, this was much more than what most 1511 students need. It’s worth noting that you need to have an internet connection for SSH to work. If your train route has poor reception, and you want to code on the train, you would need an alternative.
Even then, I would still recommend setting up your own local coding setup at some point. If you’re new to coding and you’re doing 1511 right now, I wouldn’t say you should worry about this. However, if you do intend on going on to study more CSE courses, I recommend that you come back over the break after term ends and check out this other post I wrote, which goes through setting up a Linux development environment if you have a Windows 10 computer, and using Git and GitHub to keep copies of your work on different computers and the internet.
If you’re having trouble connecting to VS Code, a fix that tends to work is
rm -r ~/.vscode-server
. Make sure to copy and paste this command carefully.Alternatively, if you know how to open a Command Prompt/Terminal, you can run ssh -t z5555555@cse.unsw.edu.au "rm -r ~/.vscode-server"
, replacing with your own zID.
If this doesn’t work, try some of the solutions here.
If you’ve spotted an error, or have any suggestions or improvements that I can make, feel free to contact me! My details are at the bottom of this page.
Despite myself and the people being acknowledged below currently being employed by the School of CSE, this blogpost doesn’t necessarily represent the views of my employer.
As of late October 2020, CSE now has an official guide available for using VS Code to connect over SSH. While the steps you’ve just followed cover all of what’s in the guide (and more!), and is up-to-date as of the time of writing, you can find the official guide here.
Thanks to the following people who’ve looked over this guide and provided feedback!