Get acquainted with the Unix shell on Stanford’s FarmShare and set up accounts on Github and Twitter so that we have a (remote) place to work and a usable data source.
This is where you will submit homework assignments for the class. If you have already been given the Github Education Pack, make the compciv repo private.
If your Github username is
hello, the URL for your repo will be
github.com/hello/compciv. Also, if you can figure it out, give my Github account (
dannguyen) read access to your compciv repo. (if you can’t figure it out, we’ll go over it in class).
Set up password-less access to Github from corn.stanford.edu via a SSH key-pair.
Register at twitter.com; you can use an existing personal Twitter account if you have one. Then follow at least 50 other users.
corn.stanford.edu command-line, send me an email to
firstname.lastname@example.org with the following:
If you've never done this before, this will probably be the most seemingly arbitrary and confusing set of steps that you'll have to take for this course. But they are necessary for setting up your the working environment for the rest of this course, and also serves as an introduction to remote/cloud computing.
But there's nothing here meant to trick you. Just follow each step one at a time and please contact me or post on Piazza when you run into problems.
Creating a Twitter and Github account are straightforward enough.
However, working from
corn.stanford.edu and setting up the SSH keys may be new to you, so follow these steps.
I've listed every command here: if you're completely new, read the commands and re-type them yourself (don't copy and paste). Just the physical act of typing helps you get a feel of how things work, even if you don't have any clue as to what the commands are doing. That's OK, this is the arbitrary and confusing part of the course.
You have a less direct path to logging in. Follow these instructions by Stanford's IT department on Downloading and Configuring SecureCRT 7. At the end of the instructions, you should be able to log into corn.stanford.edu
You should see a prompt (the same as for the OS X users) that looks like this:
In your Finder, open the folder at Applications > Disk Utilities and double-click the Terminal app. Then type (using your own SUnet ID):
You'll receive a response like this:
The authenticity of host 'corn01.stanford.edu (220.127.116.11)' can't be established.
RSA key fingerprint is 0b:e7:b4:95:03:c1:1e:07:df:04:ca:a2:3d:8e:e3:37.
Are you sure you want to continue connecting (yes/no)?
Just type in
yes (for yes) and hit Enter. You will then be asked for your password. Type it in (it'll seem like nothing's happening, but that's because the Terminal is obscuring your password) and hit Enter.
At this point, you should see a prompt that looks like this:
Note: We may not need to actually do this SSH key thing (it's cumbersome on corn.stanford.edu). Read the guide on /recipes/devops/git-and-github-setup for more details, particularly the section about the "access token"
At this point, the instructions are similar to what you'll find on Github…but not exactly. So keep following along here.
At the prompt, type the following commands in and hit Enter after each one:
mkdir -p ~/.ssh
Note: If it didn't seem like anything happened, i.e. a confirmation or error message, then you're good. This is a consequence of the Unix Philosophy tenet, "Rule of Silence":
Rule of Silence: When a program has nothing surprising to say, it should say nothing.
Type the following, substitute your SUnet ID (i.e your email), and hit Enter:
ssh-keygen -t rsa -C "email@example.com"
You'll see this output:
Generating public/private rsa key pair.
And then you will be given a prompt that looks like this…don't hit Enter just yet:
Enter file in which to save the key (/afs/.ir/users/d/u/dun/.ssh/id_rsa):
At the prompt here, type in:
Then hit Enter. This
compciv_id_rsa string is just the filename for the key.
You'll then be asked for a "passphrase" (i.e. a password). This is optional but I recommend specifying a passphrase.
You'll then see this (and a few other lines of code you can ignore)
Your identification has been saved in compciv_id_rsa.
Your public key has been saved in compciv_id_rsa.pub.
The file with the
.pub extension – that is your public key. You can generally share this with the world, and in fact, you are going to share it with Github in the next step.
Let's print it out to screen:
The output will look something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAAXbZuyQIh/g9+LjVb39hjRm+HNgcurEUiRbPdcdMTB2YhReiPTDAQABAAABAQDSmc8DCOkHaloYGOounfjEHv0jk2+XEBfR99Ynj9nq21F7H8qipCjB9h5aGJTeMjxOqPEoIy3wUw43q76CZcJ0eLyn14YS7b+pMV0mFIMGfumYtuiybpg3E0RHlQtd6BVsGaF firstname.lastname@example.org
Highlight all of that line (and just that line, down to your email address) and copy it to your clipboard (via Ctrl-C, or what have you).
By the way, that other file –
compciv_id_rsa? That's your private key. You never just want to give that out to anyone else. You can
cat it just to see what's in it though. As you can see, it's much longer than your public key. Do not copy the private key to your clipboard
Assuming you have copied your public key to your clipboard, you can follow the rest of the Github instructions at Step 3: Add your SSH key to your [Github] account
When you get to the step of typing in
ssh -T email@example.com, you will probably receive an error like this:
Permission denied (publickey).
Read on to the next step.
So try this command:
ssh -T firstname.lastname@example.org
I'm assuming you get this error:
Permission denied (publickey).
The Github help page, Error: Agent admitted failure to sign, has the information.
Execute this command:
eval "$(ssh-agent -s)"
You should see this:
Agent pid 45765
Then run this command and enter your passphrase if you set it up:
Now you should be good to go:
ssh -T email@example.com
Hi dannguyen! You've successfully authenticated, but GitHub does not provide shell access.
At this point, you're good to go. If you already know how to set up Github repos, you can try doing so from the command line, but we'll do it in class on Wednesday.
As stated in the deliverables, one of the things you need to send me, via email, is that public key, which we'll do in the next step.
As before, I list out the steps needed to finish this part of the homework. Re-type them manually to get a feel for how things work. If you want a little more insight, read the Software Carpentry guide to the Shell
If you aren't still logged in, log back into corn.stanford.edu.
corn server allows you to send mail, via the command-line, from your Stanford email address. However, it only allows you to send emails to other
Type in the following at the prompt:
You should then be prompted for a
Subject, and when you hit Enter, your prompt will move to a blank line. At this point, you can type whatever you want.
At the end of it, hit Control-D on your keyboard to exit out.
You will then be prompted for a
Cc: (hit enter to leave it blank). Then, the
Your screen will probably look like this:
corn01:~$ mail firstname.lastname@example.org
This is an email blah
@corn01:~$ # back to the prompt
Most command-line programs have options (also known as flags) that can be set. There's no consistent rhyme or reason to them across different programs (i.e.
-s for the
@corn01:~$ mail email@example.com -s "This is my subject"
I now know how to use options
@corn01:~$ # back to the prompt
Now let's send an email the more Unixy way (i.e faster, with less typing).
The Software Carpentry's guide to Unix pipes is relevant here. But jumping straight into the action:
echo command simply takes a string of text and prints it to screen. The usage looks like this (note that what's printed is in single quotation marks):
echo 'hello world'
Using a pipe, denoted by the
| character, we can send the text from
echo to any other program that can be connected to a pipe (which is most Unix programs). So let's send it to mail:
echo 'Pipes are pretty fun' | mail firstname.lastname@example.org -s 'PIPES WHOOOooo'
You should see that message in your inbox straightaway. If you try it without the
-s flag, you send it again, except without a subject. Oftentimes, the use of a pipe to connect programs will let you run them with the minimal amount of options and fuss.
Once you're done testing
It doesn't matter what order they're sent in, just that they are separated by a newline or a space.
Let's follow the same process as before, but to make things a little conceptually easier, we'll create a temporary text file that we'll pipe into the
First, change directory to your home directory:
echo and the
> operator, we can send text into a new file:
echo 'Hey dan this is my homework' >> stuff.txt
Now add your Twitter and Github URLs in the same fashion, but use the
>> (double brackets) so that the text is appended to
stuff.txt (as opposed to overwriting
echo 'https://github.com/dannguyen' >> stuff.txt
echo 'https://twitter.com/dancow' >> stuff.txt
Go ahead and
cat stuff.txt to see that your text is in there. The
cat program is short for
concatenate, and so every argument (in this case, filename) passed into
cat will be added together. Try this:
cat stuff.txt ~/.ssh/compciv_id_rsa.pub
That's pretty much your homework! Try using pipe to
>> seem to do the same thing, but they don't. The pipe character facilitates the passing of text between programs. Whereas the right-angle-brackets sends text into files)
After you're done, go ahead and delete the
stuff.txt (not that there's anything private there):
This concludes the "mail-in" part of the homework.