1 of 2

Name:

PID:

ssh <username>@<servername>

ssh switches your terminal's context to running commands on another computer. It stands for "secure shell". A shell is the program running in your terminal, or on another computer, to run commands. Depending on how the other computer, and your account, is set up, commands may work a little differently in the remote shell compared to on your computer. The commands will be working with the filesystem from that computer.

What are some reasons you might want to run commands on a computer that isn't the one you're physically logged into? Discuss with the people around you, and write down some thoughts.

joes-computer $ ssh cs15lsp23zz@ieng6.ucsd.edu

(cs15lsp23zz@ieng6.ucsd.edu) Password: <type in password>

... lots of messages about the server ...

Sun Sep 25, 2022 8:26pm - Prepping cs15lsp23

[cs15lsp23zz@ieng6-203]:~:212$ cat WhereAmI.java

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"));

}

}

[cs15lsp23zz@ieng6-203]:~:213$ javac WhereAmI.java

[cs15lsp23zz@ieng6-203]:~:214$ java WhereAmI

Linux

cs15lsp23zz

/home/linux/ieng6/cs15lsp23/cs15lsp23zz

/home/linux/ieng6/cs15lsp23/cs15lsp23zz

[cs15lsp23zz@ieng6-203]:~:215$ exit

logout

Connection to ieng6.ucsd.edu closed.

joes-computer $ javac WhereAmI.java

joes-computer $ java WhereAmI

Mac OS X

joe

/Users/joe

/Users/joe/lecture2

[ieng6]:~$ ls

WhereAmI.java example

[ieng6]:~$ cd example/

[ieng6]:example$ ls

[ieng6]:example$ cat message.txt

cat: message.txt: No such file or directory

[ieng6]:example$ exit

logout

Connection to ieng6.ucsd.edu closed.

joes-comp $ ls

message.txt

joes-comp $ scp message.txt cs15lsp23zz@ieng6.ucsd.edu:~/example/

(cs15lsp23zz@ieng6.ucsd.edu) Password:

message.txt 100% 7 0.6KB/s 00:00

joes-comp $ ssh cs15lsp23zz@ieng6.ucsd.edu

(cs15lsp23zz@ieng6.ucsd.edu) Password:

...

Sun Sep 25, 2022 8:53pm - Prepping cs15lsp23

[logout]:~:224$ ls

WhereAmI.java example-lecture-2

[logout]:~:$ cd example

[logout]:example:$ cat message.txt

hello!

scp <file1> <file2> <username>@<servername>:<path>

scp copies files from one computer to another; it stands for "secure copy". It uses the same accounts and logins as ssh, so if you can ssh into a computer, you can copy files to it with scp.

What do you notice and wonder about these terminal interactions? What's new? What's confusing?

You all have accounts specific to CSE15L on a server called ieng6.ucsd.edu that is managed by UCSD. A server is another word for a computer or a program running on a computer that enables communication to other programs and computers – ssh is one of the programs that does this communication.

2 of 2

Name:

PID: (page 2)

import java.io.IOException;

import java.net.URI;

// This interface is defined in another file (we provide it in lab 2)

// interface URLHandler { String handleRequest(URI url); }

// URI is a built-in Java class with methods like getPath() and getQuery()

class Counter implements URLHandler {

int num = 0;

public String handleRequest(URI url) {

System.out.println(url);

if (url.getPath().equals("/")) { return String.format("Number: %d", num); }

// FILL in the block below to match the behavior in the browser below!

else if (url.getPath().equals("/count")) {

} else {

return "Don't know what to do with that path!";

}

}

}

class CounterMain {

public static void main(String[] args) throws IOException {

int port = Integer.parseInt(args[0]);

// We wrote Server; it is a very short class (you can see it in Server.java in lab 2)

Server.start(port, new Counter());

}

}

local $ javac Server.java Counter.java

local $ java CounterMain

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

at CounterMain.main(Counter.java:24)

local $ java CounterMain 4000

Server Started! Visit http://localhost:4000 to visit.

Counter.java

What do you notice and wonder about this program?

Assume the WhereAmI.java file we've been using as an example is stored in the root folder of a Github repository at https://github.com/ucsd-cse15l-f22/WhereAmI

What commands should we use to compile and run the WhereAmI.java file at this point?

local $ ssh cs15lsp23zz@ieng6.ucsd.edu

remote $ git clone https://github.com/ucsd-cse15l-w23/WhereAmI

remote $