The Linux Command Line Interface (CLI)

Learning Goals

Goals for this week's lab

  • Get to know the Linux Command Line Interface (CLI)
    • Understand its importance
    • Learn basic commands for
      • Navigation
      • Remote access
      • Networking-related tasks
    • Understand basic virtualization principles

General Overview

The preparations for this unit consist of three parts

  1. Practical:
    • Setting up the necessary programs to connect to the Virtual Machines (VM) that we'll use in this and upcoming labs, and
    • Trying out the commands from readings and videos on your own machine
  2. Reading up on background information about the command line and some basic functions
  3. Watching a few videos showcasing the use of those basic commands

You can complete these parts in any order you prefer, but we suggest setting up your own environment first and experimenting with the commands on your own machine as they come up in the videos and readings.

1) Practical

Setting up a Local CLI Environment on Your Own Machine

  • If you're using MacOS or a Linux distribution, you can summon a CLI environment by launching the Terminal app or your distribution's equivalent thereof.
  • For Windows users, we suggest setting up the Windows Subsystem for Linux (WSL) which will allow you to run a Linux command line on your Windows machine.
    • Follow steps 1-6 from the linked article and install a Linux distribution of your choice, for instance Ubuntu 20.04.
    • When launching the Ubuntu app for the first time, you'll be prompted to create a (local) user account. After picking a name and password of your choice, you'll be in a Linux CLI environment.
    • Future references to opening a terminal mean opening the Ubuntu app in your case.
    • Note: the home directory of your new user will be empty initially, but you can navigate to your regular Windows user folder by typing cd /mnt/c/Users/yourusername.

Connecting to the Remote Lab Virtual Machine (VM)

To reduce the load on your personal machines and give all groups a consistent experience, you will connect to virtual machines that run in NTNU's Skyhigh OpenStack cluster. You can get a quick summary about what VMs are in the following video. The figure below shows a brief overview of components and connections.

We can connect to remote (virtual) machines either via SSH if we only want to use the command line, or with tools such as VNC to also launch graphical applications.

You need to be in the NTNU network to connect to the VMs. This is automatically the case if you are on campus and using the eduroam WiFi. Otherwise, you can use the NTNU VPN service to connect to the NTNU network first.

Verifying that an SSH Client is Installed

MacOS and nearly all desktop Linux distributions come with an SSH client preinstalled and hence require no further installation. If you followed the installation of WSL above, the Ubuntu environment will also provide you with an SSH client. You can verify the availability of an SSH client by opening a terminal and typing ssh -V. Below, you can find the expected output for different platforms.

# WSL / Linux
stas@DESKTOP [~]
-> % ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.9, OpenSSL 1.1.1f  31 Mar 2020

# On a Mac
stas@stas-mbp [~] 
-> % ssh -V
OpenSSH_9.0p1, LibreSSL 3.3.6
# WSL / Linux
stas@DESKTOP [~]
-> % ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.9, OpenSSL 1.1.1f  31 Mar 2020

# On a Mac
stas@stas-mbp [~] 
-> % ssh -V
OpenSSH_9.0p1, LibreSSL 3.3.6

Connecting via SSH

On the day of the lab, you will receive the following credentials that will allow you to connect to your team's VM: user name, password, and IP address of the VM.

If you want to connect using SSH, you can open a terminal and type in ssh <user>@<ip>, replacing <user> and <ip> with the corresponding data from your credentials. You will then be prompted to provide the password and proceed to a command line environment on the remote VM where you can execute commands. Afterwards, you can quit the session by writing exit or hitting Ctrl+D on your keyboard. The output of a short example session is provided below. Notice how the beginning of the command prompt changes to netlab@netlab-linux:~$ after connecting, indicating that you are logged in as the user netlab on a host called netlab-linux.

stas@DESKTOP [~]
-> % ssh netlab@10.212.170.85
netlab@10.212.170.86's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-156-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 [...]
netlab@netlab-linux:~$ ls
Desktop  Documents  Downloads  GNS3  Music  Pictures  Public  Templates  Videos
netlab@netlab-linux:~$ exit
logout
Connection to 10.212.170.85 closed.
stas@DESKTOP [~]
-> %
stas@DESKTOP [~]
-> % ssh netlab@10.212.170.85
netlab@10.212.170.86's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-156-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 [...]
netlab@netlab-linux:~$ ls
Desktop  Documents  Downloads  GNS3  Music  Pictures  Public  Templates  Videos
netlab@netlab-linux:~$ exit
logout
Connection to 10.212.170.85 closed.
stas@DESKTOP [~]
-> %

Connecting via VNC

While the CLI environment will be sufficient to complete the first lab, we will start using some graphical programs from week 35 and will therefore connect to the remote VM's desktop using a VNC application. We will outline the use of TigerVNC since it has implementations for all major platforms, but any VNC client should work. You can find the installer here (tigervnc64-1.13.1.exe for Windows, TigerVNC-1.13.1.dmg for MacOS, sudo apt install tigervnc-viewer on Debian-based Linux distributions).

You will receive the credentials for connecting to the VM later. For now, you can continue with reading / watching the material in Sections 2 and 3.

Once installed, you can launch the TigerVNC Viewer and connect to the remote VM by providing its IP address and password (once inside the VNC client and once within the VM). Finally, you should see the remote desktop as outlined in the screenshots below.

There might be performance issues with VNC if you're idle for a prolonged period or reconnect after your host machine went to sleep with the VNC session open. In those cases, you can try logging in and out with the netlab user. To do this, click the mouse icon in the top left corner, click the "power button" at the bottom right of the resulting menu, and select the "Log Out" option. After this, you can reconnect with your VNC client and hopefully get improved responsiveness.

If you still experience performance issues using VNC, you can also try connecting to your lab VM using the x2go software. A guide for doing so can be found here. The only difference is that in your case the user name will be netlab instead of ttm4200.

2) Introduction to the CLI and Documentation of Important Commands

3) Videos on Basic Commands for Interacting with Files (Navigation, Manipulation, Search)

An introductory series on basic commands you'll use in the command line environment.

  • File system navigation and inspection (cd, ls, ..)
  • File system manipulation (cp, rm, ..)
  • Search and match inside files using grep. Note: the first five minutes are sufficient at this stage.
  • Printing file contents using cat
  • Getting help with man

Additional Resources

  • Unix/Linux Command Reference: handy overview of many commonly used commands and options.
  • explainshell.com: online tool that parses a given command and provides details on the command itself as well as the provided options / flags / arguments.
Edit this page