The Story So Far

Pretend that you are still a graduate student at Purdue University, and you have some computations to run. Your personal computer isn't very reliable, or very fast - you can't trust it.

You are going to need the power that comes from working at an institution. Namely, the power in the basement of the math department behind all those locked doors and cameras.

Even in the best of times, you couldn't just walk in there and plug a keyboard in to the mainframe, so we are going to use the power of those computers from our own home.

So you ask your advisor where to run your compute job - they have the channels for requesting server time - and they tell you that, for the small job you are interested in, the general purpose server banach is fine.

Connecting to the server

You first want to make sure that you can connect, so do:

ssh {your purdue username}@banach.math.purdue.edu

For example, your instructor would put

ssh bradfor3@banach.math.purdue.edu

But you shouldn't because you don't know the password to that account. Log in to your own account.

It'll probably warn you that you are connecting to an unknown server. And you are. But you are a daredevil, so you will do it anyway - answer the prompt with a y for "yes".

Now it is asking for a password. This would be your purdue password, the one you used to use for things before BoilerKey came along.

Once you are through, take a look around - you know how, now - and remember all your old files and all the good times you had.

Then type exit and hit return - we're leaving for now.

Copying your script

Pretend you have put together a python script that, with the university's resources, should take about 5 minutes to run. After that, it will helpfully write what it calculated in a text file.

But you put it together on your local machine, in a folder (click that link to download it and unzip it in your project directory) - and now you need it on the remote machine.

Enter scp. It's a lot like cp - the local copy command - but you can do it over ssh connections between machines.

The syntax is simple:

scp {source} {target}

In this case,

scp -r fiveminutetask {your username}@banach.math.purdue.edu:~/

Two things to note there: the :~/ means "at the server specified, in the directory ~" - where you want to copy the files to.

-r is a "recursive copy", which lets you copy directories and not just files.

Log in

Log back in to banach, and run a quick ls - and if you did everything right, you should find your folder! cd into it and let's get this party started.

Running the script

This is pretty simple. It is a python script, so let's give it to Python to run:

python fiveminutetask.py

Regretting your choices - and undoing them

Do you really want to sit here for the full computation time? No. That is boring.

Enter the key-combination ctrl-c to stop the current process.

Fortunately, two generous Germans agreed that staying logged in is boring and unreliable, and created screen.

screen lets you run lots of terminals in your terminals - to do many things - and it is worth learning more about someday. But for now, we are going to use one of its most useful features:

Attaching and detatching.

Entering screen is simple:

screen

Once you have entered screen everything looks... the same. this is a german trick. We are now one layer deeper in this dream sequence.

Run the python command again:

python fiveminutetask.py

and then press the key sequence ctrl-a d

Now it should say you have Detached. we're back outside of screen, but things are still happening in the screen world.

exit out of banach. We're done here for now - we have just saved ourselves five minutes of waiting, and we are going to use them to save us even more time and hassle.

SSH Keys

Typing (or, copy-pasting, if you use managed passwords - I recommend KeePass 2) your password every time you connect is tedious.

We've done it three times already! Enough is enough.

There must be a better way.

Enter the power of number theory.

Fortunately, the computer can handle all the numbers for us.

enter:

ssh-keygen

Enter file in which to save the key:

Accept the default location, it's a good place for this stuff.

Enter passphrase (empty for no passphrase):

What's this mess about a password? Well, without it anyone could steal your key and use it. So we are going to give this one a nice strong password.

It will be able to let us access all kinds of servers - multiple in this class - so it is worthwhile. And it will let us log in for the entire bash session, so we won't need to keep typing and typing.

Give it a good strong password and continue.

Congratulations! You have now created cryptographic keys.

Now to type in your Purdue password one final time: run

ssh-copy-id {your username}@banach.math.purdue.edu

One last thing to do - download this bashrc config file and put it in your home directory (C:\Users\{username}\ on windows, /home/{username} on Linux). This will let you log in to your ssh key. Make sure the name is .bashrc - with the dot.

Start a new terminal, log in, and enjoy (mostly) passwordless access.

Streamlining with the Host file

But that's not the only thing. I am tired of typing "{username}@banach.math.purdue.edu". Let's make the computer remember that.

Create the file /.ssh/config in your home directory on your home machine.

You can quickly create and open it in atom with the command:

atom ~/.ssh/config

Enter a host configuration in that file:

Host math
    HostName banach.math.purdue.edu
    Port 22
    User {your purdue math username}

For example, your instructor would put:

Host math
    HostName banach.math.purdue.edu
    Port 22
    User bradfor3

but you shouldn't because failed attempts to login to your instructor's account would confuse the department sysadmin.

Make sure to save the file!

Wrapping up

Now we have dillydallied enough for our script to finish.

Open a new terminal, log in, and type:

ssh math

Wasn't that a lot easier, in the end? It doesn't make you type in your Purdue password, or username, or even the url.

Let's reconnect to screen:

screen -r

If the python script finished, success! One last thing to do: tell someone.

On banach, run:

echo "I finished the worksheet!" | write bradfor3

To write me a message.

Department of Mathematics, Purdue University
150 N. University Street, West Lafayette, IN 47907-2067
Phone: (765) 494-1901 - FAX: (765) 494-0548
Contact the Webmaster for technical and content concerns about this webpage.
Copyright© 2018, Purdue University, all rights reserved.
West Lafayette, IN 47907 USA, 765-494-4600
An equal access/equal opportunity university
Accessibility issues? Contact the Web Editor (webeditor@math.purdue.edu).