{"library":"ssh2","title":"SSH2 Client and Server for Node.js","type":"library","description":"ssh2 is a pure JavaScript implementation of an SSH2 client and server for Node.js, enabling secure remote command execution, file transfers (SFTP), and interactive shell sessions. The current stable version is 1.17.0, with development actively maintained against recent OpenSSH versions (e.g., OpenSSH 8.7). This library is distinguished by its comprehensive support for both client and server roles, offering an extensive API for various channel types (exec, shell, direct-tcpip, X11, subsystems) and pluggable authentication methods, including password and public key. It provides fine-grained control over SSH connections, making it suitable for building custom SSH tooling, automating deployments, or implementing secure backend services. While it does not adhere to a strict release cadence, updates are released as features are added or bugs are fixed, ensuring ongoing compatibility and security.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install ssh2"],"cli":null},"imports":["import { Client } from 'ssh2';","import { Server } from 'ssh2';","import * as utils from 'ssh2/lib/utils';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/mscdex/ssh2","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/ssh2","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const { readFileSync } = require('fs');\nconst { Client } = require('ssh2');\n\nconst conn = new Client();\nconn.on('ready', () => {\n  console.log('Client :: ready');\n  conn.exec('uptime', (err, stream) => {\n    if (err) throw err;\n    stream.on('close', (code, signal) => {\n      console.log(`Stream :: close :: code: ${code}, signal: ${signal}`);\n      conn.end();\n    }).on('data', (data) => {\n      console.log('STDOUT: ' + data);\n    }).stderr.on('data', (data) => {\n      console.error('STDERR: ' + data);\n    });\n  });\n}).on('error', (err) => {\n  console.error('Client Error:', err.message);\n}).connect({\n  host: process.env.SSH_HOST ?? '127.0.0.1',\n  port: parseInt(process.env.SSH_PORT ?? '22', 10),\n  username: process.env.SSH_USERNAME ?? 'user',\n  privateKey: readFileSync(process.env.SSH_PRIVATE_KEY_PATH ?? './id_rsa')\n});","lang":"javascript","description":"This example demonstrates how to establish an SSH client connection to a server and execute a remote command ('uptime'), logging its standard output and error.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}