Week 1

Week 1 – Remote Access and the Filesystem

This is not the current offering of the course. You may want the next offering at https://ucsd-cse15l-w23.github.io/, or scroll down for the fall 2022 material.

Lecture Materials

Notes from class

Monday 12pm

Monday 1pm

Wednesday 12pm

Wednesday 1pm

Note: Links will require you to log in as a UCSD student

Lab Tasks

As usual, you can read ahead and are encouraged to prepare! Keep in mind that the lab isn’t guaranteed to be final until the day of the lab, and a lot of the exercises are collaborative, so you can’t truly “finish it ahead of time”.

In this lab you’ll set your computer up for remote access to the CSE lab computers (or log into them directly) and practice with commands that work with the filesystem. You can bring a laptop and work on that, or you can come and use the computers in the lab directly, whichever you prefer.

Part 1 – Meet Your Group!

We’ve organized everyone into groups of 6-8 students for discussion. These groups will be somewhat stable throughout the quarter, though some small changes will likely happen. You will have a tutor or TA assigned to your group for help and discussion.

Your discussion leader will share a Google Doc with your group where you can fill in notes as you work; this document is only for your group. Your discussion leader will not take notes for you, you can have someone volunteer to take notes or come up with a way to share the role.

Write down in notes In your groups, share, and note in the running notes document (discussion leaders, you answer these as well!):

  • How you’d like people to refer to you (pronounce your name/nickname, pronouns like he/her/they, etc)
  • Your major
  • One of:
    • A UCSD student organization you’re a member of or interested in
    • Your favorite place you’ve found on campus so far
    • A useful campus shortcut or trick you know

Part 2 – Your CSE15L Account

Look up your course-specific account for CSE15L here:

https://sdacs.ucsd.edu/~icc/index.php

For help on resetting your password here is a tutorial.
[TUTORIAL] How to Reset your Password

Part 3 – Visual Studio Code

In Your Group for 10 minutes

Go to the Visual Studio Code website https://code.visualstudio.com/, and follow the instructions to download and install it on your computer. There are versions for all the major operating systems, like OSX (for Macs) and Windows (for PCs). If you only have access to a tablet or Chromebook while remote, you won’t be able to install it right now. If you don’t, you should chat your lab leader and let them know, and for any pair activities this week and next we will make sure to pair you with someone who does.

If you run into an error installing Visual Studio Code, speak up! You can screenshare and ask for help, and the tutor or someone in your group might be able to answer for you!

When it is installed, you should be able to open a window that looks like this (it might have different colors, or a different menu bar, depending on your system and settings):

/images/vscode.png

Write down in notes: Everyone should share a screenshot of VScode open – help folks figure it out if it won’t install. If someone gets stuck, take a screenshot of the error message or point at which they are stuck so we can help them figure it out later, and they can decide to keep trying (potentially with the tutor helping) or move on.

Part 4 – Remotely Connecting

In Your Group for 15 minutes

Note In this section, whenever you see a chunk of code in light gray, we are specifying that the code block is running on the remote server. For example:

  $ this is a command to the remote server
  $ this is a command on your own computer

Many courses in CSE use course-specific accounts. These are similar to accounts you might get on other systems at other institutions (or a future job). We’ll see how to use VScode/terminal to connect to a remote computer over the Internet to do work there.

There is a first step you need if you’re on Windows: install a program called OpenSSH, which is a program that can connect your computer to other computers that have this kind of account. You should only install the OpenSSH client, not the server:

Install OpenSSH

Then, in Visual Studio Code, we are going to connect to the remote computer using VSCode’s remote option. For reference, we’re following the steps in “Connect to a remote host” step.

