Off-Campus Access to cs.bridgewater.edu

In order to ssh into cs.bridgewater.edu from off campus you need to use the college’s VPN.  The VPN will create a secure encrypted channel between your computer and the college’s network.  Be sure, once you are finished using cs.bridgewater.edu, that you turn off the VPN so that your internet traffic does not travel through the college’s network.

In order to use the college’s VPN, you first need to install it.  You can find instructions on where to download the VPN and how to use it in a tutorial on the IT department’s web site.

To find the tutorial do the following:

    • Navigate a browser to help.bridgewater.edu.
    • Press the Log in link in the upper right corner and log in.
    • Click on the Knowledge Base tab on the menu bar.
    • Click the Information Technology category.
    • Click the Wifi & Network category.
    • Select the Using VPN to Gain Access to the Network article.

Download, install, and start the VPN by following the instructions in the knowledge base tutorial.  If you have any problems getting the VPN installed or started, please open an IT ticket by emailing help@bridgewater.edu and sending them a detailed description of the process you have taken and what the problem is.  Provide screenshots if applicable.

Once the VPN is started, you can open your terminal or Command Prompt and ssh into cs.bridgewater.edu.

Again, be sure, once you are finished using cs.bridgewater.edu, that you log out of cs.bridgewater.edu and turn off the VPN so that your internet traffic does not travel through the college’s network.

4. Pushing a File to GitHub

Prerequisite

I assume you’ve cloned our shared repository onto the Linux machine.  If you haven’t yet done so, please do so before continuing on with this tutorial.

Create README.md

Log into your Linux machine and change your working directory so that you are in the base directory of your repository.

Using an editor, create a file named README.md (if it doesn’t already exist).  Note that the filename is case sensitive.

Include at the top of the file a line of text that simply reads

# YOUR_FULL_NAME

where YOUR_FULL_NAME is replaced by your first and last names.

Submit Your Work

Anytime you want to copy your work (like the README.md file) to GitHub you need to do the following:

      1. Add the names of the files that you’ve modified or created to the staging list.
      2. Commit the changes to the files in the staging list to your local repository.
      3. Push your committed changes to our shared repository on GitHub.com.

Note that all of the following commands must be executed inside your repository directory.

STEP 1: Add the names of the files that you’ve modified or created to the staging list by issuing the following command.  Replace FILE_NAMES with the names of all of the files and directories (separated by spaces).

$ git add FILE_NAMES

STEP 2: Commit the changes to the files in the staging list to your local repository by issuing the following command. Include the double quotes and replace YOUR_MESSAGE with a short message describing your changes.

If you are submitting your code for review because you have a bug, add in the commit message @erimcg followed by a precise description of the issue you are trying to solve.  Note that “@erimcg can not find bug” is not sufficient.  Do not include @erimcg if you are submitting your work for a grade.

$ git commit -m "YOUR_MESSAGE"

STEP 3: Push your committed changes to our shared repository on GitHub.com by issuing the following command.

$ git push

Final Step

Always check that your files were successfully copied to our shared repository on GitHub.com by logging onto GitHub.com and visually checking our shared repository.  If they’re not on GitHub, I can’t pull them.

For more information on git, please see the online reference manual: http://git-scm.com/book.

2. Create a GitHub Personal Access Token

GitHub now requires users to use personal access tokens rather than passwords to authenticate themselves when communicating remotely with the GitHub servers.

When you follow the instructions in the tutorial below, do the following:

In Step 6, name your token anything you like
In step 7, choose “no expiration”
In step 7, grant the token all rights by checking all of the boxes

To create a personal access token follow the direction in the GitHub tutorial named Creating a personal access token.

 

 

1. Creating a GitHub Account

You are about to register for an online account.

When registering, ONLY use letters and numbers (a-z A-Z 0-9) in your GitHub username and in your GitHub password.

When registering, only use letters and numbers (a-z A-Z 0-9) in your GitHub username and in your GitHub password.

When registering, only use letters and numbers (a-z A-Z 0-9) in your GitHub username and in your GitHub password.

  1. Go to http://github.com and register for an account.
  2. Save your GitHub username and password in a secure location.
  3. Verify your email account by clicking on the link in the email that was sent to you by GitHub.com.
  4. Provide your instructor with your GitHub username.

 

Reaching the AWS Console With an AWS Educate Student Account

Prerequisite:  You should have applied for an AWS Educate account and received an email from AWS accepting your application.

  1. Click on the hyperlink on the line of your acceptance email that says, “Bookmark the AWS Educate Student Portal for easy access, or click here to sign in directly.”
  2. Log into the AWS Student Portal.
  3. Click on AWS Account at the top-right of the page.
  4. Click on AWS Educate Starter Account.
  5. Click on AWS Console under Your AWS Account Status.

Using Kattis’ Client on Linux

Create a Kattis Account

  1. Create an account on open.kattis.com. Choose Log in with e-mail, then choose Sign up for a Kattis account. Use your Bridgewater College email address when creating an account.

Getting the Kattis Client and Config File

  1. Log into open.kattis.com.
  2. Choose the Help tab, then choose the How to submit link located near the bottom of the page.
  3. Read the How to submit page carefully before continuing.
  4. Scroll down to the section titled Downloading a configuration file and client.
    1. Cut and paste the contents of your personal configuration file into a new file on your laptop and save the file in your Downloads directory as kattisrc.txt.
    2. Download the Kattis client into your Downloads directory by clicking on the file name.
  5. Open terminal or GitBash and change the working directory to the location of the files you downloaded (in your Download directory).
  6. Use the following command to copy your personal configuration file and submit.py to your home directory on cs.bridgewater.edu.
