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
- Host: GitHub
- URL: https://github.com/ottomatica/waitssh
- Owner: ottomatica
- License: apache-2.0
- Created: 2020-01-31T15:03:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-27T20:05:58.000Z (over 4 years ago)
- Last Synced: 2025-01-23T01:11:18.495Z (over 1 year ago)
- Topics: ssh
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
}
```