Sandra
Sandra

Reputation: 103

How to check if remote machine has SSH

What would be the best way to do this:

I want to send files to different remote machines with pscp (from local Windows machine) or sshpass(from local Unix machine) to random remote machines.

I check with a Java method first if the local machine has pscp or sshpass.
Then I want to check if the remote machine has SSH available.

What would be the best way to do the latter?

I've thought about using JSch for that, but does that not already require the existence of SSH on the remote machine?

Is this a good way in general?

Upvotes: 1

Views: 1138

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202292

The only way to test SSH existence remotely is to actually try to connect.

More technically speaking, to test if a remote SSH port 22 is open. In Java, it is as simple as to check that the following statement does not throw:

new Socket(address, 22).close();

You can go even a step further and read from the socket to check that your get an SSH identification string like "SSH-2.0-OpenSSH_5.3".


Trying to connect with JSch would do too. You just have to make sure you can distinguish "cannot connect" errors from any other errors like "cannot authenticate" (which indicate that SSH is there).

Upvotes: 1

Related Questions