Skip to content
Rushil Kasetty edited this page Sep 3, 2019 · 19 revisions

Logging into CAEN remotely

The CAEN environment is the standard for most EECS courses at the University. There are many physical "boxes" in computer labs, but you can also log into CAEN from any computer with an internet connection. While the "VNC" is one option, it is burdened with laggy connections and unreliability. Using SSH is much faster, reliable, and allows you to be more productive. In other words: SSH is just plain better. It will be worth your time to learn to use it. If you use gedit for writing code, then using SSH may present some challenges (you might like to learn emacs or vim).

But why write code on CAEN anyway? Why burden yourself with needing an internet connection? Why limit yourself to the development tools on CAEN? One could argue that a better approach is to develop code locally on your own machine, and then transfer code to CAEN only for testing and autograding. However, now you must devise a way to transfer your files to CAEN, which can be a very annoying problem in itself. The second part of this tutorial, "Transferring Files to CAEN", is meant to address this issue, and presents an approach that makes your development process more organized, efficient, and reliable.

Terminals

You will need some form of SSH client. Below are a few popular options:

  • Mac: SSH is available through the built-in terminal. Type ⌘+space to bring up spotlight, then type "terminal".
  • PC:
    • Cygwin will give you a Unix-like environment on Windows. SSH is one of the many packages available for it. Highly recommended if you want access to other Unix tools locally.
    • PuTTY is another popular client.

NOTE Putty has a graphical interface where you specify the connection details. On the other hand, this tutorial will assume you are using a terminal, like the Mac terminal or Cygwin.

Logging in

In general, the command looks like:
ssh username@hostname
Note: If you leave out the username@, the first thing ssh will ask you is to specify a user.

For UM CAEN:

  • username = <your uniqname>
  • hostname = login.engin.umich.edu

Thus, to log into CAEN, the command will look like:
ssh <uniqname>@login.engin.umich.edu

If all goes well, you will be prompted for your password (your regular UM password). After you type this in, you will be logged into CAEN remotely. That's all there is to it!

Note: If this is the first time you are logging into CAEN from a particular machine, you may see a message saying "authenticity of host .... can't be established...Are you sure you want to continue connecting?" Just type yes to add CAEN to the list of known hosts.

Tip: Configure SSH to login with less typing

Typing that long string of username and hostname can get cumbersome. You can configure SSH to log into a remote by specifying a nickname. For example:
ssh caen
Pretty cool, eh? Here's how to do it:

The path to SSH's configuration file is usually ~/.ssh/config. If it doesn't already exists, you can create it. Open this file with your favorite editor, and add the following, then save it:

Host caen  
    HostName login.engin.umich.edu  
    User     your_uniqname

That's it! You can now log in simply by typing ssh caen. Use any silly name you like, and you can add more hosts to this list later.

Transferring Files to CAEN

If you develop your code on your local machine, you will eventually need to transfer it over to CAEN for testing and autograding. There are many ways of doing this, some better than others.

While using scp or MFile will certainly get the job done, they can be very cumbersome. What if the project has many source files? What if you forget one? What if you need to do this over and over again (you will)?

Enter git. Git is a "revision control system", and is extraordinarily powerful. Other pages on this wiki cover the basics of git. This tutorial will focus on using git as a convenient way to transfer your files.

Learning to use Git (even just for the sake of transferring your files) will be well worth your time. You will notice huge gains in efficiency and productivity, especially compared to your peers who don't use it. It can also make development just plain fun! Don't be intimidated by new tools!

Advantages to using git:

  • Convenience - A simple "push" and "pull" is all it takes to transfer all the relevant files for an entire project
  • Code duplication - The workflow suggested in this tutorial will have our code duplicated in 3 places: your local machine, GitHub, and UM CAEN. This basically guarantees that you will always have a backup of your code.
  • Organization - Even without using git's advanced features, you can annotate changes to your code with simple "commits"

Getting a Github Account

GitHub is a cloud service that will be a remote host for our git repository. It has become an industry standard, and you will use it for your class projects/career eventually, so might as well start now.

