Exercise "Setup"

Objective: Create the working environment for the course on the IFA server "lifa.phys.au.dk".

If you plan to do the exercises on lifa (or molveno), you only need an internet connection and a terminal emulator with ssh capabilities. There is a terminal emulator for Windows—PuTTY—which should do just fine. MacOS and other *BSDs and Linux-based systems all have built-in terminal emulators.

Lifa runs Linux (as most servers do) so it is best, although not strictly necessary, to use a Linux system for this course, especially if you plan to do exercises on your own box. You can get a running Linux system in a multitude of ways, for example:

All your excersises and the project should be uploaded and built on lifa (or on molveno). You can either work directly on lifa through the internet—the default way—or you can work on your personal computer and then upload the exercises to lifa, but you still have to build them there.

  1. Get yourself a username on "lifa.phys.au.dk", the IFA server.

    You probably have one if you have an email account at IFA (an NFIT account). If your email is "pks05@phys.au.dk" you username on lifa is "pks05".

    If not go to NFIT help-desk (1525-415) and get yourself an NFIT account and NFIT password.

    From inside the IFA firewall you login on lifa with your NFIT username and your NFIT password.

    To login from the outside of the firewall you need a pair of RSA keys – a public key and a private key. The private key should be kept on your private computer you login from; the public key has to be added to the "authorized_keys" file on lifa (as described below).

  2. Login on you lifa account.

    You need to run a program called "terminal emulator" or simply "terminal". On older Ubuntu click Applications→Accessories→Terminal. On newer Ubuntu click on launcher (in the upper-left corner) and type "terminal", then click on the appeared terminal icon. On Mac run the utility "Terminal" in the Utilities folder in the Applications folder. On Windows you can use PuTTY, which is installed on the computers in the excercise room.
    1. If you are inside the firewall—for example on one of the computers in the exercise room—login on lifa with your NFIT username and NFIT password using secure shell:

      • On Linux or Mac type (in the terminal window)
        ssh your_username@lifa.phys.au.dk 
        where instead of "your_username" you have to type your actual NFIT username. It might ask you whether you trust lifa – answer "yes" without quotes. Then it will ask you for your password – type in your NFIT password. If everything goes right, you are logged in on lifa.
      • On windows run PuTTY and specify "lifa.phys.au.dk" without quotes as the destination. Then login with your NFIT username and password. It might ask you whether you trust lifa – answer yes.

    2. If you plan to login from outside of the IFA firewall, you have to set up a pair of RSA keys – a private key and a public key. The public key has to be added to the authorized keys on lifa and the private key has to be kept privately on your private computer you will be loggin in from.

      If you have already set up the keys, go to the next item.

      Otherwise, the official instructions (also for PuTTY) are here in English and here in Danish. If you can't read them, here are the unofficial instructions for a Linux system:

      1. If you don't have a suitable pair of personal RSA keys, create them with ssh-keygen command on a linux system (you can also do it on lifa itself by loggin in from inside the firewall with NFIT username and password as described above) by issuing the following commands at the terminal

        cd
        cd .ssh
        ssh-keygen -t rsa
        
        It will ask you for a passphrase which you have to make up and remember – there is no way to restore the passphrase if you forget it. The passphrase belongs to the key and has nothing to do with your NFIT password. Do not use a blank passphrase!

        If everything goes right, a private key, called "id_rsa", and a public key, called "id_rsa.pub" are generated in your .ssh directory.

      2. The private key has to be kept in the .ssh directory of the computer you want to login from. The public key—which is simply a line of characters—has to be added to the file ".ssh/authorized_keys" on your lifa account.
        1. If you have generated the keys on lifa itself and assuming you are connected to lifa from your private Linux box to be used to login from outside, do right after the ssh_keygen command

          cat id_rsa.pub >> authorized_keys
          this will add the public key to the authorized keys on lifa. Now logout from lifa with the exit command and copy the private key to your private computer using the secure copy command
          scp your_username@lifa:/usr/users/your_username/.ssh/id_rsa ~/.ssh/
          You can now login from outside of the firewall using this system.
        2. If you have generated the keys in the .ssh directory of your private Linux system, the private key is already where it has to be, and you only need to transfer the public key to lifa:
          • Using a computer with a terminal emulator from inside the firewall:

            1. Send the public key—the long line of characters in the "id_rsa.pub"—to yourself by email.
            2. Find a computer inside the firewall and open this email.
            3. On the same computer run terminal and login on lifa with NFIT account and password.
            4. Edit your ".ssh/authorized_keys" file inside the terminal, for example:
              cd
              cd .ssh
              nano authorized_keys
            5. Copy/paste the public key from the email to the terminal window using the computer's copy/paste facilities – usually right-click brings up a menu with "Copy" and "Paste" options.
            6. Make sure that it is one long line because copy/paste may introduce line-breaks into this line. Threre should be no line-breaks in this line.
            7. Save the file in the terminal window: press together Ctrl-key and X-key (Ctrl first); answer "y" without quotes on the question "Save modified buffer?"; accept the suggested filename by pressing Enter-key.
          • Using a computer with X-windows system inside the firewall. You can get one by booting an Ubuntu live USB or live CD on a computer in the excercise room:

            1. Send the public key file "id_rsa.pub" to yourself by email as attachment.
            2. open a terminal and login to lifa using your NFIT password (remember the -X option: you will need it to run Firefox on lifa):
              ssh -X your_username@lifa
            3. run firefox on lifa (the window will open on your screen)
              firefox --no-remote &
              in this firefox, go to your email, get your attachment, and save it in the .ssh directory.
            4. Add the key to your authorized_keys using the cat commands:
              cd
              cd .ssh
              cat id_rsa.pub >> authorized_keys
      3. After the public key had been added to authorized keys on lifa, all computers with the corresponding private key in the .ssh directory can ssh into lifa as
        ssh your_username@lifa.phys.au.dk
        It will ask you for the pasphrase of the public key.
    3. Once you have logged in on lifa try

      ssh your_username@molveno
      Molveno is the dedicated server for numerical methods. Your home directory is the same as on lifa.

      Molveno should have more recent software as compared to lifa and I can install extra software on molveno should you need some.

  3. Prepare the directory for the exercises:

    1. Create the directory for the exercises using the mkdir command:

      mkdir -p ~/public_html/numeric
      where ~/ is the abbreviation for you home directory.

      Now the URL http://www.phys.au.dk/~your_username points to your ~/public_html/ directory, while http://www.phys.au.dk/~your_username/numeric points to your ~/public_html/numeric directory which should then be the place for your exercises.

    2. Change the permissions to allow the others see your ~/public_html directory,

      chmod -R go+xr ~/public_html 
      You might need to issue this command again after you have created some new files.

      If you do not wish the others to see a certain file, for example my_secret_file, do

      chmod go-r my_secret_file
  4. Try it out

    1. Create a "test" sub-directory in your numeric directory

      mkdir -p ~/public_html/numeric/test
      and go there
      cd ~/public_html/numeric/test
      Hint: the tabulator-key on the left of the keyboard does "completion": it tries to complete—in a smart way—the words you type. You only need to type the (qualified) beginning of the name and then pressing tabulator-key will complete the name for you.
    2. Pick your favourite text editor. If you don't have one, try nano – it is very simple. You only need to remember that, for example, ^X in the menu list at the bottom of the window means pressing the Ctrl-key (usually bottom left) and the x-key (often between z and c) together, with Ctrl-key first.

      A very popular GUI text editor is gedit but you need a computer with an X-window system installed to run it (linux-based systems, like Ubuntu, usually have it installed by default). For example, you can boot the computers in the computer room off an Ubuntu Live CD or USB and work from that.

    3. create a file named test.c with the content
      #include <stdio.h>
      int main(void)
      {
        printf("hello\n");
        return 0;
      } 
    4. compile the file:
      cc test.c
    5. run the program:
      ./a.out
      the word "hello" must appear on the screen if everything goes right.
    6. Check whether you can see the file at htp://www.phys.au.dk/~your_username/numeric/test