UACalc in the cloud


These notes explain how to setup, login to, and deploy UACalc on a remote Amazon Web Services (AWS) Ubuntu server. This makes it possible to do universal algebra computations in the cloud from a terminal or ssh client using a pc or Android device. (I see no reason why this wouldn’t work from an iPhone or iPad ssh client app.)

Below, we will only use the AWS “Free Usage Tier,” which, as the name implies, is free (at least for the first year). This provides a “T1.micro” instance, which is very basic — a single processor with just 630Mb of RAM. If you are willing to pay, there is a wide range of hardware available, from standard issue stuff (about $0.10/hour) to high performance GPU clusters with tons of RAM (about $4/hour). It’s also possible to pay annually instead of hourly. Refer to the Instance Types and Pricing pages for details.

If you follow any of the instructions on this page and encounter problems, we want to know. Please post a comment in the box below.


Obtain an Amazon Web Services account

With an AWS account, you can launch remote linux servers, login to them with ssh, and then install and run whatever programs you want. The AWS Free Usage Tier includes 720 hours/month of compute time. The only catch is that you must supply Amazon with your credit card number. (They won’t charge your card unless you use premium services.)

Setting up an AWS account at is straight forward, but pages 20–31 of the Startup Engineering Lecture Notes walk you through the process with lots of screenshots. (The notes were accurate as of July 2013, but some steps may have changed.)

The lecture notes mentioned above are from the Stanford Startup Engineering course and provide lots of other useful information, such as instructions for using the terminal on a Mac (pp. 5–10) or Windows (pp. 10–18), as well as setting up a GitHub account (pp. 34–37).

Launch an AWS EC2 Ubuntu instance

After setting up an AWS account, follow the steps below to launch a remote Ubuntu server. (For more details, see pages 43–52 of the Startup Engineering Lecture Notes.)

  1. Login to your AWS account using your web browser.
  2. On the top right of the page, you should see your full name. Click on your name and a drop down menu will appear. Select from this menu AWS Management Console.
  3. Select the item near the top left called EC2 Virtual Servers in the Cloud.
  4. Click the blue Launch Instance button.
  5. Click Continue to proceed with the Classic Wizard.
  6. Select Ubuntu Server (12.04 LTS, as of this writing).
  7. Just click Continue for the next two dialog boxes and accept the default values. (These dialog boxes provide options such as requesting more CPUs or more RAM. Note: the non-default options are not part of the Free Usage Tier.)
  8. At the “Create Key Pair” stage, is important to create and save a .pem file on your computer (remembering where you save it) using this dialog box:
  9. Select a default security group, review your choices, and then click on the Launch button.
  10. Click Close on the last page. This will land you on the Instances page, where you can monitor the status of your running EC2 servers.

SSH to AWS Ubuntu instance

This section assumes you have ssh installed on your machine and you have a terminal window open with a command prompt.
We give below a very terse description of how to login to the remote AWS instance you launched in the previous section. If you want more details, see pages 53–59 of Startup Engineering Lecture Notes.

  1. In the previous section, when you launched an AWS instance, you created and downloaded a .pem file. Move that file to your ~/.ssh directory (which we’ll create if it doesn’t exist). For example, if you saved this file in your ~/Downloads directory and named it your-pem-file.pem, you would do this:
    mkdir -p ~/.ssh
    mv ~/Downloads/your-pem-file.pem ~/.ssh/
    cd ~/.ssh
  2. Next, change the permissions of the .pem file, or else AWS won’t allow you to connect.
    chmod 400 your-pem-file.pem
  3. In your browser, navigate to the EC2 Management Console, if you’re not already there. It should look something like this:
  4. The EC2 Management Console should show the address of your instance. In the figure above, you can see the address of the instance is Select and copy your address. (We will paste it into the terminal in the next step.)
  5. In a terminal window, change to the directory containing your .pem file and ssh to your AWS instance as follows (replace the address shown below with the one you just copied in the last step):
    cd ~/.ssh
    ssh -i your-pem-file.pem

    If the login succeeds, you should see something like this:

  6. Finally, you might want to add an alias for your AWS host in the file ~/.ssh/config. Create this file if it doesn’t already exist and add the following lines to it:
    Host awshost1
    User ubuntu
    IdentityFile "~/.ssh/your-pem-file.pem"

    where ec2-50-19-140-229 would be replaced with the appropriate address. Now this AWS instance can be reached with the following command: ssh awshost1.

Customize your AWS instance (optional)

An AWS instance provides a bare bones Ubuntu installation, so if you plan to use it often, you will probably want to customize it as you would any other Linux machine, by tweaking some configuration files, and installing some basic programs, like Emacs and Git. Once you terminate the instance and launch another, however, you will be back at square one, so it’s important to have an automatic setup and configuration script.

A reasonable starting point is to simply clone the Stanford Startup Engineering dotfiles repository, or my dotfiles.wjd repository. For example, I would customize a new AWS instance with these three steps:

  1. Download the script.
  2. Make it executable:
    chmod a+x
  3. Run it:

After doing this the first time, it’s a good idea to exit and log back in to your AWS instance so that the dotfiles have a chance to customize your environment. Once logged back in, consider starting the screen program by typing `screen` at the command line. This is handy in case your remote session times out. Then you can login again and type `screen -r` to recover your previous session.

