Thanks ilikecows for a very useful solution.
For a moment i thought this would be the best solution that you provided.
However, i can see another problem.
The problem is that this script connects to any server (specified by the user) in the network.
It means that there might be a new server coming up in the network all of a sudden and when a user runs this script, it should be able to login automatically without user intervention.
If i follow your solution, i would have to login into each and every server (that the script is goin to login ) and copy the id_rsa.pub there, which again doesn't help me as i have to give this script to the users and it wont be good to ask them to do the above tasks.