Updating Firefox to Latest Version

I was having troubles with updating firefox on linux. The update firefox window used to get stuck on
“connecting to server”. So I wrote this simple script to update firefox. Hope it helps.

#!/bin/bash

url="http://ftp.jaist.ac.jp/pub/mozilla.org/firefox/releases"
ver="10.0.2"
arch="linux-i686"
lang="en-US"
tarname=""
tar="tar.bz2"
download=1

isroot(){
uid=`id -u`;
if [ $uid -ne 0 ]
then
echo "the script must be used in elevated mode";
exit;
fi
}

parseargs(){

while getopts "nv:a:l:" ARGS
do
case $ARGS in
v)
ver=$OPTARG
;;
a)
arch=$OPTARG
;;
l)
lang=$OPTARG
;;
n)
download=0
;;
?)
echo "invalid arguments"
exit
;;

esac
done

}


create_url(){

tarname="firefox-$ver"
url=$url/$ver/$arch/$lang/$tarname.$tar;
}




fetch_firefox(){

if [ $download -ne 0 ];then
curl $url -o "$tarname.$tar"
fi

}

update_firefox(){

tar -xf ./$tarname.$tar -C /tmp
if [ -d /usr/lib/$tarname ];then
#rm -rf /usr/lib/$tarname
#to be safe
echo "please remove /usr/lib/$tarname directory manually and re-run the script with -n as a parameter"
exit
fi
cp -r /tmp/firefox /usr/lib/$tarname
rm /usr/bin/firefox
ln -s /usr/lib/$tarname/firefox /usr/bin/firefox

}

isroot;
parseargs $@;
create_url;
fetch_firefox
update_firefox

This script needs to be run in elevated mode with all the optional parameters:
1. -v version_number: e.g -v 10.0.2. At the time this code was written the version was 10.0.2, so I kept it the default version.
2. -a cpu arch type: one of the two: linux-i686 or linux-i86_64. Default type is linux-i686.
3. -l language: the language of firefox, default is en-US.
4. -n : this switch can be used if the tar is already downloaded and located in the current folder of the script.

I havent done any error checking, so if the script fails you wont get much info about the failure.

example usages:
1) ./updatefirefox.sh -v 10.0.2 -a linux-i86_64: To update to 10.0.2 on x86_64 arch.
2) ./updatefirefox.sh -v 10.0.2 -l en-GB: To update to 10.0.2 on en-GB locale.
3) ./updatefirefox.sh -v 10.0.2 -n : To update firefox with an already downloaded tar file located in the
current folder.

Feel free to modify the script to improve it. If there is some serious bug in the code, please let me know.

And although it is trivial for many of us but if its not then the challenge for you is to figure out how to
find out the language code? 🙂

If I get some time, I will improve the script and also give a detailed explanation of how it works. Till then Share the Firefox Love. 🙂

Linux Exile

After using linux for 3 years, I have been forced to use windows, and the transition is everything but smooth. People say linux has a very steep learning curve and users have to learn a lot to migrate to linux from windows. But no one will tell you that when you migrate from linux to windows, the unlearning curve is even steeper. 😀

We coders have a basic desire to automate things. And for simple tasks like, finding lines which match a pattern(grep), replacing a particular pattern(sed) I wouldnt be willing to write a c++ code. Leave alone c++, when I can write a single command for the task, I dont even like to write a perl script. Also the dos shell is horrible, and although I havent explored with powershell but at the first look I found it too weird. I found an alternative to shell in form of cygwin but it fails to give the same feel. 😦

Apart from the power of shell, the things I miss include multiple desktops(tried to mimic using two monitors ), the scrolling feature where you can scroll a page from an inactive windows by putting the mouse pointer over it(no altervative found) and the all powerfull text editors(gedit and vim, however notepad++ solves this problem). Also I always make a mistake in paths of file and I guess you know the reason.

But as I have no other option, I guess I will use it as an opportunity to delve deep into the windows and to find ways to make it more and more like my home linux. I will keep you updated on the progress.

My Own Stat Counter

After reading and implementing the fascinating sleeping-barber problem, readers-writers problem, and the likes, I thought lets create a problem of my own. And so I made up my own problem: Stat Counter Problem.

I have made a simple stat counter using the semaphores provided by pthread library.  When a user opens the desired webpage, a script executes which establishes a connection with a c executable which is the stat counter. The c executable reads a file which stores the current count, increments the contents by one and writes into the file and also sends the value to the script which connected to this c executable. The file operations are done in Critical Section guarded by semaphores.

