List of servers that are NOT authorized for password-less SSH

Hello friends,

We have around 500 servers (HPUX, AIX and linux) and all of them need to be accessed from our management box (linux) via password-less ssh.

Out of 500 around 150 servers are setup password-less. We need to setup password-less SSH for remaining servers. First we need to get the list of servers for which password-less SSH not working (around 350).

I tried keeping all the 500 servers names in a text file and ran ssh to every host in a loop but most of them are asking for password and it is lot of manual work to note them each box.

Is there any script which can generate list of servers for which password-les ssh not working without any manual intervention?

Pl advise, Thanks a lot,

Something like this?

#!/bin/bash

user=root
while read ip
do
  ssh -oNumberOfPasswordPrompts=0 $user@$ip 'echo' >/dev/null 2>&1
  [[ $? -ne 0 ]] && echo $ip >> no_ssh_server_list
done < server_list

--ahamed

1 Like

im curious, after you get the list of hosts that haven't been set up with passwordless ssh, how would you go about actually setting it up, considering the number of hosts would be around '350', like you said?

are you going to log into each box?

#!/bin/bash

ssh-keygen # generate keys, if not already created

user=root
while read ip
do
  ssh-copy-id -i ~/.ssh/id_rsa.pub $user@$ip >/dev/null 2>&1
  [[ $? -ne 0 ]] && echo 'Error: cannot copy key to '$user@$ip
done < no_ssh_server_list