Recently abandoned non-ssh connection http://www.aliyun.com/zixun/aggregation/14119.html"> Hadoop cluster deployment, or returned to the ssh key authentication on the way. There is some trouble inside, each Taiwan machine must upload the public key.I just again I am a lazy person, so write a few small script to complete, as long as the public key can be distributed in a machine above.
The first is to generate the ssh key script
#! / bin / sh
ssh-keygen -t rsa -P '' -f ~ / .ssh / id_rsa
cp ~ / .ssh / id_rsa.pub ~ / .ssh / authorized_keys
ssh-keygen Generally need to enter the passphrase, but usually three Enter passed, I lazy input, plus-P '' on it.
Then add the public key to the slave's script
#! / bin / sh
read-p "Enter the remote server IP:" ip
ssh-copy-id -o StrictHostKeyChecking = no -i ~ / .ssh / id_rsa.pub root @ $ ip
ssh root @ $ ip 'sed -i "s / ^ # RSAAuthentication \ yes / RSAAuthentication \ yes / g" / etc / ssh / sshd_config'
ssh root @ $ ip 'sed -i "s / ^ # PubkeyAuthentication \ yes / PubkeyAuthentication yes / g" / etc / ssh / sshd_config'
ssh root @ $ ip 'sed -i "s / ^ # PermitRootLogin \ yes / PermitRootLogin \ yes / g" / etc / ssh / sshd_config'
ssh root @ $ ip 'service sshd restart'
hostname = `ssh root @ $ {ip} 'hostname'`
echo "Add the host name and IP to the local / etc / hosts file"
echo "$ ip $ hostname" >> / etc / hosts
echo "The remote host host name is $ hostname, check / etc / hosts to ensure that the host name and IP are added to the host list file"
echo "host public key copy completed"
Then the third script reads the host list and copies / etc / hosts to all the hosts
#! / bin / sh
cat / etc / hosts | while read LINE
do
ip = `echo $ LINE | awk '{print $ 1}' | grep -v" :: "| grep -v" 127.0.0.1 "`
echo "Copying / etc / hosts to $ {ip}"
scp -o StrictHostKeyChecking = no / etc / hosts root @ $ {ip}: / etc /
done