Friday 6 September 2019

Check for SSH connectivity to multiple hosts

Checking SSH connectivity from one server to multiple hosts
Condition: All the hosts/IP's should have same username and password

Step 1: Create a file with name "ipFile" and insert all the hostnames/IP's line by line
Step 2: Create a file checkSSH.sh with below code
#/bin/bash
export user="username"

export pass="password"
export SSHPASS=$pass
>output
for i in `cat ipFile`
do
sshpass -e ssh $user@$i -q "echo $i is Accessible" >>output
done
Step 3: Edit "username" and "password" with your target IP's user and password
Step 4: Run above file using command : sh checkSSH.sh
Step 5 : A new file with name "output" will be created with the details


Below steps are useful if you don't have expect and sshpass utility
Condition : All IP's have same username

Step 1: Create a file with name "ipFile" and insert all the IP's line by line
Step 2: Create a file checkSSH.sh with below code
#/bin/bash
user="username"
>output
for i in `cat ipFile`
do
ssh -o "StrictHostKeyChecking no" $user@$i -q "echo $i is Accessible" >>output
done
Step 3: Edit user="username" with your linux user
Step 4: Run above file using command : sh checkSSH.sh
Step 5: Give password one by one
Step 6 : A new file with name "output" will be created with the details

No comments:

Post a Comment