How to Setup Password-less SSH between Vagrant Nodes
How to Setup Password-less SSH between Vagrant Nodes
UPDATE: Since my original post, I've changed:
* ssh-keygen should be executed as the vagrant user.
* copying the public keys should be done as the vagrant user.
* there is no reason to avoid the 'Warning' message by running "ls -l" into the nodes via ssh.
* run ssh-keygen for both dsa and rsa.
I make no claims the process below is the best technique. It does seem to work. The steps below are for a three node cluster.
1. When provisioning, run the following commands as root. These commands provide each node with its own private and public keys. And copy the public keys to the shared directory.
mkdir -p /home/vagrant/.ssh
chmod 700 /home/vagrant/.ssh
su vagrant -c "ssh-keygen -t rsa -P '' -f /home/vagrant/.ssh/id_rsa"
mkdir -p /vagrant/files/ssh
* ssh-keygen should be executed as the vagrant user.
* copying the public keys should be done as the vagrant user.
* there is no reason to avoid the 'Warning' message by running "ls -l" into the nodes via ssh.
* run ssh-keygen for both dsa and rsa.
I make no claims the process below is the best technique. It does seem to work. The steps below are for a three node cluster.
1. When provisioning, run the following commands as root. These commands provide each node with its own private and public keys. And copy the public keys to the shared directory.
mkdir -p /home/vagrant/.ssh
chmod 700 /home/vagrant/.ssh
chown -R vagrant:vagrant /home/vagrant/.ssh
mkdir -p /vagrant/files/ssh
cp /home/vagrant/.ssh/id_rsa.pub /vagrant/files/ssh/`hostname`.pub
2. Create a file called /vagrant/files/post_spinup_sudo_setup_ssh.sh with the contents below. Use chmod to make it executable. This file will get run as root after the nodes are started and configured.
# Add nodes to known hosts to avoid the security question.
#
ssh-keyscan -t rsa affy-master affy-slave1 affy-slave2 > /etc/ssh/ssh_known_hosts
ssh-keyscan -t dsa affy-master affy-slave1 affy-slave2 >> /etc/ssh/ssh_known_hosts
3. Create a file called /vagrant/files/post_spinup_setup_ssh.sh with the contents below. Use chmod to make it executable.
sudo /vagrant/files/post_spinup_sudo_setup_ssh.sh
# Copy the public keys to the authorized keys file.
#
cat /vagrant/files/ssh/affy-master.pub >> /home/vagrant/.ssh/authorized_keys
cat /vagrant/files/ssh/affy-slave1.pub >> /home/vagrant/.ssh/authorized_keys
cat /vagrant/files/ssh/affy-slave2.pub >> /home/vagrant/.ssh/authorized_keys
4. After 'vagrant up' is complete. Run the following:
vagrant ssh master -c /vagrant/files/post_spinup_setup_ssh.sh
vagrant ssh slave1 -c /vagrant/files/post_spinup_setup_ssh.sh
vagrant ssh slave2 -c /vagrant/files/post_spinup_setup_ssh.sh
5. Done!