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 over 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 on lifa (or molveno).

  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.

  2. Login on you lifa account.

    From the wired network at IFA (nfit.au.dk and phys.au.dk) you login on lifa with your NFIT username and your NFIT password. (You can find out your computer's network name using the command [nslookup `hostname`] or [host `hostname`]).

    From the outside world you login with a pair of RSA keys – a public key and a private key. They both are small pieces of ascii text. The private key should be kept on your private computer from which you login to lifa; the public key has to be added to the "authorized_keys" on lifa (as described below).

    Another option to login from the outside world is VPN (here in English). It is not supported, but some students used it successfully.

    1. If you are inside IFA—for example, your box is connected to IFA's wired network—login on lifa with your NFIT username and NFIT password using secure shell:

      • On Linux or Mac run your terminal emulator and 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 IFA, 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
        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 long line of ascii 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

          cd ~/.ssh
          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 on lifa from outside IFA.
        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 add the public key in the file "if_rsa.pub" to your "~/.ssh/authorized_keys" file on lifa. Copy the public key to a USB-drive or send it to yourself by email.

          • Using a computer with a terminal emulator from IFA (for example, your own box connected to wired IFA network):

            1. Open the file with your public key either from your USB-drive or from your email.
            2. Open a terminal and login on lifa with NFIT account and password.
            3. Edit your ".ssh/authorized_keys" file inside the terminal, for example using the "nano" editor:
              cd
              cd .ssh
              nano authorized_keys
            4. Copy your public key (the text in the id_rsa.pub file – one long line) from your USB-drive of from your email and paste it into nano in the terminal window using the computer's copy/paste facilities – usually right-click brings up a menu with "Copy" and "Paste" options.
            5. 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.
            6. Save the file in the terminal window: press Ctrl-key and x-key together (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 IFA. You can get one by booting an Ubuntu live USB or live CD on one of the public computers. Or, connect your Ubuntu box to the wired network at IFA.

            1. Send the public key file "id_rsa.pub" to yourself by email as an attachment.
            2. open a terminal and login to lifa using your NFIT password with the -X option -- you need that 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 your Desktop directory (or any other directory at your wish -- the important thing is to remember the name of the directory).
            4. Add the key to your "authorized_keys" using the cat commands:
              cd
              cd .ssh
              cat ~/Desktop/id_rsa.pub >> authorized_keys
              If you saved the file in another directory, you have to use the name of that directory, of course.
      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. In order to use X-window programs you have to login with "-X" option,

      ssh -X user@host

    3. create a file named test.c with the content

      #include <stdio.h>
      int main(void)
      {
        printf("hello\n");
        return 0;
      } 
    4. compile the program with the command
      cc test.c -o test
      or using make utility
      make test
    5. run the program:
      ./test
      the word "hello" must appear on the screen if everything goes right.
    6. Check whether you can see the file in your browser at http://www.phys.au.dk/~your_username/numeric/test