Gathering detailed insights and metrics for ssh2-connect
Gathering detailed insights and metrics for ssh2-connect
Gathering detailed insights and metrics for ssh2-connect
Gathering detailed insights and metrics for ssh2-connect
ssh2-connect-mysql
ssh2 connection mysql
automa-watch-ssh2
Connect on ssh
ssh2-keeper
To store your SSH2 servers connection information allowing to connect to them quickly
ssh-connect-prompt
Connect to ssh using the ssh2 module and prompt stdin for host verification, key decryption etc. Similar to what standard ssh does.
npm install ssh2-connect
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (96.45%)
JavaScript (3.55%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
149 Commits
1 Forks
2 Watchers
1 Branches
2 Contributors
Updated on Nov 26, 2024
Latest Version
4.2.0
Package Id
ssh2-connect@4.2.0
Unpacked Size
42.05 kB
Size
8.83 kB
File Count
9
NPM Version
10.8.2
Node Version
20.18.1
Published on
Nov 26, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
The Node.js ssh2-connect package extends the ssh2
module to provide a simplified callback-back approach to initiate a new SSH connection.
The project is OSS and licensed under the MIT license.
1npm install ssh2-connect
The ssh2-connect
module exposes 4 functions.
1// With ESM 2import { connect, is, closed, opened } from "ssh2-connect"; 3// Or with CommonJS 4const { connect, is, closed, opened } = require("ssh2-connect");
Use connect
to establishes the SSH connection
1// Establishes the SSH connection 2const client = await connect({ 3 host: "example.com", 4 username: "user", 5 privateKeyPath: "~/.ssh/id_ed25519", 6});
await connect(options: ConnectConfig): PromiseLike<Client>
The connect
function return a promise.
Options are inherited from the ssh2 connect
method with a few additions.
options
- The configuration options for the SSH connection.options.username
- The username for authentication. Defaults to the current user if not provided.options.retry
- The number of connection retry attempts. Set to 0
or false
to disable retries, default is 1
.options.wait
- The wait time in milliseconds between each attempts, default to 500
.options.privateKey
- The private key as a string or Buffer for authentication.options.privateKeyPath
- The path to the private key file, or true for auto-discovery in ~/.ssh.options.password
- The password for authentication.options.[key: string]
- Any other valid SSH2 connection options.Note, the "privateKeyPath" option is provided as a conveniency to read the private key and fill the "privateKey" property.
Additionally, all options may be provided in camalize (the default in ssh2) and snake cases. For example, both "privateKey" and "private_key" would be interprated the same.
is(conn: unknown): boolean
Checks if the provided argument conn
is an instance of the Client
connection class from the ssh2 package.
conn
- The object to check, probably an SSH client connection.close(conn: Client): PromiseLike<boolean>
Close the the SSH client connection. It resolves to true
if the connection was opened and closed. Otherwise it resolves to false
.
conn
- The SSH client connection to close.closed(conn: Client): boolean
Checks if the provided SSH client connection is closed.
conn
- The SSH client connection to check.opened(conn: Client): boolean
Checks if the provided SSH client connection is open and writable.
conn
- The SSH client connection to check.This package simplifies the creation and the usage of an SSH connection. For example, the original ssh2 code...
1import ssh2 from "ssh2"; 2const connection = new ssh2(); 3connection.on("error", function (err) { 4 // Handle the connection error 5 connection.end(); 6}); 7connection.on("ready", function () { 8 // Work with the connection 9 connection.end(); 10}); 11connection.connect({ 12 host: "localhost", 13 user: "milou", 14 password: "wafwaf", 15});
Is simplified to:
1import { connect } from "ssh2-connect"; 2try { 3 const ssh = await connect({ 4 host: "localhost", 5 username: "milou", 6 private_key_path: "~/.ssh/id_ed25519", 7 }); 8 // Work with the connection, then close it 9} catch (err) { 10 // Handle the connection error 11} finally { 12 // Close the connection 13 ssh.end(); 14}
The example is using both the "ssh2-connect" and "ssh2-fs" modules.
1const connect = require("ssh2-connect"); 2const fs = require("ssh2-fs"); 3// Open the connection 4connect({host: "localhost"}, function(err, ssh){ 5 // Create a directory 6 fs.mkdir(ssh, "/tmp/a_dir", (err, stdout, stderr){ 7 console.log(stdout); 8 }); 9});
Compare this to the more verbose alternative using the original ssh2 module.
1ssh2 = require("ssh2"); 2fs = require("ssh2-fs"); 3connection = new ssh2(); 4connection.on("error", function(err){ 5 connection.end() 6}); 7connection.on("ready", function(){ 8 fs.mkdir(connection, "/tmp/a_dir", (err, stdout, stderr){ 9 console.log(stdout); 10 }); 11}); 12connection.connect({host: "localhost"});
Tests are executed with mocha. To install it, run npm install
, it will install mocha and its dependencies in your project "node_modules" directory.
1npm install 2npm test
Source code is written in Typescription. The build command generates the JavaScript files.
1npm run build
The test suite is run online with GitHub actions against several Node.js version.
Versions are incremented using semantic versioning. To create a new version and publish it to NPM, run:
1npm run release 2# Or (`git push` is only supported for the release script) 3npm run release:<major|minor|patch> 4git push --follow-tags origin master
The NPM publication is handled with the GitHub action.
The project is sponsored by Adaltas based in Paris, France. Adaltas offers support and consulting on distributed systems, big data and open source.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More