An open API service indexing awesome lists of open source software.

https://github.com/ottomatica/waitssh

⏱ Cross-platform utility to wait for ssh to become available
https://github.com/ottomatica/waitssh

ssh

Last synced: over 1 year ago
JSON representation

⏱ Cross-platform utility to wait for ssh to become available

Awesome Lists containing this project

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](https://www.npmjs.com/package/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](https://tools.ietf.org/html/rfc4253#section-4.2). 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.

```js
const waitssh = require('waitssh');
let sshInfo = {port: 2002, hostname: 'localhost'}
try {
await waitssh(sshInfo);
} catch (error) {
console.error(error);
process.exit(1);
}
```