Optional Ungraded Assignment: SSH setup


Introduction

You can connect to OSC with SSH if you have a bash shell on your machine, either natively with a Mac or Linux machine, or via WSL, Git Bash, or another application on Windows.

The regular way to do this is typing ssh <username>@pitzer.osc.edu and then providing your password, which can get tedious. There are two setup steps you can take to make this quicker:

  1. Avoid being prompted for your password.

  2. Set up a shortcut for your SSH connection name.

A third thing you can do below, assuming you have VS Code installed locally, is to get it to SSH tunnel to OSC: this will be as if you have VS Code open in OnDemand, but then not in your browser!

1. Avoid being prompted for password

These steps are similar to what you did for your SSH Github authentication.

  1. On your own computer, generate a public-private SSH key-pair:
$ ssh-keygen -t rsa

When you’re prompted for a passphrase, you can just press enter if you are okay with not having a passphrase.

If you do want a passphrase, you have to take an extra step to not be prompted, after step 3 below:

$ ssh-add
# (Then here, don't enter a passphrase in any case!)
  1. From your own computer, transfer the public key to the remote computer:
# Replace <user> by your username, e.g. "jelmer@owens.osc.edu"
$ cat ~/.ssh/id_rsa.pub | ssh <user>@owens.osc.edu 'mkdir -p .ssh && cat >> .ssh/authorized_keys'
  1. Log in to the remote computer (OSC) and once there, set appropriate permissions:
$ chmod 700 .ssh; chmod 640 .ssh/authorized_keys

See also this Tecmint post in case you’re struggling, and Buffalo Chapter 4 page 59-60.


2. Use a shortcut for your SSH connection

These two steps should both be done on your local machine.

  1. Create a file called ~/.ssh/config:
$ touch ~/.ssh/config
  1. Open the file in a text editor and add your alias(es) in the following format:
Host <arbitrary-alias-name>    
     HostName <remote-name>
     User <user-name>

For instance, I have something along these lines for Pitzer and Owens:

Host op
    HostName pitzer.osc.edu
    User jelmer

Host oo
    HostName owens.osc.edu
    User jelmer

Now, you just need to use your, preferably very short, alias to log in:

$ ssh op

This shortcut will also work with scp and rsync!

$ rsync ~/scripts op:/fs/ess/PAS1855/scripts


3. Set up your local VS Code to SSH tunnel into OSC

If you want to use VS Code to write code, have a shell, and interact with files at OSC directly, you don’t need to use the VS Code Server from OSC OnDemand. You can also “SSH tunnel” in with your local installation. This is a more convenient way of working because it’s quicker to start up and you are not working inside a browser (which, among other things, takes away screen space and interferes with some keyboard shortcuts).

The set-up is pretty simple (see also these instructions if you get stuck), just recall to do this in your local installation of VS Code, assuming you have one.

  1. Install the VS Code “Remote Development extension pack” by opening up the Extensions side bar, searching for it there, and then clicking “Install”.

  2. Open up the Command Palette (F1 or Ctrl+ShiftP) and start typing “Remote SSH”. Then, select Remote-SSH: Connect to Host… and specify your SSH connection: e.g. ssh jelmer@pitzer.osc.edu (you’ll have to do this separately for Pitzer and Owens if you want to be able to connect to either).

  3. With the above setup, you shouldn’t be prompted for a password and VS Code will connect to OSC!

    If you’re asked about the operating system of the host, select Linux, which is the operating system of the OSC clusters.

    Now, if you open a shell or try to open a file, you are interacting with the OSC file system and not your local computer.



Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".