I want to do SSH with username and password to multiple servers need to know option to put username password in below script
for HOST in $(cat ping.txt ) ; do ssh $HOST "ping -c 10 google.com" ; done
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can use sshpass, but better to use ansible. Example of sshpass usage:
# vim server.list 192.168.0.100 192.168.0.101 # apt-get install sshpass $ vim script.sh #!/bin/bash while read -r line do echo "running $line" SSHPASS=PASSWORD sshpass -e ssh-copy-id USERNAME@"$line" -o "StrictHostKeyChecking no" done < "server.list"
$ sh script.sh running 192.168.0.100 ... Number of key(s) added: 1 running 192.168.0.101 ... Number of key(s) added: 1