The codes are as follows:

stat.php: The script on the webpage.


<?php
$host="172.16.25.98";
$port="8080";
$connected=FALSE;
if(($sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP))!==FALSE){
 if(@socket_connect($sock,$host,$port)!==FALSE){
 $connected=TRUE;
 }
}

if($connected==FALSE){
 echo "<p>Error connecting to the stats counter, this means, your hit was not recorded.</p>";

}
else{
 socket_write($sock,$ignorecount);//$ignorecount to 1 if you dont want to count
 $count = socket_read($sock,10);
 $count = substr($count,0,strlen($count)-1);
 $count =(int)$count;
 echo "No. of hits: ".$count;
}
?>

stats.c:The C executable which actually implements the stats counter.


#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>
#include <unistd.h>
#include <signal.h>
#define SERVER_PORT "8080"
#define BACKLOG 10

sem_t fileaccess;

void stats(int sock_fd,int file_fd){
 char buf[10];
 recv(sock_fd,buf,sizeof(buf),0);
 sem_wait(&fileaccess);
 int size = lseek(file_fd,0,SEEK_END);
 if(size == -1){
 printf("error in opening file\n");
 sprintf(buf,"Error reading the stats\n");
 send(sock_fd,buf,(strlen(buf)+1),0);
 sem_post(&fileaccess);
 exit(1);
 }
 else if(size == 0){
 printf("opened file for the first time\n");
 if(!ignorecount)
 strcpy(buf,"1");
 else
 strcpy(buf,"0");
 write(file_fd,buf,2);
 }
 else{
 lseek(file_fd,0,SEEK_SET);
 printf("size:%d\n",size);
 int nbytes = read(file_fd,buf,size);
 if(!nbytes){
 printf("error in reading\n");
 close(file_fd);
 sem_post(&fileaccess);
 exit(1);
 }
 int count=0, i=0;
 printf("buff:%s",buf);
 size--;
 while(i<size){
 count = count*10 + (buf[i]-'0');
 i++;
 }
if(!ignorecount){
 count++;
 }
 printf("count%d\n",count);
 sprintf(buf,"%d",count);
 size = strlen(buf);

 lseek(file_fd,0,SEEK_SET);
 write(file_fd,buf,size+1);

 }
 send(sock_fd,buf,(strlen(buf)+1),0);
 printf("hit\n");
 close(file_fd);
 sem_post(&fileaccess);
 exit(0);

}

int main(){
 struct sockaddr_storage their_addr;
 socklen_t addr_size;

 sem_init(&fileaccess,0,1);

 struct addrinfo hints, *res;
 int sockfd,new_fd;
 memset(&hints,0,sizeof(hints));

 hints.ai_family=AF_UNSPEC;
 hints.ai_socktype=SOCK_STREAM;
 hints.ai_flags=AI_PASSIVE;

 if(getaddrinfo(NULL,SERVER_PORT,&hints,&res)){
 printf("error connecting\n");
 exit(1);
 }

 sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
 if(sockfd==-1){
 printf("Error creating socket\n");
 exit(1);
 }
 printf("Socket created successfully\n");
 if(bind(sockfd, res->ai_addr, res->ai_addrlen)==-1){
 printf("Error binding to socket\n");
 exit(1);
 }
 printf("successful bind now listening at port no.%s\n",SERVER_PORT);
 listen(sockfd, BACKLOG);
 pid_t pid;

 int file_fd=open("./count",O_RDWR|O_CREAT,S_IRWXU|S_IROTH|S_IRWXO);
 if(file_fd==-1){
 printf("error opening file, exiting...\n");
 }
 signal(SIGCHLD,SIG_IGN);

 while(1){

 addr_size = sizeof their_addr;
 new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size);

 pid = fork();

 if(!pid){
 close(sockfd);
 stats(new_fd,file_fd);
 }

 close(new_fd);
 }
 close(file_fd);
 close(sockfd);

 return 0;
}

I have tested the code using the following bash script.


#!/bin/bash

count=0;
totalcount=$1;
echo $1;
while [ $count -le $totalcount ]
do
 wget --no-proxy http://localhost/template10/stats.php  2>> log &
 echo "\nPresent count is: $count";
 count=$((count + 1));
done

