2

I encountered a problem on how to achieve password-less login between any two nodes in a server cluster. Now I have a server cluster consists of 10 nodes with following ip addresses:

192.168.0.1 # node1
192.168.0.2 # node2
...
192.168.0.10 # node10

My username on these three nodes are all xyz, and the system on these nodes are all Ubuntu14.04.

This seems to be a canonical question and should have been answered in many places, but my search using Google only tell me the solution for two nodes. For example, pass the public key generated in node1 to the authorized_keys file in node2, ..., node10 to allow password-less login from node1 to the rest nodes. But how to scale this method to any two nodes in a server cluster? should we manually generate public key in every node and copy the public key of each node to the rest nodes? Is there a general and convenient method?

1

If you have a cluster setup, you likely have a shared file system. If so, then you can just add the SSH key to the server itself. If it connects to another server it will find its own key in the list of authorized keys. Then you can connect from any server to any server.

In case they have different file systems you need to do this manually. Either you create a new SSH key for the xyz user and ssh-copy-id that to each of the other servers. This scales like N² with the number of servers, that is not cool.

You can generate one SSH key and copy it to all the machines to /home/xyz/.ssh/id_rsa and id_rsa.pub. Then register this key with all the machine. Now you can log in from any server to any other server using the same SSH key.

In order to deploy this I'd write a quick script that uses scp and a for-loop to iterate through the servers.

  • Brilliant answer! My file system are not shared due to some issues. So like you said, I copy the private/public keys of node1 to rest nodes and register the public keys therein. Finally, it works. Thanks a lot! – ROBOT AI Oct 1 '16 at 12:08
  • As an expansion on "a quick script", if the machines are centrally managed, that tool (puppet, ansible, chef, ...) can be used to push user authorized_keys files to each machine. – user4556274 Oct 1 '16 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.