While setting up my Raspberry Pi Cluster I needed passwordless SSH access between the master and worker nodes. There are a few ways to do this which I detail below.
Check if the SSH key exists
1 | ls -l ~/.ssh/id_rsa.pub |
Keychain
The Keychain
steps below allow for passwordless SSH access from node1
to node3
.
Keychain is a manager for ssh-agent.
1 | sudo apt-get install keychain |
Setup Common User
The steps below are based on the work by Ben Heidorn - udemy.com
A common user is needed on each node to allow the nodes to authenticate and execute the MPI commands. I used the username mpiuser
. By default the PI’s install with the user PI
and password raspberry
.
node1:
1 | sudo useradd -m -u 2345 mpiuser |
-m
creates the home directory, -u
is the user id, I think you can use any user id as long as they are same on all nodes.
1 | sudo passwd mpiuser ~ raspberry for both prompts, secure I know! |
Now login as user mpiuser
to test it works
1 | su - mpiuser ~ switch to the mpiuser user |
Repeat the same for node3, this can be done over SSH using the PI user. You can connect using ssh pi@node3
. When done run exit
to fall back to node1.
Setup Generate SSH Keys
Allow each node to authenticate using SSH (Secure Shell) using public & private keys.
node1:
1 | su - mpiuser |
-t rsa
is the encription type
1 | ssh-copy-id mpiuser@node3 ~ copys the ssh key to node3 (this would need to be done for nodes2/4) |
To allow the user to login without a password/passphrase. This is done on the Node1 (master)
1 | nano .bashrc |
At the bottom of the file add
1 | # keychain magic |
After saving the file recompile it by running
1 | source .bashrc |
Now you should be able to run ssh node3
and not be asked for a password.
No passphrase
node1
1 | ssh-keygen -t rsa ~ default location `/home/pi/.ssh/id_rsa` |
node3
1 | ssh-keygen -t rsa |
This will copy the keys to
1 | .ssh/authorized_keys |