The terminal and remote login

Instructor note

Total: 30min (Teaching:20Min | Discussion:0min | Breaks:0min | Exercises:0Min | Type-along-pause:10 min )

Prerequisites

  • An active user account on one of the HPC systems (clusters)

  • Activated two-factor authentication (2FA)

Get a user account and access to a project

 https://www.sigma2.no/how-apply-user-account

Setup two-factor authentication (2FA)

Two-factor authentication (2FA) is now mandatory for all users. To setup 2FA, please follow the instructions here.

Objectives

  • Questions

    • What is UNIX ?

    • What is a terminal/Command line/UNIX shell, why do we need it

    • What do we mean by logging in to a remote system ?

    • What is ssh

  • keypoints

    • The UNIX terminal

    • The ssh program

    • Connect to a remote HPC system.

Instructor note

First excersice

  • Introduce the shared document

  • Short pause for people to log in

  • Open the shared document and start the discussion, while the learners type in answers

CLI (Command Line Interface)

Before we dive into what CLI is, let’s remind ourselves of how we ask a computer to do something for us.

What are the methods you know for interacting with a computer?

Use the interactive document to write down the answers

What is UNIX

UNIX is an Operating System(OS). An operating system is a software that makes a computer usable by managing the hardware, other software and automated tasks that are needed for the computer to work. Windows, MacOS, Android,Chrome OS and Ubuntu are some examples of operating systems. There are different flavors of UNIX, and except Windows, all the other examples above are flavors of UNIX. Versions of Windows 10 and newer have support to executing UNIX commands as well, while older versions do not.

What is a CLI

The CLI (Command Line Interface) also referred to as the Terminal/Command line/UNIX shell or UNIX terminal, is a user interface that interprets text inputs to machine-understandable instructions. Shell is a program that use this method of interface. There are different variants of the Shells as well and a common one is Bash, which we will focus on during this lesson. In addition to being a CLI, bash is also a scripting language.

We will use the term terminal to refer to the CLI and use the bash flavor of the shell.

Why do we need to use the terminal

  • Efficient way to achieve complex tasks. Some examples;

    • Rename 1000 files by prepending the string “latest” to their names

    • Group a collection of RAW, PNG and JPG files in sub-folders by their type

    • Extract the first 10 lines of 100 files and place it in a new file

    • Count how many lines start with a “>” in a file with 1 million lines. Then extract those matching lines to a new file.

  • Work on remote computers

  • Pipelines: combine multiple commands to achieve a repetitive task

Find my terminal

Visual Studio Code (VSCode) has a built-in terminal that can be used.

To open it, click the Toggle Panel toggle_panel_button button in the top right corner, or use the hotkey
⌘ Cmd+J or Ctrl+J, depending on your operating system.

VSCode terminal

Components of a terminal

A Terminal

Instructor note

Use the interactive document to vote for I found my terminal or I can not find my terminal

What is SSH (Secure Shell)

SSH is a protocol (established set of rules) used to make it possible for two computers to securely communicate over a network (internet is a (huge) network).

Logging in to a remote HPC system

The first step in using a cluster is to establish a temporary encrypted connection from our laptop to the cluster, via the Internet and/or your organization’s network using ssh.
Make sure you have a SSH client installed on your laptop terminal.

Test if ssh is installed before proceeding

Check ssh version

 [user@laptop ~]$ ssh -V

 OpenSSH_x.x xx, OpenSSL xxx xxx

ssh installed and OK to continue

Danger

[user@laptop ~]$ ssh -V

Command 'ssh' not found

Not OK! stop and inform instructor

Connect to cluster

Instructor note

Use the interactive document to vote for

  • I have ssh

  • I do not have ssh

  • I am lost, what you mean by ssh

Go ahead and log in to the cluster:

Remember to replace MY_USER_NAME with the username you received after registering for an account. You will be asked first for your two-factor authentication (2FA) code and subsequently for your password.

Warning

The characters you type after the two-factor authentication code and password prompts are not displayed on the screen. Normal output will resume once you type the code or password and press Enter.

We will use the Remote - SSH extension to connect to the remote machine.

  1. Click the monitor icon in the left sidebar to open the Remote Explorer view. remote_icon

  2. Click the + button to add a new SSH host.

remote_plus

  1. Enter the SSH connection string in the format USERNAME@saga.sigma2.no and press Enter.

remote_host

  1. You may be asked to edit an SSH configuration file. Select the default option and press Enter. It will most likely be called /home/USERNAME/.ssh/config, /Users/USERNAME/.ssh/config, or C:\Users\USERNAME\.ssh\config, depending on your operating system.

  2. Connect to the remote machine by clicking the Connect in Current Window button.

remote_connect

  1. Enter your 2FA code when prompted. Then enter your password.

remote_connect_movie

Where are we?

It is not uncommon that users think that a high-performance computing installation is one giant, magical machine. Sometimes, people will assume that the computer they’ve logged on to is the entire computing cluster. So what’s really happening? What computer have we logged on to? The name of the current computer we are logged onto can be checked with the hostname command. (You may also notice that the current hostname is also part of our prompt!)

[MY_USER_NAME@login-1.SAGA ~]$ hostname

login-1.saga.sigma2.no