IMPORTANT! STOP! READ!: GitHub is a tool that must be used responsibly. Any code put on a GitHub account is publicly visible unless you put it in a PRIVATE repository. Submitting any code for an EECS class to a public GitHub repository is almost certainly a violation of the Honor Code. Anyone can see it, and if they copy your code, you are also in violation. The authors of this Wiki are in no way responsible for your actions. You have been warned.

So, we need a private repository on GitHub to place our code in. But those aren't free. Good news: GitHub gives 5 free private repositories to university students (Edit: as of 2019-01-07, GitHub provides unlimited free private repositories for everyone). Make an account using your @umich.edu email, then fill out the quick "free plan" request here. It may take a day or two to get activated.

Aside: BitBucket is another git repository hosting service. Although not as popular as GitHub, it has unlimited free private repositories. This tutorial assumes you will be using GitHub. However, a BitBucket account is a great place to privately store your projects for the long-run to make room for new projects on GitHub. The site allows you to easily "import" code from your GitHub account in a few clicks.

Connecting your local machine to GitHub

First of all, you will need to have git installed on your local machine. It is available as one of the packages for Cygwin, and can also be installed for Mac or Linux.

Git transfers information to remote machines via SSH, so you will need to create an SSH key for authentication, and tell GitHub about it to create a trusted line of communication. You can do this by following the tutorial on GitHub.

Connecting CAEN to GitHub

CAEN Redhat Linux should already have git installed, so all you have to do is set up the ssh key with GitHub. You can follow the same exact steps as for the local machine setup.

Creating a repository for your project

First, create a blank repository on GitHub for us to push our code to later.

Using a web browser, log into your GitHub account:

  1. In the top right of the page, you should see a "Create New.." plus-sign. Choose "New repository"
  2. Give it a name (e.g. eecs281.project1) and be sure to select Private
  3. Do not add any other options for now
  4. Click "Create repository"

This should result in an empty repository on GitHub. The resulting webpage will have instructions for creating a blank repository on your local machine. A summary is below.

On your local machine, navigate to the directory of your project. For example, ~\EECS_280\project1\. Then use the following commands:

git init
git remote add origin git@github.com:your_GitHub_account_name/eecs280.project1.git

Now that you have created a repo on your machine and hooked it up to git, you will need to "push" your source files to GitHub. For example, if "main.cpp" is a source file in your project:

git add main.cpp
git commit -am "Initial commit"
git push -u origin master

Now git is setup to track main.cpp. The "commit" command takes in a string message, allowing you to log your progress. The "push" command syncs the remote (GitHub.com) with the local repository. The "-u" should only be used for the first push you make.

If you have a preexisting project and would like to add all of its files to the repository, instead of git add main.cpp you can type git add .

Now your repository page on GitHub.com should show these changes.

Last but not least, you need to "clone" the repository on CAEN. Log into CAEN and navigate to the path where you would like the project code to reside. Once there, type:

git clone git@github.com:your_GitHub_account_name/eecs280.project1.git

This single command has copied your entire project over to CAEN! Neat!

The Workflow

This is what we have been working towards all along. The simple workflow suggested in this tutorial will help you code and test safely and efficiently. However, it is just a suggestion, and many different workflows are possible.

  1. After making some changes to the code on the local machine, add any new files and commit your changes with a nice message:

     Local-Machine$ git add Dealer.cpp  
     Local-Machine$ git commit -am "Implemented shuffle function. Needs testing."  
     Local-Machine$ git push origin master
    
  2. Now that you have committed and pushed the changes, log into CAEN and navigate to the repository to test your code:

     User@caen$ git pull origin master
     User@caen$ git log
    

The "log" command is optional, and prints out all past commit messages so you can be sure everything is synced

  1. Run your tests on CAEN. If you want to make changes, do them locally and go back to the first step

Notice how this workflow is one-way. Any changes are made in your local copy of the code. These changes are then "pushed" to GitHub, and then "pulled" from GitHub into CAEN. No changes to the code are made in CAEN. You certainly can commit and push changes from CAEN, but that requires keeping track of updates to prevent conflicts (out of the scope of this tutorial).