Lab 1: Unix, SSH, and Vim

Table of contents

  1. Lab Logistics
  2. The Terminal
  3. Remotely Connecting
  4. Basic UNIX Commands
    1. “Where am I?”
    2. Looking and Moving Around
    3. Creating New Things
    4. Opening Things
  5. The Vim Text Editor
  6. More Practice

In this lab, you’ll set your computer up for remote access to the CSE lab computers and practice with commands that work with the filesystem.

Lab Logistics

In this class, you are assigned to lab sections, in which you will be in the CSE basement lab rooms to work hands-on on activities related to the tools and techniques that you’ll be using on programming assignments.

Labs are graded by participation, based on your attendance and engagement with the lab activity. You will not need to submit anything at the end of the lab, but we will leave instructions throughout the lab activity for you to checkoff your work with a tutor. This helps us ensure that you are following the lab activity.

If you finish the lab activity early, we strongly encourage you to begin working on the programming assignment, which will have been recently released and related to the lab activity you just did. Take advantage of this time to get help from tutors!

The Terminal

If your device runs Windows, we strongly encourage you to install Windows Subsystem for Linux (WSL) so that you also have access to a UNIX-like environment. You can find instructions for installing WSL here on the official Microsoft website. This process may be a little complicated, so please feel free to ask a tutor for help!

If your device runs MacOS or Linux, then you can directly access a terminal on your device.

  • MacOS: Click the Launchpad icon in the Dock, type in “Terminal”, then select the Terminal application.
  • Linux: Press Ctrl+Alt+T to launch a terminal window.

Remotely Connecting

As a student, you are assigned an account on the ieng6 server hosted by UCSD. These are similar to accounts you might get on other systems at other institutions (or a future job). We’ll see how to use your machine to connect to a remote computer over the Internet to do work there.

Your account name is the same account name as the one that’s used for your school Google account, i.e. it is the string that precedes “@ucsd.edu” in your school email address. In case you need to check the status of your student account, refer to the UCSD Student Account Lookup page.

For the first step, open a terminal. Your command will look like this, but with the aname replaced by your account name.

$ ssh aname@ieng6.ucsd.edu

Since this is likely the first time you’ve connected to this server, you will probably get a message like this:

$ ssh aname@ieng6.ucsd.edu
The authenticity of host 'ieng6.ucsd.edu (128.54.70.227)' can't be established.
RSA key fingerprint is SHA256:ksruYwhnYH+sySHnHAtLUHngrPEyZTDl/1x99wUQcec.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Copy and paste the one of the corresponding listed public key fingerprints and press enter. We do this for complicated security reasons.

  • If you see the phrase ED25519 key fingerprint answer with: SHA256:8vAtB6KpnYXm5dYczS0M9sotRVhvD55GYz8EjN1DYgs
  • If you see the phrase ECDSA key fingerprint answer with: SHA256:/bQ70BSkHU8AEUqommBUhdAg0M4GaFIHLKq0YQyKvmw
  • If you see the phrase RSA key fingerprint answer with: SHA256:npmS8Gk0l+zAXD0nNGUxr7hLeYPn7zzhYWVKxlfNaeQ

After this, you get a prompt to enter your password. This is the same password you use to log into your student account on other websites, like Canvas and Tritonlink. The terminal itself does not show what you type when you enter your password. This is conventionally done for your own security, so that others looking at your screen don’t see it. Just trust that it gets inputted when you type.

Now your terminal is connected to a computer in the CSE basement, and any commands you run will run on that computer! We call your computer the client and the computer in the basement the server based on how you are connected.

If, in this process, you run into errors and can’t figure out how to proceed, ask! Remember – it is rare for a tutorial to work perfectly. We often have to stop, think, guess, Google search, ask someone, etc. in order to get things to work the way the tutorial says.

To exit out of the ieng6 server and return to running commands on your local device, type exit as a command—hey hey, don’t exit yet! The rest of the lab will involve working in your ieng6 account.

Basic UNIX Commands

Navigating the terminal is like navigating a text-based adventure game: you have a limited set of commands which you can use on a limited set of objects in order to interact with the environment.

To review from lecture, the files in your system are organized into folders (which are conventionally called “directories”). Directories are often nested within each other to create a highly organized structure.

“Where am I?”

The location in the filesystem in which you are currently is called the “working” directory. You can use the pwd command to print the name of the working directory.

$ pwd
/home/aname

The $ symbol is the prompt. In the terminal, it represents that you can type commands after this symbol to execute them. It is conventional to include $ when giving examples of commands to make it clear that they are user-written commands, as opposed to output from a command.

Looking and Moving Around

