0

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?

  • 1
    Who is the script running as? What user? – Canadian Luke Mar 21 '14 at 17:59
  • Logs suggest you're running the script as root; did you generate your SSH keys id_* and save them to /root/.ssh on the master? – ernie Mar 21 '14 at 18:01
  • hduser runs this script as root on Master PC. – Eyüp Alemdar Mar 21 '14 at 18:02
  • No, I didn't generate public/private keys with root. I generated them with hduser as root. It works correctly if I invoke ssh on Master PC's terminal. It doesn't work in script. – Eyüp Alemdar Mar 21 '14 at 18:05
  • Thk yout @ernie, It works after copied id_rsa and id_rsa.pub under /home/hduser/.ssh/ directory to /root/.ssh/. – Eyüp Alemdar Mar 21 '14 at 18:14
0

The SSH logs show that the login session is looking in /root/.ssh/ for the credentials, which implies your script is running as root.

Either copy your id_* files to /root/.ssh, generate the appropriate credentials as root, or run the script as the user where you have the credentials saved.

  • Is there a way to change this looking directory /root/.ssh/ to /home/hduser/.ssh/? – Eyüp Alemdar Mar 21 '14 at 18:42
  • Yes, run the script as hduser instead of in a su or sudo environment . . . – ernie Mar 21 '14 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.