Finally, delete the file, since we’ll download and use a different script in the next section.

Deploy UACalc in the cloud

Now that you have an AWS instance up and running, you can install the UACalc command line interface in three easy steps (which are also described as “Method 2” on this page).

  1. Download the script: You can use your browser to download it, OR type the following at the command line:
  2. Make it executable:
    chmod a+x
  3. Run it:

If you try these commands and get an error, we want to know. Please post a comment in the box below.

For some examples of what can be done with UACalc from the Jython command line interpreter, see this page.

SSH to AWS instance from an Android device

If you want to connect to your AWS instance from an Android device, you must somehow get the pem file that you created when you launched the instance onto your device. For example, you might email it to yourself, or put it in Dropbox. These methods might not be very safe, since you want to keep your pem file private, but probably the risk that someone wants to hack into your AWS instance is fairly small. Alternatively, you could start a new AWS instance using the browser on your Android device, and then the pem file would be saved on the device to begin with.

  1. From the Android App Store, install JuiceSSH.
  2. Start the JuiceSSH app and select Connections.
  3. Select New Connection and fill in the fields as appropriate:
    Nickname: whatever
    Type: SSH
    Address: (your AWS server address)
    Port: 22
    Connect Via: (leave blank)
    Identity: (we’ll set this in the next step)
  4. Tap the field next to Identity and select New… You should see this screen
  5. Enter any nickname you want, enter ubuntu for the username, and then tap the button next to “Private Key.” You should see this screen
    If you select the Smart Search option, the app should locate the pem file for you, assuming you saved it on your device as mentioned at the start of this section. Otherwise, enter the full path to the pem file. Then select OK and Save. Make sure the nickname you chose now shows up in the Identity field of the New Connection dialog and select Save.
  6. The name you chose for your connection should now appear in the main JuiceSSH Connections screen. Tap the name and it should login to your AWS Ubuntu instance. You should see something like this
  7. Now go ahead and try some UACalc commands on your Android device, like this

    With the Hacker’s Keyboard, it will look like this

    Two nice features of the Hacker’s Keyboard are the tab and up arrow keys, which are useful for command completion and recall.

    The keyboard takes up quite a lot of a small screen, and it can be tiresome to type computer code on a touchscreen, but a Bluetooth keyboard is a viable alternative, and it may be possible to plug your device into a standard monitor using an HDMI adapter.

    If you don’t have an Android phone, or you don’t like the idea of using your phone for doing computational research, it’s now possible to buy a mini Android computer for about $75 (example 1, example 2). (Reportedly these can even run Ubuntu.) Depending on your goals, using an inexpensive local device to access cloud computing resources might turn out to be a very economical and powerful option, especially if you mainly do your computing at the command line.

    If you want to use applications that require graphics (like the UACalc gui), cloud computing might still be an option, but as of this writing (October 3, 2013) we haven’t tried to run a remote xserver on AWS, for example. Alternatively, a native Android UACalc app might be worth developing in the future. Perhaps this would be a good project for a student.

    Miscellaneous Notes

    • GAP in the cloud.
      It’s easy to install and run GAP on an AWS instance using the gapsync installer.
    • Keep-alive ssh session.
      The ssh server (sshd) will close a remote connection if it doesn’t hear anything from the client for a while. You can have your client send a keep-alive signal to the server once in a while by adding the following lines to your `~/.ssh/config` file:

      Host remotehost
        ServerAliveInterval 240

      This will send a keep-alive signal every four minutes to remotehost. To enable this for all hosts use:

      Host *
        ServerAliveInterval 240

      Also, make sure to do `chmod 600 ~/.ssh/config`, because the config file must not be world-readable.

    • Unfreeze a frozen terminal window.
      If sshd closes your connection and freezes the terminal window, you can simply close that terminal window and open a new one, or you can use “tilde dot” (that is, `Enter~.`) to disconnect from the frozen session. (This is one of the many things Ralph Freese taught me. Thanks Ralph!)
    • Use Screen to recover a remote session.
      Inevitably there will come a time when your session is terminated while you’re in the middle of something and you must try to recover that session and pick up where you left off. Therefore, immediately after logging in to a remote host, it is recommended that you start the Screen program by typing `screen` at the command line. If you do this, and if your session is interrupted, then the next time you login to the same host, you can type `screen -r` to recover your previous session.

      Important Note: If you use Emacs, you will need to customize your Screen configuration settings because the default is for Screen commands to begin with `C-a`. In Emacs, `C-a` will move the point to the start of the current line, so screen commands won’t work when you’re visiting an Emacs buffer.

      Customizing Screen is a simple matter of changing some of the settings in your .screenrc configuration file. I recommend the configuration used in the Stanford Startup Engineering course, which can be installed on your machine as follows (see the lecture notes for more details):

      cd $HOME
      wget -O .screenrc

      (The same .screenrc file is part of the dotfiles.wjd setup, so you already have it if you ran the script at

      If you put the above mentioned .screenrc configuration file in your home directory, then all Screen commands will begin with `C-t` instead of `C-a`, so Screen commands will work even when you’re using Emacs.

      Some Screen tutorials are here, here, and here.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s