Observations:

  • The total count registered by the stats counter is equal to or greater than the totalcount specified in the script. The count is greater in the cases where wget encounters race conditions and gives the error: “xyz file sprung up retrying”.  The extra count is equal to the no. of such errors.
  • When the file count(which stores the current count) is opened in vim, a warming [noeol] is given.
  • As obvious from the stats.php code, I had to splice the last character of the output hits, else a garbage character was being shown.

If you have solutions or comments on the above observations, please let me know.

Get your hit counted by visiting my website:

What I learnt from Stallman

Mr Richard Stallman, the president of the Free Software Foundation, delivered a lecture at IIT Guwahati in the Lecture Series organised by Techniche on 4th September, 10. Here’s a detail of what all I came to learn from him.

A software is free if it ensures the following 4 basic rights to each of its users:
0. The user has the freedom to run the software as and where he/she wishes.
1. The user has the freedom to check-out the source code of the software to find out what exactly the software does and has the freedom to modify it according to his/her needs.
2. The user has the freedom to distribute and share the exact copy of the software.
3. The user has the freedom to distribute and share the modified version of the software.

A software which violates any one of the above mentioned is termed as proprietary software or in his terms a ‘Malware’. The developer of these softwares force your computers to work as they wish thereby captivating it. He termed this as the ‘Digital Colonisation’.

So with these four basic rights in mind, Mr Stallman started doing what he could do best with the skills he got. He started creating the GNU-OS, to provide alternatives to all the people who want to get rid of this ‘Digital Colonisation’. He started off in 1983 and as the beginning years of 1990s started to advent, he was prepared with almost everything except the kernel. He started on a project to develop micro-kernel based OS, but it had a lot of flaws and morover at the same time Linus Torvalds came up with an OS of his own named linux. So this linux kernel got embedded within all other GNU softwares thus creating the OS GNU/Linux.

Mr Stallman was disappointed by the general widespread use of linux to denote this amalgamated OS. Linux was based on completely different principles of providing a powerful software, wheres GNU denotes the philosophy of freedom of software. So by using the term linux instead of GNU/Linux people are being driven to a completely different philosophy unknowingly. Morover, it is undermining the efforts of the people who contributed to the various GNU projects which is a major part of GNU/Linux OS.

The term open-source software was coined in 1998 to denote the principles of linux. The aim of the open source software is to create a powerful software. It never states that the software should ensure those 4 basic rights. This is what concerns Stallman, that people are confusing the Free Software Movement with the Open Source Movement.

He contradicted the fears that if all the software in the world was free, then IT industry will become worthless and lose jobs. He said that instead it would create jobs, because all the free sourcecode available is to be tailor made for the clients which typically are big companies or government agencies.

Check out the following videos.

Some of his quotes which I liked the most:

“If you are using a proprietary software, and your friend says that it is very nice and asks you for a copy, then you are in a dilemma. You have to choose between the two evils. Whether you would share it with your friend and break the agreement with the developer of the software, or you would be ungrateful to your friend and honour the license. If you were to choose, you should choose the first option considering your friend is not as evil as the developer of those proprietary softwares.”

“An article mentioned that I was the father of the open source software. I wrote back to the editor that if it were to be true, then the child that was conceived(open source) was a product of artificial insemination with sperms stolen from me without my knowledge and consent”.

The Shabang

“#” + “!”, the sharp(#) + the bang(!), the shabang can be seen on top of scripting files like a shell script or a perl script. So when shell recognizes a shabang, it treats the text following it to be the command to be invoked with the current file as argument. So when I execute a file , say hello.


#!/bin/bash

echo "Hello World"

what happens is it is interpreted as /bin/bash ./hello. Now the bash interpreter reads the file hello, but treats the shabang as a  comment, as comments start with ‘#’ in bash.

So let us see what all interesting stuffs can be done using this shabang. To execute these scripts, paste them into files on your PC, change their permissions by: chmod u+x filename. Then execute the file by ./filename.

1. Self-Reading File


#!/bin/cat

 #echo "Hello! I dont want to get printed"

2. Self-Deleting File:


#!/bin/rm

echo "Alas! I would be deleted"

3. Self-Banner file:


#!/usr/games/banner

echo "Alas! I wont be converted to a banner"

Redirect the output to some output file: ./selfbanner > output. The output wont contain the contents of the file, instead it will have “./selfbanner”.

4. Infinite Loop

file: call1


