0

I have script that inputs the list of server ips and ssh using pem key to run commands but some servers have password i want to skip that so that it take the next ip ? Below is the script:

cat privateiptest-ss | while read LINE
do
echo $LINE >> ss-prodcht1.txt
stackname=$LINE
ssh -o "PasswordAuthentication=no" -o "StrictHostKeyChecking no" -t -t -i key.pem ec2-user@$stackname "bash -s" <  sh.sh
done
1
  • That won't work. A password request and "normal" output is separate, done by separate scripts or programs. That is due to security issues so that things cannot be automated, just as you try to do ;-)
    – arkascha
    Commented Sep 11, 2016 at 21:47

1 Answer 1

2

If you use the option BatchMode=yes with ssh, i.e.

ssh -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -t -t -i key.pem ec2-user@$stackname "bash -s" <  sh.sh

then ssh will never prompt for a password. For servers that do require a password, ssh will fail.

2
  • Thank you so much this is what i wanted hope this will not break anything ?
    – San's
    Commented Sep 12, 2016 at 3:26
  • @San's I cannot possibly know if it will break anything, but it will do it will do what you were asking for. You'll just have to test it yourself.
    – redneb
    Commented Sep 12, 2016 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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