Skip to content
Advertisement

How to find if remote host is reachable over SSH without actually doing ssh

I have multiple remote hosts connected to my local host (server-A). TO ensure/filter the list of hosts which are genuinely reachable to localhost , I do ping test.

JavaScript

However ping test could not provide me any check to ensure that filtered remotehost-IPs are reachable over SSH connection /port 22.

JavaScript

Query:

Above check work for me if connection is refused. However, if SSH connection is possible then I enter into the remote host or proceed to password prompt. Which cause barrier to check return code.

So I wanted to know if there is any way to check if the remote IP WOULD be reachable or not reachable over SSH beforehand. ?

Advertisement

Answer

A Bash-Specific Solution

If you are using the Bash shell specifically, then you have access to TCP and UDP sockets. For example:

JavaScript

This won’t tell you if the actual protocol in use is really SSH, but is often sufficient to determine that a given port is listening. Your mileage may vary.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement