Stephen Fry

"Education is the sum of what students teach each other in between lectures and seminars. " - Stephen Fry

Tuesday 8 January 2013

Quick Guide: Remotely adding a new user on Ubuntu 12.04

In the following is a quick guide to creating a new user (we will be calling this user "username") on a Amazon Cloud EC2 instance with Ubuntu 12.04 AMI

CREATING NEW USER

We will begin by adding the new user and setting the new users password

$ sudo adduser <username>

This command will then take you though the setting up a password. You can check the users that you now have my opening the /etc/passwd file

Now we are going to make use of a unix command called "visudo", this allow you to edit the sudoerrs file in a concurrent access safe way.  Before using visudo, we need to check that the default editor is the one that we would like and change it, if required:

sudo update-alternatives --config editor

Now you will be given a dialogue where you can select your favourite text editor.

visudo


Now add the following line to the file that has been opened:

<username> ALL=(ALL) ALL

Now exit the machine and log back in as ubuntu. 


You can now switch to this newly created user with 
$ su <username>
$ cd /home/<username>

GENERATING KEYS FOR SSH TO NEW USER

We are now going to generate the public key for public/private key pair that will be used later to SSH directly into this new user

ssh-keygen -b 1024 -f mykey -t dsa

This line has generated two files, the public key paws.pub and the private key paws. To be able to ssh from a local machine to the new paws user on this remote machine, we need to place copy the contence of paws.pub into /home/paws/.shh/authorized_keys and we need to have a copy of the private key (called paws) on the local machine


$ mkdir .ssh
$ chmod 700 .ssh
$ cat mykey.pub > .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys

Now that we have the key we need to transfer this key on to our local machine and generate the private key



$ sudo chown <username>:ubuntu .ssh
$ sudo cp mykey /home/ubuntu


$ sudo chown <username>:ubuntu .ssh/authorized_keys

$ sudo chmod 777 /home/ubuntu/mykey


Logout and return to local machine
$ scp -i originalkey.pem ubuntu@<URL-of-server>:/home/ubuntu/mykey mykey

Now you can ssh into your remote machine as this new user:

chmod 400 mykey ssh -i mykey <username>@url-of-server






Monday 7 January 2013

Quick Guide : Amazon Cloud EC2

The following is a quick guide to setting up an virtual server on Amazon Cloud EC2:

SETUP


1) Login to AWS Management Console using your Amazon account and navigate to EC2

2) In the top right hand corner, check that the location of the servers is the one that you would like to use, I will be using Ireland

3) In the "Getting Started" section of the EC2 dashboard, select Launch instance to create a new virtual server

4) I will be demonstrating the "Classic Wizard"

5) Select the Amazon Machine Image (AMI) that you would like to use, I will be using the Amazon Linux AMI 2012.09, 64bit edition 

6) Enter the instance details, I am going to be creating 1 micro instance on EC2 so I've not changed any of the options on this page or the following Advanced Instance Options page or Storage Device Configuration page

7) Now you can create tags, using tags for your instances is really useful so I highly recommend it. I've set the key and value to "PAWS-router-management-server"

8) Creating a public/private key is vital for using SSH to access your virtual server. Give the private key a sensible name and download it

9) Creating a new security group is highly recommended, otherwise you can use make use the default group. I will be accessing the server using SSH so I've opened up port 22 to SHH 

10) Review the opinions you have chosen and save  

ACCESS


1) If you navigate to the "instances" page, you will now be able to see your newly created instance. Selecting your instance will give you access to more detailed information 

2) To access your new instance, open the terminal and locate the private key you downloaded during set up

3) Change the permissions on the key using: $ chmod 400 <name-of-key>

4) Connect via SSH using: $ ssh -i <name-of-key> <public-DNS-name-of-server>

More details on the Amazon Linus AMI are available at  http://aws.amazon.com/amazon-linux-ami/ . Its useful to note that there is no root password, you can't SSH in as root or use su but if you use sudo, no password is required and that the package manager used is yum


Sunday 9 December 2012

Betteridge's law of headlines

I dont have much to add here but the Wikipedia article is well worth a read http://en.wikipedia.org/wiki/Betteridge's_law_of_headlines

Display image of 

@ianbetteridge

