# The terminal and remote login ```{instructor-note} Total: 30min (Teaching:20Min | Discussion:0min | Breaks:0min | Exercises:0Min | Type-along-pause:10 min ) ``` ```{prereq} - 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 `````{tabs} ````{group-tab} SAGA/Fram/Betzy https://www.sigma2.no/how-apply-user-account ```` ````{group-tab} FOX https://www.uio.no/english/services/it/research/platforms/edu-research/help/fox/account-login.md ```` ````` ## Setup two-factor authentication (2FA) Two-factor authentication (2FA) is now mandatory for all users. To setup 2FA, please follow the instructions [here](https://documentation.sigma2.no/getting_help/two_factor_authentication.html). ```{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. ```{exercise} 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 `````{tabs} ````{group-tab} Visual Studio Code Visual Studio Code (VSCode) has a built-in terminal that can be used. To open it, click the `Toggle Panel` ![toggle_panel_button](vscode/toggle_panel_icon.png) button in the top right corner, or use the hotkey
⌘ Cmd+J or Ctrl+J, depending on your operating system. ![VSCode terminal](/images/vscode_terminal_2.png) ```` ````{group-tab} Default system terminal Most operating system flavors will bring up the default terminal using one of the two methods described below. Do not worry if your default terminal does not support all `bash` commands we will be using in this lesson, as we will use the default terminal only to establish connection to the remote HPC system. The rest of the commands will be executed on the remote HPC system itself. ```{instructor-note} Try to show how to locate the terminal using different methods and on different operating systems if possible. ``` * `ALT + CTRL + T` (press down ALT key, CTRL key and then press the T) OR * In the program search box type `terminal` #### Windows This is how it looks like in Windows when you search for the terminal. ![Windows search](/images/windows_terminal.png) #### MacOs And this is how it looks like in Mac when you search for your terminal. ![Mac search](/images/mac_terminal.png) #### What if you did not find a terminal? If the above methods failed to locate the terminal, then do an internet search "how to open terminal on MY-OS-NAME" where MY-OS-NAME is the operating system you are on. If you are on an older Windows version (Windows 7) you could download the program called [Git SCM to Windows](https://gitforwindows.org/) and that will be your terminal to connect to the HPC system. ```` ````` ### Components of a terminal ![A Terminal](/images/terminal.svg) ```{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 ````{exercise} Check ssh version ```console [user@laptop ~]$ ssh -V OpenSSH_x.x xx, OpenSSL xxx xxx ``` **ssh installed and OK to continue** ```` ````{danger} ```console [user@laptop ~]$ ssh -V Command 'ssh' not found ``` **Not OK! stop and inform instructor** ```` ![Connect to cluster](/images/connect-to-remote.svg) ```{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`. ``` `````{tabs} ````{group-tab} Visual Studio Code ```{admonition} Installing VSCode SSH extension :class: warning :class: dropdown Before we begin, we must install the `Remote - SSH` extension in Visual Studio Code. This extension allows you to connect to a remote machine and work on files as if they were stored locally on your machine. 1. Click the blocks icon in the left sidebar to open the **Extensions** view. ![extensions_icon](/images/vscode_extensions_icon.png) 2. Search for `Remote - SSH` in the search bar. 3. Click the **Install** button to install the extension. ``` 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](/images/vscode_remote_icon.png) 2. Click the **+** button to add a new SSH host. ![remote_plus](/images/vscode_remote_plus.png) 3. Enter the SSH connection string in the format `USERNAME@saga.sigma2.no` and press **Enter**. ![remote_host](/images/vscode_remote_host.png) 4. 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. 5. Connect to the remote machine by clicking the **Connect in Current Window** button. ![remote_connect](/images/vscode_remote_connect.png) 6. Enter your 2FA code when prompted. Then enter your password. ![remote_connect_movie](/images/vscode_remote_recording.gif) ```` ````{group-tab} Default system terminal ```{literalinclude} snippets/saga/12-login.txt :language: terminal ``` ```` ````` ## 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!) ```{literalinclude} snippets/saga/12-hostname.txt :language: bash ```