For the first step, open a terminal in VSCode (Ctrl or Command + `, or use the Terminal → New Terminal menu option). Your command will look like this, but with the zz replaced by the letters in your course-specific account.

$ ssh cs15lfa22zz@ieng6.ucsd.edu

(That’s one, five, l (not one); the one and l look very close in some fonts.)

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

⤇ ssh cs15lfa22zz@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])? 

I (Joe) always say yes to these messages when I’m connecting to a new server for the first time; it’s expected to get this message in that case. If you get this message when you’re connecting to a server you connect to often, it could mean someone is trying to listen in on or control the connection. This answer is a decent description of what’s going on: Ben Voigt’s answer

So type yes and press enter, then give your password; the whole interaction should look something like this once you give your password and are logged in:

# On your client
⤇ ssh cs15lfa22zz@ieng6.ucsd.edu
The authenticity of host 'ieng6-202.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])? 
Password: 
# Now on remote server
Last login: Sun Jan  2 14:03:05 2022 from 107-217-10-235.lightspeed.sndgca.sbcglobal.net
quota: No filesystem specified.
Hello cs15lfa22zz, you are currently logged into ieng6-203.ucsd.edu

You are using 0% CPU on this system

Cluster Status 
Hostname     Time    #Users  Load  Averages  
ieng6-201   23:25:01   0  0.08,  0.17,  0.11
ieng6-202   23:25:01   1  0.09,  0.15,  0.11
ieng6-203   23:25:01   1  0.08,  0.15,  0.11

Sun Jan 02, 2022 11:28pm - Prepping cs15lfa22

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! When you ask, take a screenshot of your problem and add it to your group’s running notes document, then describe what the fix was. If you don’t know how to take a screenshot, 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. I look up the right way to describe the (yes/no) answer on first login all the time, for example. So you are helping your group learn about potential issues when you do this, and that’s a major learning outcome of the course! If you see someone else have an issue that you didn’t, ask why, and what might be different about what you did, or how your environment is set up. You will learn by reflecting on this.

Write down in notes When you’re done, discuss what you saw upon login. Take a screenshot or copy/paste the output. Did you all see the same thing? What might the differences mean? Note the results of your discussion in the notes document.

Part 5 – Run Some Commands

Try running the commands cd, ls, pwd, mkdir, and cp a few times in different ways, both on your computer, and on the remote computer after ssh-ing. Discuss in your group what you see. Can you cause them to produce error messages? What do they mean? If you’re on Windows, what happens when you use them on Windows?

Here are some specific useful commands to try:

  • cd ~
  • cd
  • ls -lat
  • ls -a
  • ls <directory> where <directory> is /home/linux/ieng6/cs15lfa22/cs15lfa22abc, where the abc is one of the other group members’ username
  • cp /home/linux/ieng6/cs15lfa22/public/hello.txt ~/
  • cat /home/linux/ieng6/cs15lfa22/public/hello.txt

Write down in notes: Copy at least one example from each group member, with an explanation, into your shared notes doc.

Hint: To log out of the remote server in your terminal, you can use:

  • Ctrl-D
  • Run the command exit

You can also open more terminals in VSCode (there is a little + button at the top of the terminal window where you can create another).

Part 6 – Moving Files over SSH with scp

So far we’ve seen how we can do some work on local and remote computers. One key step in working remotely is being able to copy files back and forth between the computers. There are lots of options for how to do this – you might have done it yourself in the past by sending yourself an email, or storing it in Google Drive or Dropbox and accessing it from the another computer later.

We’ll see now another way to copy a file (or many files!) from your computer to a remote computer. The command is called scp, and we will always run it from the client (that means from your computer, not logged into ieng6). Create a file on your computer called WhereAmI.java and put the following contents into it:

class WhereAmI {
  public static void main(String[] args) {
    System.out.println(System.getProperty("os.name"));
    System.out.println(System.getProperty("user.name"));
    System.out.println(System.getProperty("user.home"));
    System.out.println(System.getProperty("user.dir"));
  }
}

Compile and run the WhereAmI program using the javac and java commands below.

javac WhereAmI.java
java WhereAmI

What do you see? (If you don’t have java installed on your computer, skip this step).

Then, in the terminal from the directory where you made this file, run this command (as usually, using your username):

scp WhereAmI.java cs15lfa22zz@ieng6.ucsd.edu:~/

You should be prompted for a password just like when you log in with ssh. If you get errors, ask your group members for help! You’ll all learn.

Then, log into ieng6 with ssh again, and use ls. You should see the file there in your home directory! Now you can run the program on the ieng6 computer using the same javac and java commands from before.

javac WhereAmI.java
java WhereAmI

Since java is installed on the server, everyone should be able to run it no matter the client.

Write answer in notes: Try to get a screenshot of everyone successfully *using scp and ssh. If someone can’t, no worries! Get a screenshot of where *they got stuck (don’t try to resolve an error for more than a few minutes) and *put that in the notes so we can help with it later.

Write answer in notes: What’s different about the output when you run this on the client vs. the server? What does this mean for what getProperty does?

What we see here is one solution for running code remotely – we can copy files to a remote server with scp, then log in and run them there.

Before you go on, do the following:

  • Have someone on your team start a timer
  • Make a change to WhereAmI.java and save the file
  • Copy the file to the remote server
  • Log into the remote server and run the file
  • Stop the timer

Write answer in notes: How long did it take you? (Not everyone has to do this, but someone should.) Assume you’d have to do this process 100 times over the course of a PA. How long would you spend copying and running the file?

Part 7 – SSH Keys

So far, we’ve seen how to log in, run commands, and copy files to a remote server with ssh and scp. Every time we log in or run scp, we have to type (or copy-paste) our password. This is frustrating, time consuming, and interrupts whatever task we were trying to do. Naturally, we should look into if there are ways to avoid this repetitive, frustrating task with a configuration or program.

In this case, there is a great solution – ssh keys. The idea behind ssh keys is that a program, called ssh-keygen, creates a pair of files called the public key and private key. You copy the public key to a particular location on the server, and the private key in a particular location on the client. Then, the ssh command can use the pair of files in place of your password. This is a common setup step in lots of work environments that involve code on a server.

Here’s what you should run to set this up:

# on client (your computer)
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/joe/.ssh/id_rsa): /Users/joe/.ssh/id_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/joe/.ssh/id_rsa.
Your public key has been saved in /Users/joe/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:jZaZH6fI8E2I1D35hnvGeBePQ4ELOf2Ge+G0XknoXp0 joe@Joes-Mac-mini.local
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|       . . + .   |
|      . . B o .  |
|     . . B * +.. |
|      o S = *.B. |
|       = = O.*.*+|
|        + * *.BE+|
|           +.+.o |
|             ..  |
+----[SHA256]-----+

Note: When given the prompt Enter file in which to save the key (/Users/joe/.ssh/id_rsa): press enter again to specify the default path and take note of it. In this case, the default path is /Users/joe/.ssh/id_rsa.

If you’re on Windows, follow the extra ssh-add steps here: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement#user-key-generation

This created two new files on your system; the private key (in a file id_rsa) and the public key (in a file id_rsa.pub), stored in the .ssh directory on your computer.

Now we need to copy the public (not the private) key to the .ssh directory of your user account on the server.

# on client
$ ssh cs15lfa22zz@ieng6.ucsd.edu
<Enter Password>
# now on server
$ mkdir .ssh
$ <logout>
# back on client
$ scp /Users/joe/.ssh/id_rsa.pub cs15lfa22@ieng6.ucsd.edu:~/.ssh/authorized_keys
# You use your username and the path you saw in the command above

Once you do this, you should be able to ssh or scp from this client to the server without entering your password.

Write down in notes: Try to get everyone to the point where they can do this, and take a screenshot of logging in without a password. If you can’t, share a screenshot and description of where you got stuck!

Write down in notes: Repeat the timing experiment of editing and running WhereAmI.java now that you don’t have to use a password. How much time is saved per run?

Part 8 – Making Remote Running Even More Pleasant

Use what you’ve learned to come up with the most pleasant process you can for making a local edit to WhereAmI.java, then copying it to the remote server and running it.

Some hints:

  • You can write a command in quotes at the end of an ssh command to directly run it on the remote server, then exit. For example, this command will log in and list the home directory on the remote server:

    $ ssh cs15lfa22@ieng6.ucsd.edu "ls"
    
  • You can use semicolons to run multiple commands on the same line in most terminals. For example, try:

    $ cp WhereAmI.java OtherMain.java; javac OtherMain.java; java WhereAmI
    
  • You can use the up-arrow on your keyboard to recall the last command that was run

Write down in notes First try using just what we learned in this lab, and document the best process you came up with. Try to get the total time for a run after editing and saving to under 10 total keystrokes/mouse clicks, including all typing. A “keystroke” is pressing one key on your keyboard. For example, pressing the up arrow counts as one keystroke, and typing “java” counts as 4.

If you have more time, brainstorm other ideas or search for other ways you might easily run remote code.

Part 9 – Wrapup

Discuss with your team – do you have any open questions about things you saw that you don’t understand? Write them down in your notes document or ask your tutor. Even if they don’t know, writing them down means we can come back to them later!

If you didn’t get everything to work, that’s OK! Keep trying and make sure your tutor knows if you’re totally stuck getting something set up; we’ll be posting some office hours soon where you can come to get unstuck as well.

Before you leave the lab, head to the assignment “Lab1 Participation” on Gradescope and complete it. It only has a couple of questions and is not going to take more than 2 minutes. This assignment will be used to award you participation credit for this lab. Please note that you will be receiving full credit for participation only if you have attended the lab in-person and actively engaged in discussions with your group.

Remote Login FAQ

Logging in with ssh doesn’t work

Make sure you are logging in with your account and not cs15lfa22 (we’ve seen lots of failed login attempts with Joe’s account).

If you feel stuck, tell us on Piazza, but give us lots of information. Like, lots. Just “it doesn’t work” is not enough for us to go on.

Make sure to include:

  • Your username (cs15lfa22XX, where XX is specific to you)
  • Screenshots of going through the password reset workflow from the tutorial
  • A screenshot or copy/paste of what a failed login attempt looks like (this helps us double-check your command line)

In general, this is a good lesson in how to ask good questions and report good issues. The more information you give, the more the person trying to help you can help!

I’ve been able to successfully log in using my active directory username and password. Can I complete the assignment using that?

This is fine for this lab, but in future labs it’s useful to have the cs15l-specific account set up. Go ahead and complete the lab with that account, but come to office hours so we can help diagnose the issue with your course-specific account.

I’ve been able to successfully log in using an account the TA temporarily shared with me during lab. Can I complete the assignment using that?

No, because sometimes we change passwords and permissions on these accounts, and having dozens of students using the same account doesn’t work well (for example, there’s only one authorized_keys file, and lots of folks writing over it at the same time doesn’t work well!)

I tried all that and it still doesn’t work and I give up.

Note that in the lab report below, it says to describe what happened if you can’t complete a step! Describe your stuck-ness in detail, and that counts as doing the report. Then come to office hours so we can help diagnose the issue.

Week 1 Lab Report

Friday, September 30, you’ll submit a lab report by writing a blog post like we just described. The topic will be remote access.

You will write a tutorial for incoming 15L students (and your future self!) about how to log into a course-specific account on ieng6. Your post should include the steps you took, along with screenshots of what each step looked like. You’re free to use the screenshots you took for lab 1, or new ones. Complete any steps you didn’t complete in your group on your own.

Overall, make sure you have at least 6 screenshots, one for each of the steps below (though more is useful, remember that this will help out your future self). For each step include 2-3 sentences or bullet points describing what you did. If for some reason you didn’t do the step exactly, describe why not (maybe your computer already had something on it, maybe the department computers worked differently, etc).

  • Installing VScode
  • Remotely Connecting
  • Trying Some Commands
  • Moving Files with scp
  • Setting an SSH Key
  • Optimizing Remote Running

You should complete the writing on your own. Feel free to ask anyone (staff or other students are fine!) for help if you’re struggling to get remote access set up, understand commands, get your writing to show up on Github Pages, etc. But do not get help from anyone on authoring the report itself – the writing and screenshots must be your own.

You will upload your submission by publishing the page on Github Pages, then printing the page to PDF and uploading to the Lab Report 1 assignment on Gradescope.

Submission FAQ

Should I submit the Google Doc we used during the lab session for this Lab Report Assignment?

No, this individual lab report submission is about the screenshot tutorial you’ll put on your own Github Pages.

You need not upload the shared notes Google doc anywhere.

How do I submit my Github Pages site to Gradescope?

Visit the page with your tutorial in a browser (Safari, Chrome, Brave, Firefox, Edge, etc), and use “Print” to save it to a PDF. Then upload the PDF to the “Lab Report 1 - Remote Access and Filesystem” assignment on Gradescope.

Can I use screenshots from the lab document we worked on together?

Sure! If they are from your account, that’s fine. If you were unable to get your ssh login to complete all these steps, don’t share another user’s screenshots, instead describe where you got stuck.