#!/bin/bash

echo "Hello, I am struck in an infinite loop."
$1

file: call2


#!./call1

echo "I am being ignored. "

Now change the permissions and execute ./call2 on the shell and see wat happens.

Bypass 150MB proxy limit

This is a very basic code which takes as an argument the document to be fetched and the approximate size of the document, and fetches the document even though its size may be more than the max 150MB limit as set by IITG proxy server.


#!/bin/sh

maxlimit=$((150*1024*1024));

if [ $# -lt 2 ]; then
 echo "enter an ip to fetch file from and its size";
 exit 1
 else
 if [ $# -gt 2 ]; then
 echo "Only single ip supported as of now";
 exit 1
 fi
fi

ip=$1;
size=$(($2/maxlimit));

i=1;
end=-1;

while [ $i -le $size ]
do
 start=$((maxlimit*i-maxlimit));
 end=$((maxlimit*i-1));
 curl --range $start-$end $ip --output filename$i &
 i=$((i+1));
done
end=$((end+1))
curl --range $end- $ip --output filename$i &

To run this code. Download it and save it into a file say “curlip.sh”. Now type

$chmod +x curlip.sh

This gives the file, the permission to execute.

now to use type:

$ ./curlip ipname size

ipname= exact address of the file to be downloaded. e.g you can try http://netbeans.osuosl.org/6.8/bundles/netbeans-6.8-ml-linux.sh . To dowload netbeans.

size= approximate size of the file. e.g. 257*1024*1024,

This code breaks the document into fragments of size=maxlimit. Then it creates the output files as filename1, filename2, …. filenamen.

You can generate the final document by typing the command.

$cat filename? >outputfilename

This code is just an illustration of the working of curl, and very limited in its capabilities. You can build upon to make it more generic, or solve your own specific purpose.

VIM Art: Splitting screens in vim

Its 2:30am and today at 8:00am I have a quiz of graphics. Dunno about the quiz, but the course did teach me a lot. Just look at the picture. 😀

Dont worry, its just my almighty all powerful Vim showing its art side. And you thought all vim users are nerds, just look at what I did with a simple set of commands.

Let me guide you through the steps. You dont have to be a great linux fanatic for them as they are quite basic. Just open a file in vim. I opened an elf executable file to get that blue texture. Then type these two commands as many times as you wish.

:vsplit

:split

vsplit is a command which splits the screen into two vertical portions, similarly split splits the file into horizontal sections.  You can create interesting designs by applying these commands in different windows. If you want to open another file as a section just type filename after the command. e.g. :vsplit filename.

To move from one window to another just type these commands in normal mode:

<Ctrl-W> j : to move to the window(section) below the current section.

<Ctrl-W> k: To move to the window above the current section.

<Ctrl-W> h: To move to the window to the left side of the current section.

<Ctrl-W> l: To move to the window to the right side of the current section.

Current section is the one where you cursor is blinking.

To close a particular section type :q

To close all the sections and exit type :qall , if any one of the section is not saved, vim refuses to quit. In this case type :wall to save all the files and then type :qall to exit or you can just type :qall! to exit without saving.

If you want to work on a singe window, go to the window using the commands mentioned above. then type : only. Here again type : only! to override changes of other windows, or save the window first.

There are a lot many things you can do with splitting screens, read the manual for further knowledge.

Bash History

To all you lazy linux command line coders and scripters bash has a rich feature to pamper your laziness, The Bash History. Almost all of you might be knowing that pressing the up arrow brings the previous command onto the command prompt, and pressing it some more gives you the less recent ones. But it doesnt end here, actually you ve just started here. Lets explore the rich features the bash history provides us.

The first thing to note here is that bash stores your command history in a file named .bash_history in your home folder. Just open the file and you can see upto the last 500 commands you typed. Delete a command if you wish it to be deleted, modify it or do whatever you.(I trust you’d figure out the reasons for doing so).

Then you have the history command in your linux box which shows you the list of all commands along with their ids. If you need a finer result, you could use the powerful “grep” command which linux provides.

$history | grep ssh
165  ssh -Y 172.16.25.98
166  ssh -Y 172.16.25.98
167  ssh -Y guest@172.16.25.98
169  ssh -Y guest@172.16.25.98
170  ssh -Y 172.16.25.98
309  pintosssh
310  jatingassh
311  labssh
317  ssh $uname@202.141.81.145
319  ssh $uname@$pintos
321  ssh $uname@$pintos

Bash also allows for incremental search on the history list. Use ctrl+r and type the first few letters of the command, the last command from the history list that matches with your string would be displayed.Press Ctrl+R again to find a command further back.Now just press enter to execute the command or press any of the arrow key to bring the command on the prompt and edit it and execute it.
(reverse-i-search)`vec’: g++ vectortest.cpp

But by far the most powerful feature is the bash history expansion. History expansions are implemented by the history expansion character ‘!’. The line selected from the history list is called ‘event’ and portions of that command that are selected are called ‘words’.

The rest of the portion is from the blog of SPS. Refer:http://spsneo.com /blog/
So there are basically three parts to a history expansion all of which are optional and are separated by a colon ‘:’.
1. Event Designators:
a. !n It refers to n’th command in the history.
b. !-n It refers to n’th command in the history from last.
c. !! is an alias for !-1.
d. !string It refers to the most recent command in the history starting with string. It is again an useful expansion when you don’t remember the arguments to a command which you have executed earlier.
e. !?string[?] It refers to the most recent command containing string. The trailing ? may be omitted if string is immediately followed by a newline.

2. Word Designators:

a. n The nth word, count starting from 0. 0th word normally refers to the command. Example:
$sudo cat /etc/resolv.conf     //Instead you want to edit the resolv.conf file
$sudo vi !!:2                       //This is equivalent to sudo vi /etc/resolv.conf
b. ^ This refers to 1st word. This is equivalent to :1 as refered above. The only advantage is that you can omit : (colon) when you use ^. Example:
$cat ~/.bashrc
$vi !!^        //This is equivalent to “vi !!:1” that is vi ~/.bashrc
c. $ This refers to the last word.
d. x-y This refers to a range of words; ‘-y‘ is equivalent to ‘0-y’.
e. * This refers to all the words except the 0th one. This is helpful when you have to execute a command with all the arguments passed to the last command.
f. x* This is an alias for x-$ .

Note: If a word designator is used without an event specification, the last command in the history is used as the event. Example –
$cat ~/.bashrc
$vi !:1 // This is equivalent to vi !!:1 or vi ~/.bashrc

3. Modifiers:

a. h This removes the trailing file name component, leaving the head. Example:
$cat /home/spsneo/.bashrc
$ls !!:1:h //This expands to ls /home/spsneoExplanation: !! refers to the last command and then :1 refers to the 1st word of the last command and then :h removes the trailing file name component i.e., .bashrc . Hence the expansion.
b. t This removes all leading file name components, leaving the tail.
c. r This removes the trailing suffix of the form .xxx , leaving the basename.
d. p Print the new command but do not execute it.
e. s/old/new This substitutes the first occurrence of old with new. Example:
$cat /etc/resolv.conf
$!!:s/resolv/yum //This expands to cat /etc/yum.conf
f. g This is used in conjunction with “:s” modifier. This causes changes to be applied over the entire event line rather than just the first occurrence. Example:
$cat test.cpp test.h
$!!:gs/test/source/ //This expands to cat source.cpp source.hh

Adopt these features to save yourself from a lot of repetitive typing and enjoy the terminal.

Some Interesting Files in Linux

These are some of the interesting device files in linux/ unix-like operating systems:-

1. /dev/null: Also known as null device is a file that discards all data written to it but returns a successful write operation. On reading this file it returns an eof immediately ie no data can be read from the file. It is also known as the black-hole as it can absorb anything.

2. /dev/zero: On requesting a read operation from this file, it returns as many null characters(ASCII value ox00) as requested. All writes to /dev/zero are treated as in the case with /dev/null.

3. /dev/full: It is also know as full device and returns no space left on device when a write is attempted. On reading it returns as many null character as requested similar to /dev/zero.

4./dev/random: It serves as a true random number generator. It allows access to environmental noise from device drivers and other sources.

5. /dev/urandom: Similar to /dev/random but generates pseudo-random numbers.

examples:

1. /dev/null:

As Input: Trying to read 10 bytes from the file but 0 bytes read.

sanmukh@sanmukh-laptop:~$ dd if=/dev/null of=/dev/stdout bs=10 count=1
0+0 records in
0+0 records out
0 bytes (0 B) copied, 2.228e-05 s, 0.0 kB/s

As Output: Trying to write to the file from standard input. 14 characters entered(including enter(\n)), write successful.

sanmukh@sanmukh-laptop:~$ dd of=/dev/null if=/dev/stdin bs=10 count=2
aslkfjaslkjfa
1+1 records in
1+1 records out
14 bytes (14 B) copied, 2.22438 s, 0.0 kB/s

2. /dev/zero:

As Input

sanmukh@sanmukh-laptop:~$ dd of=/dev/stdout if=/dev/zero bs=10 count=2
2+0 records in
2+0 records out
20 bytes (20 B) copied, 5.1962e-05 s, 385 kB/s

3. /dev/full:A  write to the file returns no space left on device.

As output:

sanmukh@sanmukh-laptop:~$ dd if=/dev/stdin of=/dev/full bs=10 count=2
asfkhasf
dd: writing `/dev/full’: No space left on device
0+1 records in
0+0 records out
0 bytes (0 B) copied, 1.2284 s, 0.0 kB/s

4. /dev/random: Three different reads from the file returning different outputs.

sanmukh@sanmukh-laptop:~$ dd if=/dev/random of=/dev/stdout bs=10 count=2
zF2+0 records in
2+0 records out
20 bytes (20 B) copied, 9.7778e-05 s, 205 kB/s
sanmukh@sanmukh-laptop:~$ dd if=/dev/random of=/dev/stdout bs=10 count=2
ːl]�s�+����O��v2+0 records in
2+0 records out
20 bytes (20 B) copied, 9.8616e-05 s, 203 kB/s
sanmukh@sanmukh-laptop:~$ dd if=/dev/random of=/dev/stdout bs=10 count=2
.�p�^ )�T$�=g8}�2+0 records in
2+0 records out
20 bytes (20 B) copied, 9.8336e-05 s, 203 kB/s

