Sunday 19 August 2012

SSH client and daemon: Introduction


SSH client application allows you to logging in a remote computer, or execute commands remotely.

It is also able to execute graphical applications, and to forward TCP ports from and to local and remote machines.

SSH establishes a securely encrypted communication between local and remote hosts along an insecure network.

For SSH client to work it needs to connect to a SSH server in the remote computer.


INSTALL SSH AND SSHD


SSH program binaries are:

ssh — OpenSSH SSH client (remote login program)
sshd — OpenSSH SSH daemon


In Debian or Ubuntu:

$ sudo aptitude install openssh-client # installs ssh client

$ sudo aptitude install openssh-server # installs sshd daemon


CONFIGURE SSH CLIENT

Sunday 12 August 2012

Calculate a PRIME number LIST using C language


This C program calculates a list with first prime numbers.

Build the program


C is a compiled language, so we will need to install a C compiler: gcc
$ sudo aptitude install gcc

We copy this text in a file, e.g: prime_calculator.c

Next we compile the file:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall

or if we want further optimization:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall -O3

-lm option links the math library so we can calculate square roots.

Execute the program


After compilation, an executable appears: prime_calculator.
$ chmod a+x prime_calculator # we grant it execution permission.

If we want to show first ten prime numbers:
$ ./prime_calculator 10
PRIME LIST:
2 3 5 7 11 13 17 19 23 29

If we pass more than two arguments, it calculates the prime list but does not show anything. Just to measure its execution time:
$ time ./prime_calculator 10 *
real 0m0.008s
user 0m0.004s
sys 0m0.000s