waitssh
v1.0.5
Published
Cross-platform utility that waits for ssh to become available
Readme
waitssh
waitssh is a cross-platform utility that waits for ssh to become available.
One common use case is for waiting for Virtual Machines to boot and waiting for sshd to be ready. Other tools, such as wait-on are agnostic to the network setup and will fail in cases such as port-forwarding.
Implementation
How does it work? waitssh implements the first phase of the SSH protocol specification, described in RFC 4253. Immediately after the TCP connection is established, and before negotiating the cryptography, both ends send an identification string:
SSH-protoversion-softwareversion SP comments CR LF
waitssh open a socket, attempts to write send a client version string to the ssh sever. waitssh gracefully handles ECONNRESET errors and reconnects as needed until the server responses with the appropriate version string.
Using waitssh
waitssh does not need authentication information to verify the ssh connection being ready, only the hostname and port.
const waitssh = require('waitssh');
let sshInfo = {port: 2002, hostname: 'localhost'}
try {
await waitssh(sshInfo);
} catch (error) {
console.error(error);
process.exit(1);
}