Passwordless SSH

No need to mention that ssh is a great tool to securely connect to a remote computer whether it be a desktop or a server. Just issue the ‘ssh’ command with the remote computer as argument, enter the password when prompted and you are done. You are now ready to execute commands on the computer as if you are sitting right in front of it.

But now consider this case. We have setup a server and we want to monitor it on timely basis. The monitoring may involve its CPU usage, disk usage and a lot many parameters which I even don’t know the names. So what we can do is we can write a script which timely logs the details into some file and we can occasionaly log onto the remote system and collect the log files. Solves the purpose but doesn’t sound good for a computer geek na..!!! I mean whats the use of the script when we have to manually intervene periodically?

So what we do is we write a script on our local computer which would periodically log onto the remote computer fetch the details and create the log files in our home comp. But now the problem is that each time the script tries to log onto the remote computer, it would be prompted for a password, thus requiring manual intervention mandatory.Can’t we do better?

Well the answer is provided by the SSH itself. Apart from the password authentication, SSH also supports public key authentication.

To start with open a shell terminal and type ssh-keygen -t rsa on your local computer.(Just keep on pressing enter for defaults.)

sanmukh@sanmukh-laptop:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sanmukh/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sanmukh/.ssh/id_rsa.
Your public key has been saved in /home/sanmukh/.ssh/id_rsa.pub.
The key fingerprint is:
db:b7:28:98:fd:19:16:1a:32:3d:c5:15:93:37:a7:27 sanmukh@sanmukh-laptop
The key’s randomart image is:
+–[ RSA 2048]—-+
|            +o   |
|         . …o .|
|          o  . + |
|       . .    E .|
|      o S .    o |
|       o * .     |
|       +o + .    |
|      o o. = .   |
|         o+ .    |
+—————–+

Now logon to your remote computer and in your home directory create a file named authorized_keys in .ssh directory only if it doesnt exist. Create the .ssh directory if required. Copy the contents of the file id_rsa.pub on your local computer into the file authorized_keys of the remote computer.

Illustration:

$ scp ~/.ssh/id_rsa.pub username@hostcomp:~/

now logon to the remote comp.

$ ssh username@hostcomp

now create .ssh directory if it doesn’t exist.

$ mkdir .ssh

Now you have your id_rsa.pub file in the ~username directory. i.e. your account directory on the hostcomp.

type

$ cat id_rsa.pub >>.ssh/authorized_keys

Now on your local computer type ssh-add.

$ ssh-add
Identity added: /home/sanmukh/.ssh/id_rsa (/home/sanmukh/.ssh/id_rsa)

So now you are done. You can now login to your remote computer with ssh without being prompted for password.