Thursday 29 November 2012

LaTeX - The IEEE Surveys & Tutorials Way (Pt 2)

This the second article in a series on using the IEEEtrans and LaTeX to form a survey suitable for submission to IEEE surveys & tutorials

Yesterday's article made use of the bare bones template for journals provided by IEEEtrans, now we are going to look at the requirements of a survey in IEEE surveys & tutorials 

IEEE Surveys & Tutorials

The following information is largely taken from the Information for Authors page, on the IEEE Communications Surveys & Tutorials site.
The focus of this article is a survey not a tutorial, therefore all of the points below are regarding surveys and not necessary tutorials.  

IEEE Communications Survey & Tutorials is a free online journal published by the IEEE Communications Society. Article appear in both the IEEE Xplore Electronic Library and the IEEE ComSoc Digital Library

To finding existing surveys to read and use as examples, you can sign up to a guest account with IEEE ComSoc Digital Library which will give you free access, at the time of writting, the IEEE ComSoc Digital Library website was down, so I've not yet been able to verify this.

IEEE Communications Surveys and Tutorials is targeted for the generalist throughout the field of communications and communications networking. Intended readers include those involved in research, development, deployment, or instruction in fields related to communications.

All surveys should be tutorial in nature and should be written in a style comprehensible to readers outside the speciality of the article.

Typically, mathematical equations should be kept to a minimum, and not be used unless they are vital to the presentation. Articles intended to instruct in a mathematical area should be presented at a level comprehensible to readers with appropriate backgrounds, and the appropriate background should be carefully delineated in the introductory section of the article.

The term survey, as applied here, is defined to mean a survey of the literature. A survey article in IEEE Communications Surveys & Tutorials should provide a comprehensive review of developments in a selected area, covering its development from its inception to its current state and beyond, and illustrating its development though liberal citations from the literature. Such citations would naturally lead to an authoritative and comprehensive bibliography. The objective is to provide the reader with a sense of the history, development, and future of the topic area, including its interactions with other areas, and enough information to comprehend the development and identify the major players.

As an example, the article "A survey of markup languages" might discuss a number of markup languages, such as WML, XML, HTML, CHTML, and voiceXML. The article might define the term "markup language" and describe some general features and objectives by way of introduction. The article might then provide a time-line of events leading to the advent of markup languages, citing major milestones and breakthroughs. From there, the article might describe the markup languages in chronological order, showing how previous languages developed from previous ones through liberal citations to the literature. The article might conclude by giving the author's well-thought-out opinions on the future.

References must be numbered sequentially, not alphabetically. The basic reference format is: [#] L. Brakmo and L. Peterson, " TCP Vegas: End to End Congestion Avoidance on a Global Internet," IEEE JSAC, vol. 13, no. 8, Oct. 1995, pp. 1465-80.

Authors must clearly state the category of the article in the abstract and again in the introductory section and also clearly state the scope of the article. For example, there must be a statement of the form "This article surveys the literature over the period 1990-2001 on turbo codes as they apply to wireless communications."

Authors are encouraged to consider inclusion of multimedia materials in cases where such material would substantially improve the value of the article to the reader. HOW ???

Figures and tables should be used liberally. 

There are no limits on paper length, number of figures, references, etc.

Required formats for electronic submission is PDF.
Submit survey's using the LaTex structure. Include the compiled pdf, figures (as eps files with fonts embedded), bios and photos in the final article, keywords, and abstract
(Note: For the best presentation of your article's entry in IEEE Xplore, do not include equations in the abstract.)

Once the survey is complete it's submitted via the ManuscriptCentral website






Wednesday 28 November 2012

Ocaml 2 HTML

As I'm often adding OCaml code to blog posts I really wanted to find an automatic way to add syntax highlighting. The first solution that I have found is caml2html but I'm still looking for something better ... suggestions welcome

System programming in OCaml - Part 1

This series of articles will follow my journey through "Unix system programming in OCaml", available as a pdf here. After this series, I hope to move onto a series on Mirage system programming in OCaml and working with Signposts (a framework for managing end-to-end connectivity between devices using DNS infrastructure for signalling)

Introducing the Sys and Unix

The modules that give access to the system in OCaml are:
  • Sys - functions common to all OS's that run OCaml
  • Unix - functions specific to unix
To make use of these modules in some OCaml code, we can add open Sys or/and open Unix to the top of the OCaml program.

NOTE that Unix and Sys can overwrite some of the functions in the Pervasive module, so to access a function from the Pervasive module you need to add Pervasives. in front of the function call.

When using ocamlc to compile OCaml programs that made use of  Unix, you need to pass unix.cma to the compiler e.g.

$ ocamlc unix.cma hello.ml -o hello

The same is not true of sys.cma

PASSING INFORMATION TO YOUR PROGRAM

Now we are going to consider 2 different ways of passing information from your terminal to your ocaml program

1) Passing the information as arguments to the executable. For this we are going to use Sys.argv which will return a string array of arguments passed to the program. The first index of the argument array that we use here is 1, this is because the 0th element in the array is the command used to call the program. Consider the following simple example:



open Sys;;
print_string argv.(1)
 

Now provided that at least one argument is passed to the program, this argument will be printed. We can now extend this program, to print the number of arguments and then exactly what the user will have just entered

open Sys;;

let args = Array.length argv;;
print_int args ;;
print_newline ();;
for i=0 to args-1 do
  print_string argv.(i);
  print_char ' ';
done;
2a ) Passing information using the environment variables, this can be fetched from within the OCaml programing using Sys.enviroment, this will return as array of environment variables

