ssh -q -o "BatchMode=yes" user@host "echo 2>&1" && echo "OK" || echo "NOK"
this method is suitable but it returns true when the pub.key is copied to host.
I need to see if an ssh is connectiable between two devices without keys.
Simply wants to check if the sshd is running remotely.
If you just want to check if you can connect to a host via ssh, you could simply check if port 22 is open. There are various ways to to this.
Using nmap (replace localhost with your target host):
To use this in a script:
You can also use netcat:
To use this in a script:
This is a quick check which is sufficient in most situations, however it is not fool-proof. There is no guarantee that the service listening on the remote port is actually an SSH server.
You could attempt a dummy connection and inspect the returned header, e.g:
however such an approach is undesirable for various reasons. The only guaranteed way would be to establish an actual connection as you’ve shown in your question.