I have one master and four slave computers. I generated rsa public/private key on master PC. Then I copied publickey (id_rsa.pub
) to slave machines as authorized_keys
.
It doesn't ask password when I invoke SSH like this on master PC's terminal:
ssh –o UserKnownHostsFile=/dev/null –o StrictHostKeyChecking=no hduser@slave1
I wrote this script to automatically login slave machines without asking password.
SERVER_LIST=`cat /home/hduser/slaves` # slave1, slave2 ...
for host in $SERVER_LIST; do
host=hduser@$host
ssh –t –o UserKnownHostsFile=/dev/null –o StrictHostKeyChecking=no $host;
done
SSH is asking slaves passwords when I use this script. I'm getting this message when use SSH with -vv
option:
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/id_rsa ((nil))
debug2: key: /root/.ssh/id_dsa ((nil))
debug2: key: /root/.ssh/id_ecdsa ((nil))
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
hduser@slave1's password:
I changed permissions on master PC and slave PC.
sudo chmod 755 /home/hduser
sudo chmod 700 -R ~/.ssh
sudo chown hduser ~/.ssh
It doesn't ask password when I invoke SSH on terminal but It still asking password when invoke it in script. What am I missing? How can I fix it?
hduser
runs this script as root on Master PC.root
. I generated them withhduser
as root. It works correctly if I invoke ssh on Master PC's terminal. It doesn't work in script.id_rsa
andid_rsa.pub
under/home/hduser/.ssh/
directory to/root/.ssh/
.