Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@types/ssh2
Advanced tools
@types/ssh2 provides TypeScript definitions for the ssh2 library, which is a client and server implementation of the SSH2 protocol. This package allows developers to use the ssh2 library with TypeScript, providing type safety and autocompletion features.
Establishing an SSH Connection
This code sample demonstrates how to establish an SSH connection to a remote server and execute a command ('uptime') on that server. The connection is established using the ssh2 library, and the TypeScript definitions provided by @types/ssh2 ensure type safety.
const Client = require('ssh2').Client;
const conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.exec('uptime', (err, stream) => {
if (err) throw err;
stream.on('close', (code, signal) => {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', (data) => {
console.log('STDOUT: ' + data);
}).stderr.on('data', (data) => {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '127.0.0.1',
port: 22,
username: 'frylock',
privateKey: require('fs').readFileSync('/here/is/my/key')
});
Setting up an SSH Server
This code sample demonstrates how to set up an SSH server that listens for incoming connections. The server authenticates clients using a username and password, and allows them to execute commands. The TypeScript definitions provided by @types/ssh2 ensure type safety for the ssh2 library's server functionality.
const { Server } = require('ssh2');
const fs = require('fs');
const server = new Server({
hostKeys: [fs.readFileSync('host.key')]
}, (client) => {
console.log('Client connected!');
client.on('authentication', (ctx) => {
if (ctx.method === 'password' && ctx.username === 'foo' && ctx.password === 'bar')
ctx.accept();
else
ctx.reject();
}).on('ready', () => {
console.log('Client authenticated!');
client.on('session', (accept, reject) => {
const session = accept();
session.on('exec', (accept, reject, info) => {
console.log('Client wants to execute: ' + info.command);
const stream = accept();
stream.stderr.write('Oh no, the dreaded errors!
');
stream.write('Just kidding about the errors!
');
stream.exit(0);
stream.end();
});
});
}).on('end', () => {
console.log('Client disconnected');
});
}).listen(22, '127.0.0.1', () => {
console.log('Listening on port 22');
});
node-ssh is a simpler, higher-level library for SSH connections in Node.js. It provides a more user-friendly API compared to ssh2, but may lack some of the advanced features and flexibility of ssh2.
ssh2-promise is a wrapper around ssh2 that provides a promise-based API. This can make it easier to work with asynchronous operations compared to the callback-based API of ssh2.
simple-ssh is another high-level library for SSH connections in Node.js. It focuses on simplicity and ease of use, but may not offer the same level of control and customization as ssh2.
npm install --save @types/ssh2
This package contains type definitions for ssh2 (https://github.com/mscdex/ssh2).
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/ssh2
Additional Details
These definitions were written by Qubo https://github.com/tkQubo.
FAQs
TypeScript definitions for ssh2
The npm package @types/ssh2 receives a total of 1,271,917 weekly downloads. As such, @types/ssh2 popularity was classified as popular.
We found that @types/ssh2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.