You can’t do much without knowing what exists in the current working directory to interact with. You can use the ls command to list out the contents of the current working directory.

$ ls
folder
hello.txt

Most commands will have multiple pre-defined options which allow you to modify the behavior of a command. Options are usually written as a dash (-) followed by a few letters. Some common options for the ls command include:

  • -a: list all files, including hidden files
  • -l: list in a long format, which shows additional information, such as permissions and time of creation
  • -la: enables both the -a and -l options for the same command

You can change your working directory to a different directory using the cd command with the destination directory as an argument.

$ cd folder
$ pwd
/home/aname/folder

There are also built-in symbols which refer to locations in the filesystem that you can use as arguments to commands.

  • / (slash) represents the root directory, which is the top-most directory in a file system. It has to start somewhere!
  • ~ (tilde) represents the home directory, which is usually a specific directory assigned to each user on a system.
  • . represents the current directory.
  • .. represents the parent directory, i.e. the directory in which this directory is contained.

For example, to navigate to the home directory from anywhere, you can use the command:

$ cd ~

To list out the contents of the parent directory, with a long format and including hidden files, you can use the command:

$ ls -la ..

Creating New Things

You can use the mkdir command to make a new directory with the given name as an argument.

$ mkdir nestedfolder
$ ls
nestedfolder

By default, the output of a command is printed out to the screen. But we can redirect the output into files using the > character. For example:

$ pwd > mylocation.txt

Takes the output from pwd and redirects it into a new file called mylocation.txt (thus it does not print to the terminal).

Opening Things

You can use the cat command to display the contents of a file. This command is designed to be used to concatenate files, but it is also commonly used to print out things.

$ cat mylocation.txt
/home/aname/folder

Now let’s practice a bit with these commands to create an organization setup for this class.

  1. Navigate to your home directory if you aren’t already there.
  2. Create a directory called cse29 and change into this directory. This is where we’ll keep all the files you use in this class organized in one place.
  3. Then, create a directory called lab1 and change into this directory. This is where we’ll keep all the files you practice with in this lab activity organized in one place.

At this point, you should call over a tutor to checkoff on your progress before continuing to Vim.

The Vim Text Editor

Back in my day, before we had IDEs, we had to write all our code in the terminal with Vim, and we liked it!

Up till now, you have most likely been programming in a graphical editor where you could click around with a mouse and highlight things by clicking and dragging.

But CSE 29 is cool. And using the mouse is decidedly uncool (in our view). So we are now going to learn a keyboard-based editor. Because you will spend the entire quarter inside the terminal (and you will love it), knowing how to use a text-based editor like what we are about to introduce is incredibly crucial.

After all, all the awesome hackers in movies are always typing, have you seen a single movie hacker clicking around with a mouse? Blurgh.

Our terminal-based editor is called vim. It’s an incredibly powerful editor once you learn how to use it properly. However, the learning curve is very steep, which is why the more you practice in these earlier weeks, the better.

Conveniently (for both you and I), vim comes with its own tutorial program called vimtutor. For the remainder of today’s lab, you will follow this tutorial to get familiar with the basics of the vim editor.

Before going through the tutor, here are a few things to note:

  1. You should read everything very carefully. Do not miss a single sentence.
  2. Try to spend as much time experimenting and practicing as possible as you complete the tutorial. Repetition is key in becoming a proficient vim user.
  3. If you are short on time, you should prioritize the following lessons in the tutorial:
    • Lesson 1 (full)
    • Lesson 2.1-2.3
    • Lesson 2.6-2.7
    • Lesson 3.1-3.2
    • Lesson 4.1-4.2
    • Lesson 6.4
  4. Capitalization matters: For intsance, Lesson 1.5 (“Text Editing - Appending”) says “Press A to append text”, you need to enter an uppercase A, which means pressing Shift-a, or pressing A with the caps lock on.

Now you are ready to begin the tutorial! Take it slow and be very thorough. Enter the following command to start:

$ vimtutor

This should take around 25-30 minutes, but feel free to take a bit more time to get familiar with using Vim.

More Practice

Once you’ve completed vimtutor, let’s practice navigating the filesystem and writing files.

{. :note} The vimtutor program was, in fact, one big vim session. The commands and keyboard operations you learned in vimtutor can all be used when you’re using actual vim.

In the lab1 folder, create a new file and write some text in it using vim. (Try to practice the commands you learned in vimtutor!) The name of the file and its contents aren’t too important. Write out an inspiring quote, a line of poetry/lyrics, or your credit card number and the three funny numbers on the back a nice message for the staff team.

Feel free to create some more files/directories and write some more things in files, to get familiar with the filesystem and using Vim.

When you feel like you’ve done enough, call over a tutor to be checked off for this activity.