Su servicio está escuchando solo en la dirección de loopback, 127.0.0.1
.
Cuando realiza una conexión desde 192.168.0.21
o cuando especifica la dirección ip
, no funciona, ya que su servicio no está escuchando en ese ip
.
Cuando usa hostname
desde 192.168.0.12
, funciona porque se conecta a la dirección de bucle invertido. Esto se debe a que primero buscará en su archivo de hosts, /etc/hosts
, que tiene una entrada que apunta hostname
a su bucle invertidoip
:127.0.0.1 master1.mycluster
Примерно так:
#!/bin/bash
# I assume "logfile" is the log file. If you just want the last run
# in the log fil, use date> logfile.
# It is always a good idea to get a time stamp in this kind of logs.
date >> logfile
# The read takes the input from servers.txt, which is done at the
# bottom using `done < servers.txt`.
# Some people like to do `cat servers.txt | while read -r hostname ; do`
# but they get negative comments on stackexchange :-)
while read -r hostname ; do
# Test if the host is up with a simple ping
# Throw away all output.
if ping -c1 "$hostname" > /dev/null 2>/dev/null; then
# We now test if a host is up with a simple command, echo.
# with -o PasswordAuthentication=no, we make sure that password
# authentication is not used. Output the result to the logfile.
if ssh -o PasswordAuthentication=no "$hostname" echo ' '; then
echo "OK - $hostname" >>logfile
else
echo "AArrrghhh $hostname" >> logfile
fi
else
# I assumed you want some idea of how many servers are skipped.
echo "skipped $hostname" >> logfile
fi
done < servers.txt
Это быстрая запись, и, вероятно, потребуется некоторая настройка. Комментарии должны дать вам несколько советов о том, что проверить.
Это прекрасно :-)Я внес в него некоторые изменения;-)
Конвертировать private.ppk в private.pem:
$ apt install putty-tools
$ puttygen private.ppk -O private-openssh -o private.pem
$ eval `ssh-agent -s`
$ ssh-add priv_key.pem
И скрипт будет работать идеально
вывод.лог
root@Pi-3Plus:~# cat output.log
Sat 20 Jul 20:37:51 EEST 2019
SSH-Key Refused - 192.168.1.106
No route to 192.168.4.34
SSH-Key Accepted - 192.168.1.2
No route to 192.168.4.33
SSH-Key Refused - 192.168.1.101
SSH-Key Refused - 192.168.1.195
No route to 192.168.4.39
SSH-Key Accepted - 192.168.1.2
Добавление модификаций кода ниже.
#!/bin/bash
# I assume "logfile" is the log file. If you just want the last run
# in the log fill, use date> logfile.
# It is always a good idea to get a time stamp in this kind of logs.
date >> output.log
# The read takes the input from servers.txt, which is done at the
# bottom using `done < servers.txt`.
# Some people like to do `cat servers.txt | while read -r hostname ; do`
# but they get negative comments on stackexchange :-)
while read -r hostname ; do
# Test if the host is up with a simple ping
# Throw away all output.
if ping -c1 "$hostname" > /dev/null 2>/dev/null; then
# We now test if a host is up with a simple command, echo.
# with -o PasswordAuthentication=no, we make sure that password
# authentication is not used. Output the result to the logfile.
if ssh -l ADDUSERHERE -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o PasswordAuthentication=no -n "$hostname" echo ''; then
echo "SSH-Key Accepted - $hostname" >>output.log
else
echo "SSH-Key Refused - $hostname" >> output.log
fi
else
# I assumed you want some idea of how many servers are skipped.
echo "No route to $hostname" >> output.log
fi
done < servers.txt