Connecting to OSC through SSH

Author

Jelmer Poelstra

Published

April 12, 2024



Introduction

This page will first go through the basics of connecting to OSC with SSH, using the ssh command. If you use ssh frequently, or plan to do so, the two sections after that will show you two useful tricks:

Finally, there is a section on SSH-tunneling a local VS Code installation to OSC (this is incredibly useful!).

If you have a Windows computer, you can’t use SSH in a shell like on Mac or Linux, but you can instead use a GUI-based SSH client like PuTTY.

Alternatively, for an experience more similar to those one Unix-based operating systems, you can install one of the following, which will enable you to get a terminal program that runs a Unix shell:

  • Windows Subsystem for Linux (WSL) — the more involved option, this will basically run a Linux Virtual Machine on your computer.
  • Git for Windows, which comes with a Unix (Bash) shell — “Git Bash”. To install this, download it from this page and install it using all the default settings for the installation, except:
    • In “Adjusting Your PATH Environment”, select “Use Git from Git Bash Only”.
    • In the prompt “Configuring the Line Ending Conversions”, choose “Checkout as-is, commit as-is”.


1 Basic SSH connection in a terminal

To connect to OSC or other remote computers without using a web portal like OnDemand, you can use SSH. You can do so via the ssh command if you have a Linux or a Mac computer, since these two operating systems are both Unix-based and have built-in terminals with Unix shells.

Here, I’ll briefly demonstrate how to use the ssh command. On your own computer, open a terminal application and input the command ssh <user>@<host>, where:

  • <user> should be replaced by your OSC username, and
  • <host> should be replaced by the name of the computer you want to connect to:
    • pitzer.osc.edu to connect to the Pitzer cluster
    • owens.osc.edu to connect to the Owens cluster

For example, if I (username jelmer) wanted to log in to the Pitzer cluster, I would use:

ssh jelmer@pitzer.osc.edu
The authenticity of host 'pitzer.osc.edu' can't be established.
RSA key fingerprint is 2a:b6:f6:8d:9d:c2:f8:2b:8c:c5:03:06:a0:f8:59:12.
Are you sure you want to continue connecting (yes/no)?

If this is the first time you are connecting to Pitzer via SSH, you’ll encounter a message similar to the one above. While the phrase “The authenticity of host ‘pitzer.osc.edu’ can’t be established.” sounds ominous, you will always get this warning when you attempt to connect to a remote computer for the first time, and you should type yes to proceed (you then won’t see this message again).

You should now be prompted for your password. Type it in carefully because no characters or even *s will appear on the screen, and then press Enter.

jelmer@pitzer.osc.edu's password:

If you entered your password correctly, your shell is now connected to OSC rather than operating on your own computer. That is, you’ll have shell access very much in the same way as when using the “Pitzer Shell Access” button on OSC OnDemand. (The key difference between SSH-ing in this way rather than using OnDemand is that the terminal is not running inside your browser, which can be convenient.)

SSH shortcuts!

If you use SSH a lot to connect to OSC, typing ssh <username>@pitzer.osc.edu every time and then providing your password can get pretty tedious. The next two sections will show you how to make this go faster.


2 Avoid being prompted for your OSC password

If you take the following steps, you will not be prompted for your OSC password every time you log in using SSH. Both steps should be done in a terminal on your local machine:

  1. Generate a public-private SSH key-pair:

    ssh-keygen -t rsa

    You’ll get some output and will then be asked several questions, but in each case, you can just press Enter to select the default answer.

  2. Transfer the public key to OSC’s Pitzer cluster:

cat ~/.ssh/id_rsa.pub | ssh <user>@pitzer.osc.edu 'mkdir -p .ssh && cat >> .ssh/authorized_keys'
# Replace <user> by your username, e.g. "ssh-copy-id jelmer@pitzer.osc.edu"
ssh-copy-id <user>@pitzer.osc.edu

All done! Test if it works by running:

# Try connecting to Pitzer (once again, replace '<user>' by your username):
ssh <user>@pitzer.osc.edu

The same commands work for Owens, just replace pitzer with owens in the commands above.
Additional instructions: See this Tecmint post in case you’re struggling to get this to work.


3 Use a shorter name for your SSH connection

You can easily set up alternative ways of referring to you SSH connection (i.e., “aliases”), such as shortening jelmer@pitzer.osc.edu to jp, by saving these aliases in a text file ~/.ssh/config, as shown below.

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

  1. Create a file called ~/.ssh/config:

    touch ~/.ssh/config
  2. Open the file in a text editor and add your alias(es) in the following format:

    Host <arbitrary-alias-name>    
       HostName <remote-address>
       User <username>

    For instance, my file contains the following so as to connect to Pizer with jp and to Owens with jo:

    Host jp
       HostName pitzer.osc.edu
       User jelmer
    
    Host jo
       HostName owens.osc.edu
       User jelmer

Now, you just need to use your, preferably very short, alias to log in — and if you did the previous no-password setup, you won’t even be prompted for your password!

ssh jp

These shortcuts also work with scp and rsync!

For example:

rsync ~/scripts op:/fs/scratch/PAS0471


4 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 necessarily need to use the VS Code (Code Server) in OSC OnDemand. You can also make your local VS Code installation “SSH tunnel” into OSC.

This is a more convenient way of working because it’s quicker to start, will never run out of alotted time, and because you are not working inside a browser, you have more screen space and no keyboard shortcut interferences.

The set-up is pretty simple (see also these instructions if you get stuck), and should also work on Windows:

  1. If necessary, install VS Code (instructions for Windows / Mac / Linux) on your computer, and open it.

  2. Install the VS Code “Remote Development extension pack”: open the Extensions side bar (click the icon with the four squares in the far left), and in that side bar, search for “Remote Development extension pack”. That extension should appear with an Install button next to it: click that.

  3. Open the Command Palette (F1 or Ctrl+ShiftP) and start typing “Remote SSH”.

    Then, select Remote-SSH: Add New SSH Host… and specify your SSH connection: for Pitzer, this is ssh <osc-username>@pitzer.osc.edu, e.g. ssh jelmer@pitzer.osc.edu (you’ll have to do this separately for Owens if you want to be able to connect to both this way).

    In the “Select SSH configuration file to update” dialog, just select the first (top) option that shows up.

  4. You’ll get a “Host Added!” pop-up in the bottom-right of your screen: in that pop-up, click Connect.

  5. If you did the no-password setup described above (recommended!), 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.
    • If you’re asked whether you “Trust the Authors” of such-and-such directory, click Yes.
    • If there is a pop-up in the bottom-right asking you to update Git, click No and check “Don’t show again”.

You are now on a login node!

Just be aware that you’ll now be on a Login node (and not on a Compute node like when you use VS Code through OnDemand), so avoid running analyses directly in the terminal, and so on.



Back to top