open Unix;;

let env = environment();;
for i=0 to (Array.length env) -1  do
 print_string env.(i);
 print_newline);
done;

Don't forget then when you compile this, you need to add unix.cma to the command as we are making use of the Unix library

2b ) We can also lookup the values of environment variables using the Sys.getenv (or Unix.getenv) functions that takes a variable name and returns the value associated with it

open Sys;;

let var = argv.(1);;
print_string (getenv var)

Exceptions

Unless otherwise stated in the documentation, all function in the Unix module raise the exception Unix_error.

Exception Unix_error of error * string * string

The first argument is the error code, the second argument is the name of the system call that raised the error and third argument identifies the object on which the error was called.

If an exception reaches the top-level then the program will halt. The Unix module provides a function for clearly describing exceptions. We can make 2a use this function as follows:

open Unix;;

let prog () = 

  let env = environment();;
   for i=0 to (Array.length env) -1  do
    print_string env.(i);
    print_newline);
   done;

 done;

 handle_unix_error prog ();;



LaTeX - The IEEE Surveys & Tutorials Way (Pt 1)

This article aims to give an overview of setting out a survey for submission to an IEEE Journal.

For this article, I will be using ubuntu 12.10, 32 Bit and Vim as my text editor.

IEEEtran is the offical LaTeX class for authors of IEEE transaction journals and coferences

My primary source of information for this article is the latest version of the IEEEtran package IEEEtrans director. Other helpful information is available here.

INSTALLATION & SETUP

The essential book on LaTeX
The IEEEtrans directory (as linked above) includes a "bare bones example of a IEEE journal, called bare_jrnl.tex. We will now use the IEEEtran LaTeX class to compile this .tex file into a pdf file.

To find out the location that we need to place IEEEtran.cls in, use:

$ locate article.cls

For me, the first location returned is /usr/share/texlive/texmf-dist/tex/latex/base/article.cls

I now need to move the IEEEtran.cls that I download into the same directory as article.cls. So move the the IEEEtrans directory and execute:

$ sudo cp  IEEEtran.cls <location-of-article.cls>

You can now tell Tex about this new LaTeX class using:

$ sudo texthash

Latex is already installed on my system but to allow us of the IEEEtran class, you may also need:

$ sudo apt-get install texlive-fonts-recommended


If you get an error of the form:
Font OT1/ptm/m/n/9=ptmr7t at 9.0pt not loadable: Metric (TFM) file not found
Then it is likely that you need to install the texlive-fonts-recommended package.

Now we are going to compile the bare_jrnl.tex, by moving to its directory and excauting:

$ latex bare_jrnl.tex

You can now view the outputted document using:

$ xdvi bare_jrnl

NEXT STEPS

Now you have a bare bones copy of your paper, you can customize it to meet your specific requirements and add the content of your paper. I will look at this in more detail tomorrow. is the Information for Authors