New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ssh2-connect

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2-connect - npm Package Compare versions

Comparing version 3.5.0 to 4.0.0

.prettierrc.yml

65

CHANGELOG.md

@@ -5,9 +5,22 @@ # Changelog

## [3.5.0](https://github.com/adaltas/node-ssh2-connect/compare/v3.4.3...v3.5.0) (2024-09-02)
## [4.0.0](https://github.com/adaltas/node-ssh2-connect/compare/v3.5.0...v4.0.0) (2024-09-09)
### ⚠ BREAKING CHANGES
- remove default export
- typescript convertion
### Features
* TS type definitions ([#4](https://github.com/adaltas/node-ssh2-connect/issues/4)) ([7797eea](https://github.com/adaltas/node-ssh2-connect/commit/7797eead6976e5fb56ee0fbcd0ae1b5251064e99))
- esm convertion ([81fafc9](https://github.com/adaltas/node-ssh2-connect/commit/81fafc920c60b424bcdae12c16a0ab6697b780ff))
- typescript convertion ([02ac456](https://github.com/adaltas/node-ssh2-connect/commit/02ac4566dcc3096a7a9ac27a7e81b0548cd6663c))
- remove default export ([ba369c8](https://github.com/adaltas/node-ssh2-connect/commit/ba369c85ac2f7dca5a20e20fdfb54e84d6c3db14))
## [3.5.0](https://github.com/adaltas/node-ssh2-connect/compare/v3.4.3...v3.5.0) (2024-09-02)
### Features
- TS type definitions ([#4](https://github.com/adaltas/node-ssh2-connect/issues/4)) ([7797eea](https://github.com/adaltas/node-ssh2-connect/commit/7797eead6976e5fb56ee0fbcd0ae1b5251064e99))
### [3.4.3](https://github.com/adaltas/node-ssh2-connect/compare/v3.4.2...v3.4.3) (2024-06-12)

@@ -21,20 +34,17 @@

### Features
* closed and opened functions ([5823068](https://github.com/adaltas/node-ssh2-connect/commit/5823068ed32f5710c916eb63c733e433778558be))
- closed and opened functions ([5823068](https://github.com/adaltas/node-ssh2-connect/commit/5823068ed32f5710c916eb63c733e433778558be))
### [3.3.1](https://github.com/adaltas/node-ssh2-connect/compare/v3.3.0...v3.3.1) (2022-03-12)
### Bug Fixes
* build coffee ([6ec05f3](https://github.com/adaltas/node-ssh2-connect/commit/6ec05f34953f4d0c7ce4bf21b2004a9a8ee954ec))
- build coffee ([6ec05f3](https://github.com/adaltas/node-ssh2-connect/commit/6ec05f34953f4d0c7ce4bf21b2004a9a8ee954ec))
## [3.3.0](https://github.com/adaltas/node-ssh2-connect/compare/v3.2.3...v3.3.0) (2022-03-12)
### Features
* export is function ([df7e608](https://github.com/adaltas/node-ssh2-connect/commit/df7e608882a4ab48df38ec5cc619ffd66b91a43e))
- export is function ([df7e608](https://github.com/adaltas/node-ssh2-connect/commit/df7e608882a4ab48df38ec5cc619ffd66b91a43e))

@@ -49,13 +59,10 @@ ### [3.2.3](https://github.com/adaltas/node-ssh2-connect/compare/v3.2.2...v3.2.3) (2022-03-12)

### Features
* support ed25519 and rsa discovery ([5b0791f](https://github.com/adaltas/node-ssh2-connect/commit/5b0791f1badd173344e1ad4196e0f3d58ce11f57))
- support ed25519 and rsa discovery ([5b0791f](https://github.com/adaltas/node-ssh2-connect/commit/5b0791f1badd173344e1ad4196e0f3d58ce11f57))
## Version 3.1.0
* test: latest mocha
* feat: re-activate optional callback API
- test: latest mocha
- feat: re-activate optional callback API

@@ -65,35 +72,37 @@ ## Version 3.0.0

Breaking changes:
* src: promise based API
- src: promise based API
Project Management
* package: ignore lock files
* package: latest dependencies
* doc: new connect.js sample
* wait: new option, default to 2000
* package: update author url
* license: use MIT
- package: ignore lock files
- package: latest dependencies
- doc: new connect.js sample
- wait: new option, default to 2000
- package: update author url
- license: use MIT
## Version 2.0.5
* package: upgrade dependencies
- package: upgrade dependencies
## Version 2.0.4
* readme: add author company
- readme: add author company
## Version 2.0.3
* readme: convert usage example to js
- readme: convert usage example to js
## Version 2.0.2
* dependency: update to ssh 0.6.0
- dependency: update to ssh 0.6.0
## Version 2.0.1
* package: release commands
- package: release commands
## Version 2.0.0
* travis: test against node 7 and 8
* package: upgrade to CoffeeScript 2
- travis: test against node 7 and 8
- package: upgrade to CoffeeScript 2

@@ -1,5 +0,3 @@

module.exports = {
extends: [
"@commitlint/config-conventional"
]
export default {
extends: ["@commitlint/config-conventional"],
};
{
"name": "ssh2-connect",
"description": "Callback-based api behind ssh2 to open an SSH connection",
"version": "3.5.0",
"version": "4.0.0",
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)",
"coffeelintConfig": {
"indentation": {
"level": "error",
"value": 2
},
"line_endings": {
"level": "error",
"value": "unix"
},
"max_line_length": {
"level": "ignore"
},
"no_backticks": {
"level": "ignore"
},
"no_nested_string_interpolation": {
"level": "ignore"
}
},
"contributors": [],

@@ -34,7 +15,19 @@ "dependencies": {

"@commitlint/cz-commitlint": "^19.4.0",
"coffeescript": "^2.7.0",
"@eslint/js": "^9.10.0",
"@types/mocha": "^10.0.7",
"@types/ssh2": "^1.15.1",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.5",
"lint-staged": "^15.2.10",
"mocha": "~10.7.3",
"prettier": "^3.3.3",
"rollup": "^4.21.2",
"should": "~13.2.3",
"standard-version": "^9.5.0"
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"tsx": "^4.19.0",
"typescript": "^5.5.4"
},

@@ -44,2 +37,9 @@ "engines": {

},
"exports": {
".": {
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.cjs"
}
},
"homepage": "https://github.com/adaltas/node-ssh2-connect",

@@ -57,15 +57,18 @@ "keywords": [

"license": "MIT",
"main": "./lib/index",
"lint-staged": {
"*.js": "npm run lint:fix",
"*.md": "prettier -w"
},
"main": "./lib/index.js",
"mocha": {
"throw-deprecation": true,
"inline-diffs": true,
"loader": "ts-node/esm",
"recursive": true,
"reporter": "spec",
"require": [
"should",
"coffeescript/register"
"should"
],
"inline-diffs": true,
"timeout": 40000,
"reporter": "spec",
"recursive": true
"throw-deprecation": false,
"timeout": 40000
},
"optionalDependencies": {},
"repository": {

@@ -76,2 +79,6 @@ "type": "git",

"scripts": {
"build": "tsc --project tsconfig.src.json && rollup -c",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:staged": "npx lint-staged",
"prepare": "husky install",

@@ -83,5 +90,6 @@ "release": "standard-version",

"postrelease": "git push --follow-tags origin master",
"test": "mocha 'test/**/*.coffee'"
"test": "mocha 'test/**/*.ts'"
},
"types": "types/index.d.ts"
"type": "module",
"types": "./dist/types/index.d.ts"
}

@@ -1,78 +0,117 @@

[![Build Status](https://secure.travis-ci.org/adaltas/node-ssh2-connect.png)][travis]
# Node.js ssh2-connect
The Node.js ssh2-connect package extends the [`ssh2`][ssh2] module to provide a simplified callback-back approach to initiate a new SSH connection.
[![Build Status](https://img.shields.io/github/actions/workflow/status/adaltas/node-ssh2-connect/test.yml?branch=master)](https://github.com/adaltas/node-ssh2-connect/actions)
[![NPM](https://img.shields.io/npm/dm/ssh2-connect)](https://www.npmjs.com/package/ssh2-connect)
[![NPM](https://img.shields.io/npm/v/ssh2-connect)](https://www.npmjs.com/package/ssh2-connect)
## Usage
The Node.js ssh2-connect package extends the [`ssh2`](https://www.npmjs.com/package/ssh2) module to provide a simplified callback-back approach to initiate a new SSH connection.
The `connect` function return a promise. Its signature is `await connect(options)`
## Installation
It also accept an optional callback function. In such case, its signature is `connect(options, callback)`.
The project is OSS and licensed under the [MIT license](https://github.com/adaltas/node-ssh2-connect/blob/master/LICENSE.md).
This package simplifies the creation of an SSH connection. For example, the original ssh2 code...
```bash
npm install ssh2-connect
```
## Usage
The `ssh2-connect` module exposes 4 functions.
```js
const ssh2 = require('ssh2')
const connection = new ssh2()
connection.on('error', function(err){
// Handle the connection error
connection.end()
})
connection.on('ready', function(){
// Work with the connection
connection.end()
})
connection.connect({
host: 'localhost',
user: 'milou',
password: 'wafwaf'
})
// With ESM
import { connect, is, closed, opened } from "ssh2-connect";
// Or with CommonJS
const { connect, is, closed, opened } = require("ssh2-connect");
```
...is simplified to:
Use `connect` to establishes the SSH connection
```js
const connect = require('ssh2-connect')
(async () => {
try{
const ssh = await connect({
host: 'localhost',
username: 'david',
private_key_path: '~/.ssh/id_rsa'
})
// Work with the connection
ssh.end()
}catch (err){
// Handle the connection error
}
})()
// Establishes the SSH connection
const client = await connect({
host: "example.com",
username: "user",
privateKeyPath: "~/.ssh/id_ed25519",
});
```
## Options
### `await connect(options: ConnectConfig): PromiseLike<Client>`
Options are inherited from the [ssh2 `Connection.prototype.connect`][ssh2-connect] function with a few additions:
The `connect` function return a promise.
- `username`
The username used to initiate the connection, default to the current
environment user.
- `privateKeyPath`
Path of the file containing the private key, `true` to enable auto-discovery or `false` to disable auto-discovery, default to `true`.
- `retry`
Attempt to reconnect multiple times, default to `1`.
- `wait`
Time to wait in milliseconds between each retry, default to `2000`.
Options are inherited from the [ssh2 `connect` method](https://www.npmjs.com/package/ssh2#client-methods) 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]) or underscore form. For example, both "privateKey" and "private_key" would be interprated the same.
Additionally, all options may be provided in camalize (the default in [ssh2](https://www.npmjs.com/package/ssh2)) and snake cases. For example, both "privateKey" and "private_key" would be interprated the same.
## Installation
### `is(conn: unknown): boolean`
This is OSS and licensed under the [new BSD license][license].
Checks if the provided argument `conn` is an instance of the `Client` connection class from the ssh2 package.
```bash
npm install ssh2-connect
- `conn` - The object to check, probably an SSH client connection.
### `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.
## Purpose
This package simplifies the creation and the usage of an SSH connection. For example, the original [ssh2](https://www.npmjs.com/package/ssh2) code...
```js
import ssh2 from "ssh2";
const connection = new ssh2();
connection.on("error", function (err) {
// Handle the connection error
connection.end();
});
connection.on("ready", function () {
// Work with the connection
connection.end();
});
connection.connect({
host: "localhost",
user: "milou",
password: "wafwaf",
});
```
Is simplified to:
```js
import { connect } from "ssh2-connect";
try {
const ssh = await connect({
host: "localhost",
username: "milou",
private_key_path: "~/.ssh/id_ed25519",
});
// Work with the connection, then close it
} catch (err) {
// Handle the connection error
} finally {
// Close the connection
ssh.end();
}
```
## Examples

@@ -83,8 +122,8 @@

```js
const connect = require('ssh2-connect');
const fs = require('ssh2-fs');
const connect = require("ssh2-connect");
const fs = require("ssh2-fs");
// Open the connection
connect({host: 'localhost'}, function(err, ssh){
connect({host: "localhost"}, function(err, ssh){
// Create a directory
fs.mkdir(ssh, '/tmp/a_dir', (err, stdout, stderr){
fs.mkdir(ssh, "/tmp/a_dir", (err, stdout, stderr){
console.log(stdout);

@@ -98,14 +137,14 @@ });

```js
ssh2 = require('ssh2');
fs = require('ssh2-fs');
ssh2 = require("ssh2");
fs = require("ssh2-fs");
connection = new ssh2();
connection.on('error', function(err){
connection.on("error", function(err){
connection.end()
});
connection.on('ready', function(){
fs.mkdir(connection, '/tmp/a_dir', (err, stdout, stderr){
connection.on("ready", function(){
fs.mkdir(connection, "/tmp/a_dir", (err, stdout, stderr){
console.log(stdout);
});
});
connection.connect({host: 'localhost'});
connection.connect({host: "localhost"});
```

@@ -115,11 +154,10 @@

Tests are executed with mocha. To install it, simple run `npm install`, it will install mocha and its dependencies in your project "node_modules" directory.
Tests are executed with mocha. To install it, run `npm install`, it will install mocha and its dependencies in your project "node_modules" directory.
To run the tests:
```bash
npm install
npm test
```
To generate the JavaScript files:
Source code is written in Typescription. The build command generates the JavaScript files.

@@ -130,3 +168,3 @@ ```bash

The test suite is run online with GitHub action against several Node.js version.
The test suite is run online with [GitHub actions](https://github.com/adaltas/node-ssh2-connect/actions) against several Node.js version.

@@ -139,4 +177,5 @@ ## Release

npm run release
# Or
# Or (`git push` is only supported for the release script)
npm run release:<major|minor|patch>
git push --follow-tags origin master
```

@@ -148,9 +187,4 @@

* David Worms: <https://github.com/wdavidw>
- David Worms: <https://github.com/wdavidw>
This package is developed by [Adaltas](https://www.adaltas.com).
[travis]: http://travis-ci.org/adaltas/node-ssh2-connect
[ssh2]: https://github.com/mscdex/ssh2
[ssh2-connect]: https://github.com/adaltas/node-ssh2-connect
[license]: https://github.com/adaltas/node-ssh2-connect/blob/master/LICENSE.md

@@ -0,18 +1,18 @@

#!/usr/bin/env node
const connect = require('..');
import connect from "ssh2-connect";
(async () => {
const ssh = await connect({
host: 'localhost',
username: process.env['USER'],
private_key_path: process.env['HOME']+'/.ssh/id_rsa'
})
ssh.exec('whoami', (err, stream) => {
stream.on('data', (data) => {
process.stdout.write(data.toString())
})
stream.on('close', () => {
ssh.end()
})
})
})()
await connect({
host: "localhost",
username: process.env["USER"],
private_key_path: process.env["HOME"] + "/.ssh/id_rsa",
}).then((ssh) => {
ssh.exec("whoami", (err, stream) => {
stream.on("data", (data) => {
process.stdout.write(data.toString());
});
stream.on("close", () => {
ssh.end();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc