Passwordless SSH Access

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
2
su - mpiuser                   ~ switch to the mpiuser user
exit ~ exit that user session and go back to the `pi` 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
2
3
su - mpiuser
ssh-keygen -t rsa ~ same to the default location `/home/mpiuser/.ssh/id_rsa`
~ passphrase `raspberry` - secure right? :D

-t rsa is the encription type

1
2
3
ssh-copy-id mpiuser@node3     ~ copys the ssh key to node3 (this would need to be done for nodes2/4)
ssh node3 ~ should now ask for the passphrase
exit ~ go back to node1

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
2
3
# keychain magic
/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

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
2
3
4
ssh-keygen -t rsa                             ~ default location `/home/pi/.ssh/id_rsa`
~ blank password
ssh-copy-id -i ~/.ssh/id_rsa.pub pi@node3
ssh pi@node3

node3

1
2
3
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub pi@node1
ssh pi@node1

This will copy the keys to

1
.ssh/authorized_keys

References