San's
San's

Reputation: 1

Skip password prompt using sh script

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

Upvotes: 0

Views: 3245

Answers (1)

redneb
redneb

Reputation: 23850

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.

Upvotes: 2

Related Questions