scp <file name to transfer> <bc_username>@cs.bridgewater.edu:<file name to transfer>

Note that when typing the above command you need to replace <file name to transfer> and <bc_username> with appropriate information.

Setting Up Submit.py

  1. SSH into cs.bridgewater.edu
  2. Run chmod 700 submit.py.
  3. Create a subdirectory in your home directory named bin and move submit.py into bin.

Setting up .kattisrc

  1. Rename the kattis config file (e.g. kattisrc.txt) to .kattisrc.

Testing the Script

  1. Navigate to https://open.kattis.com/problems/hello with a browser to view the hello problem.
  2. Write a program on your VM that solves the hello problem with a class named Hello in a file named Hello.java.
  3. Submit your program to Kattis using the following command: submit.py -p hello -l Java -m Hello Hello.java
  4. Navigate to open.kattis.com with a browser and click on your name in the upper right corner to see if your solution was accepted.

Bash

Bash

The shell that is started by default on our host is called bash. When bash is run it displays a command prompt (a.k.a. system prompt or bash prompt) to the user.  This prompt often includes the name of the directory that the user is logged into followed by $.  When the command prompt appears on the screen, the user can enter commands after the prompt and press enter to have the shell execute the command.

Bash’s Hidden Files

If we run the following command we can see all of the files in the current directory including the hidden files.  A hidden file is a file whose name starts with a period.  If we run the command from our home directory we can see the three files: .bash_history, .bash_profile and .bashrc.

$ ls –al

Bash History

When at the command prompt, we can use the up arrow and down arrow keys to display on the command prompt previous commands that we’ve had the shell execute.    These previous commands are stored in .bash_history.

The up arrow and down arrow keys can help speed up the development process. Rather than having to retyping a compile command, for example, we can just use the up arrows to repeat the command to we entered earlier.

The .bashrc and .bash_profile Script Files

Both .bash_profile and .bashrc are script files that are editable by the user.  When we start a terminal application to gain access to a shell prompt, the terminal typically starts a non-login shell.  When starting a non-login shell the script file ~/.bashrc is executed.  When we SSH into a machine, a login shell is started and the scripts in .bash_profile and .bashrc are run.

Some useful things to add in these script files are definitions for environmental variables and aliases.

An environmental variable is a string that can be used to refer to another string (usually much longer) in a script or program.  For example, suppose I often change my current working directory to /home/eric/courses/csci105. I can add an environmental variable named INTRO to .bashrc and use it to refer the path.  In .bashrc  I would add the following.

INTRO=/home/eric/courses/csci105
export INTRO

In order to be able to use the new environmental variable we need to reload the .bashrc file.  To do this you need to either log out and back in or run the following command:  (dot space dot bashrc)

$ . .bashrc

Now when you want to go to your homework directory you can substitute the environmental variable for the homework path.

$ cd $INTRO

Aliases are used to define shortcuts to commands that are invoked repeatedly or are lengthy to type.  Suppose I would like to make it so that when I typed ls the shell executed ls -l.  I can do this by creating an alias for ls -l.

alias ls=’ls –l’

Don’t forget to reload the .bashrc file.  After it has been reloaded, when you type the command ls it will execute ls –l.

Linux and Vi commands

If you search the web for ‘linux cheat sheet‘ you find numerous one-page documents that list the most commonly used Linux commands.  I recommend that you print or bookmark one to help you learn them.

Navigating the File System

Some of the most common commands that we’ll use are for listing the files within a directory and moving around the file system.

  • ls
  • ls -l
  • ls -al
  • pwd
  • cd /
  • cd $HOME
  • cd ..
  • cd [dir] (absolute or relative path)

UNIX directory structure

Standard-unix-filesystem-hierarchy

Manipulating Directories and Files

  • mkdir [dir]
  • rmdir [dir]
  • mv [src] [dest]
  • touch [file]
  • cp [orig] [new]
  • cp -r [src_dir] [dest_dir]
  • rm [file]
  • rm -r [dir]    (BE CAREFUL!)
  • chmod [mode] [file]

Displaying File, Manual, Environment and System Information

  • cat [file]
  • man [command]
  • which [command]
  • whereis [command]
  • env
  • whoami
  • hostname
  • date
  • clear

Viewing and Killing Processes

  • ps
  • ps -ax
  • kill [pid]
  • kill -9 [pid]

Pipes

  • [command] | [command]
  • cat filename | less

Vi – The Editor of Champions

  • Insert Mode (i)
    • arrow keys
    • delete
  • Command Mode (esc)
    • x – delete char
    • r [char] – replace char
    • dd – delete line
    • # dd – delete multiple lines
    • u – undo last command
    • yy – copy to clipboard
    • # yy – copy multiple lines
    • p – paste contents of clip board
    • $ – go to the end of a line
    • 0 – go to the beginning of a line
    • shift + G – go to the end of the file
    • shift + H – go to the beginning of the file
    • :# – goto line a particular line
    • :/search_term – search for a particular term
    • :%s/old/new/g – find and replace
    • :w – write the file
    • :q – quit vi
    • :q! – quit without writing
    • shift+z+z – write and quit
    • :set number – show line numbers
    • :set nonumber – hide line numbers