UNPKG

54.2 kBMarkdownView Raw
1# Description
2
3SSH2 client and server modules written in pure JavaScript for [node.js](http://nodejs.org/).
4
5Development/testing is done against OpenSSH (7.1 currently).
6
7[![Build Status](https://travis-ci.org/mscdex/ssh2.svg?branch=master)](https://travis-ci.org/mscdex/ssh2)
8
9# Table of Contents
10
11* [Requirements](#requirements)
12* [Installation](#installation)
13* [Client Examples](#client-examples)
14 * [Execute `uptime` on a server](#execute-uptime-on-a-server)
15 * [Start an interactive shell session](#start-an-interactive-shell-session)
16 * [Send a raw HTTP request to port 80 on the server](#send-a-raw-http-request-to-port-80-on-the-server)
17 * [Forward local connections to port 8000 on the server to us](#forward-local-connections-to-port-8000-on-the-server-to-us)
18 * [Get a directory listing via SFTP](#get-a-directory-listing-via-sftp)
19 * [Connection hopping](#connection-hopping)
20 * [Forward remote X11 connections](#forward-remote-x11-connections)
21 * [Dynamic (1:1) port forwarding using a SOCKSv5 proxy (using `socksv5`)](#dynamic-11-port-forwarding-using-a-socksv5-proxy-using-socksv5)
22 * [Invoke an arbitrary subsystem (e.g. netconf)](#invoke-an-arbitrary-subsystem)
23* [Server Examples](#server-examples)
24 * [Password and public key authentication and non-interactive (exec) command execution](#password-and-public-key-authentication-and-non-interactive-exec-command-execution)
25 * [SFTP-only server](#sftp-only-server)
26* [API](#api)
27 * [Client](#client)
28 * [Client events](#client-events)
29 * [Client methods](#client-methods)
30 * [Server](#server)
31 * [Server events](#server-events)
32 * [Server methods](#server-methods)
33 * [Connection events](#connection-events)
34 * [Connection methods](#connection-methods)
35 * [Session events](#session-events)
36 * [Channel](#channel)
37 * [Pseudo-TTY settings](#pseudo-tty-settings)
38 * [Terminal modes](#terminal-modes)
39
40## Requirements
41
42* [node.js](http://nodejs.org/) -- v5.2.0 or newer
43
44## Installation
45
46 npm install ssh2
47
48## Client Examples
49
50### Execute `uptime` on a server
51
52```js
53var Client = require('ssh2').Client;
54
55var conn = new Client();
56conn.on('ready', function() {
57 console.log('Client :: ready');
58 conn.exec('uptime', function(err, stream) {
59 if (err) throw err;
60 stream.on('close', function(code, signal) {
61 console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
62 conn.end();
63 }).on('data', function(data) {
64 console.log('STDOUT: ' + data);
65 }).stderr.on('data', function(data) {
66 console.log('STDERR: ' + data);
67 });
68 });
69}).connect({
70 host: '192.168.100.100',
71 port: 22,
72 username: 'frylock',
73 privateKey: require('fs').readFileSync('/here/is/my/key')
74});
75
76// example output:
77// Client :: ready
78// STDOUT: 17:41:15 up 22 days, 18:09, 1 user, load average: 0.00, 0.01, 0.05
79//
80// Stream :: exit :: code: 0, signal: undefined
81// Stream :: close
82```
83
84### Start an interactive shell session
85
86```js
87var Client = require('ssh2').Client;
88
89var conn = new Client();
90conn.on('ready', function() {
91 console.log('Client :: ready');
92 conn.shell(function(err, stream) {
93 if (err) throw err;
94 stream.on('close', function() {
95 console.log('Stream :: close');
96 conn.end();
97 }).on('data', function(data) {
98 console.log('STDOUT: ' + data);
99 }).stderr.on('data', function(data) {
100 console.log('STDERR: ' + data);
101 });
102 stream.end('ls -l\nexit\n');
103 });
104}).connect({
105 host: '192.168.100.100',
106 port: 22,
107 username: 'frylock',
108 privateKey: require('fs').readFileSync('/here/is/my/key')
109});
110
111// example output:
112// Client :: ready
113// STDOUT: Last login: Sun Jun 15 09:37:21 2014 from 192.168.100.100
114//
115// STDOUT: ls -l
116// exit
117//
118// STDOUT: frylock@athf:~$ ls -l
119//
120// STDOUT: total 8
121//
122// STDOUT: drwxr-xr-x 2 frylock frylock 4096 Nov 18 2012 mydir
123//
124// STDOUT: -rw-r--r-- 1 frylock frylock 25 Apr 11 2013 test.txt
125//
126// STDOUT: frylock@athf:~$ exit
127//
128// STDOUT: logout
129//
130// Stream :: close
131```
132
133### Send a raw HTTP request to port 80 on the server
134
135```js
136var Client = require('ssh2').Client;
137
138var conn = new Client();
139conn.on('ready', function() {
140 console.log('Client :: ready');
141 conn.forwardOut('192.168.100.102', 8000, '127.0.0.1', 80, function(err, stream) {
142 if (err) throw err;
143 stream.on('close', function() {
144 console.log('TCP :: CLOSED');
145 conn.end();
146 }).on('data', function(data) {
147 console.log('TCP :: DATA: ' + data);
148 }).end([
149 'HEAD / HTTP/1.1',
150 'User-Agent: curl/7.27.0',
151 'Host: 127.0.0.1',
152 'Accept: */*',
153 'Connection: close',
154 '',
155 ''
156 ].join('\r\n'));
157 });
158}).connect({
159 host: '192.168.100.100',
160 port: 22,
161 username: 'frylock',
162 password: 'nodejsrules'
163});
164
165// example output:
166// Client :: ready
167// TCP :: DATA: HTTP/1.1 200 OK
168// Date: Thu, 15 Nov 2012 13:52:58 GMT
169// Server: Apache/2.2.22 (Ubuntu)
170// X-Powered-By: PHP/5.4.6-1ubuntu1
171// Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
172// Content-Encoding: gzip
173// Vary: Accept-Encoding
174// Connection: close
175// Content-Type: text/html; charset=UTF-8
176//
177//
178// TCP :: CLOSED
179```
180
181### Forward local connections to port 8000 on the server to us
182
183```js
184var Client = require('ssh2').Client;
185
186var conn = new Client();
187conn.on('ready', function() {
188 console.log('Client :: ready');
189 conn.forwardIn('127.0.0.1', 8000, function(err) {
190 if (err) throw err;
191 console.log('Listening for connections on server on port 8000!');
192 });
193}).on('tcp connection', function(info, accept, reject) {
194 console.log('TCP :: INCOMING CONNECTION:');
195 console.dir(info);
196 accept().on('close', function() {
197 console.log('TCP :: CLOSED');
198 }).on('data', function(data) {
199 console.log('TCP :: DATA: ' + data);
200 }).end([
201 'HTTP/1.1 404 Not Found',
202 'Date: Thu, 15 Nov 2012 02:07:58 GMT',
203 'Server: ForwardedConnection',
204 'Content-Length: 0',
205 'Connection: close',
206 '',
207 ''
208 ].join('\r\n'));
209}).connect({
210 host: '192.168.100.100',
211 port: 22,
212 username: 'frylock',
213 password: 'nodejsrules'
214});
215
216// example output:
217// Client :: ready
218// Listening for connections on server on port 8000!
219// (.... then from another terminal on the server: `curl -I http://127.0.0.1:8000`)
220// TCP :: INCOMING CONNECTION: { destIP: '127.0.0.1',
221// destPort: 8000,
222// srcIP: '127.0.0.1',
223// srcPort: 41969 }
224// TCP DATA: HEAD / HTTP/1.1
225// User-Agent: curl/7.27.0
226// Host: 127.0.0.1:8000
227// Accept: */*
228//
229//
230// TCP :: CLOSED
231```
232
233### Get a directory listing via SFTP
234
235```js
236var Client = require('ssh2').Client;
237
238var conn = new Client();
239conn.on('ready', function() {
240 console.log('Client :: ready');
241 conn.sftp(function(err, sftp) {
242 if (err) throw err;
243 sftp.readdir('foo', function(err, list) {
244 if (err) throw err;
245 console.dir(list);
246 conn.end();
247 });
248 });
249}).connect({
250 host: '192.168.100.100',
251 port: 22,
252 username: 'frylock',
253 password: 'nodejsrules'
254});
255
256// example output:
257// Client :: ready
258// [ { filename: 'test.txt',
259// longname: '-rw-r--r-- 1 frylock frylock 12 Nov 18 11:05 test.txt',
260// attrs:
261// { size: 12,
262// uid: 1000,
263// gid: 1000,
264// mode: 33188,
265// atime: 1353254750,
266// mtime: 1353254744 } },
267// { filename: 'mydir',
268// longname: 'drwxr-xr-x 2 frylock frylock 4096 Nov 18 15:03 mydir',
269// attrs:
270// { size: 1048576,
271// uid: 1000,
272// gid: 1000,
273// mode: 16877,
274// atime: 1353269007,
275// mtime: 1353269007 } } ]
276```
277
278### Connection hopping
279
280```js
281var Client = require('ssh2').Client;
282
283var conn1 = new Client();
284var conn2 = new Client();
285
286conn1.on('ready', function() {
287 console.log('FIRST :: connection ready');
288 conn1.exec('nc 192.168.1.2 22', function(err, stream) {
289 if (err) {
290 console.log('FIRST :: exec error: ' + err);
291 return conn1.end();
292 }
293 conn2.connect({
294 sock: stream,
295 username: 'user2',
296 password: 'password2',
297 });
298 });
299}).connect({
300 host: '192.168.1.1',
301 username: 'user1',
302 password: 'password1',
303});
304
305conn2.on('ready', function() {
306 console.log('SECOND :: connection ready');
307 conn2.exec('uptime', function(err, stream) {
308 if (err) {
309 console.log('SECOND :: exec error: ' + err);
310 return conn1.end();
311 }
312 stream.on('end', function() {
313 conn1.end(); // close parent (and this) connection
314 }).on('data', function(data) {
315 console.log(data.toString());
316 });
317 });
318});
319```
320
321### Forward remote X11 connections
322
323```js
324var net = require('net');
325
326var Client = require('ssh2').Client;
327
328var conn = new Client();
329
330conn.on('x11', function(info, accept, reject) {
331 var xserversock = new net.Socket();
332 xserversock.on('connect', function() {
333 var xclientsock = accept();
334 xclientsock.pipe(xserversock).pipe(xclientsock);
335 });
336 // connects to localhost:0.0
337 xserversock.connect(6000, 'localhost');
338});
339
340conn.on('ready', function() {
341 conn.exec('xeyes', { x11: true }, function(err, stream) {
342 if (err) throw err;
343 var code = 0;
344 stream.on('end', function() {
345 if (code !== 0)
346 console.log('Do you have X11 forwarding enabled on your SSH server?');
347 conn.end();
348 }).on('exit', function(exitcode) {
349 code = exitcode;
350 });
351 });
352}).connect({
353 host: '192.168.1.1',
354 username: 'foo',
355 password: 'bar'
356});
357```
358
359### Dynamic (1:1) port forwarding using a SOCKSv5 proxy (using [socksv5](https://github.com/mscdex/socksv5))
360
361```js
362var socks = require('socksv5');
363var Client = require('ssh2').Client;
364
365var ssh_config = {
366 host: '192.168.100.1',
367 port: 22,
368 username: 'nodejs',
369 password: 'rules'
370};
371
372socks.createServer(function(info, accept, deny) {
373 // NOTE: you could just use one ssh2 client connection for all forwards, but
374 // you could run into server-imposed limits if you have too many forwards open
375 // at any given time
376 var conn = new Client();
377 conn.on('ready', function() {
378 conn.forwardOut(info.srcAddr,
379 info.srcPort,
380 info.dstAddr,
381 info.dstPort,
382 function(err, stream) {
383 if (err) {
384 conn.end();
385 return deny();
386 }
387
388 var clientSocket;
389 if (clientSocket = accept(true)) {
390 stream.pipe(clientSocket).pipe(stream).on('close', function() {
391 conn.end();
392 });
393 } else
394 conn.end();
395 });
396 }).on('error', function(err) {
397 deny();
398 }).connect(ssh_config);
399}).listen(1080, 'localhost', function() {
400 console.log('SOCKSv5 proxy server started on port 1080');
401}).useAuth(socks.auth.None());
402
403// test with cURL:
404// curl -i --socks5 localhost:1080 google.com
405```
406
407### Invoke an arbitrary subsystem
408
409```js
410var Client = require('ssh2').Client;
411var xmlhello = '<?xml version="1.0" encoding="UTF-8"?>' +
412 '<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">' +
413 ' <capabilities>' +
414 ' <capability>urn:ietf:params:netconf:base:1.0</capability>' +
415 ' </capabilities>' +
416 '</hello>]]>]]>';
417
418var conn = new Client();
419
420conn.on('ready', function() {
421 console.log('Client :: ready');
422 conn.subsys('netconf', function(err, stream) {
423 if (err) throw err;
424 stream.on('data', function(data) {
425 console.log(data);
426 }).write(xmlhello);
427 });
428}).connect({
429 host: '1.2.3.4',
430 port: 22,
431 username: 'blargh',
432 password: 'honk'
433});
434```
435
436## Server Examples
437
438### Password and public key authentication and non-interactive (exec) command execution
439
440```js
441var fs = require('fs');
442var crypto = require('crypto');
443var inspect = require('util').inspect;
444
445var ssh2 = require('ssh2');
446var utils = ssh2.utils;
447
448var allowedUser = Buffer.from('foo');
449var allowedPassword = Buffer.from('bar');
450var allowedPubKey = utils.parseKey(fs.readFileSync('foo.pub'));
451
452new ssh2.Server({
453 hostKeys: [fs.readFileSync('host.key')]
454}, function(client) {
455 console.log('Client connected!');
456
457 client.on('authentication', function(ctx) {
458 var user = Buffer.from(ctx.username);
459 if (user.length !== allowedUser.length
460 || !crypto.timingSafeEqual(user, allowedUser)) {
461 return ctx.reject();
462 }
463
464 switch (ctx.method) {
465 case 'password':
466 var password = Buffer.from(ctx.password);
467 if (password.length !== allowedPassword.length
468 || !crypto.timingSafeEqual(password, allowedPassword)) {
469 return ctx.reject();
470 }
471 break;
472 case 'publickey':
473 var allowedPubSSHKey = allowedPubKey.getPublicSSH();
474 if (ctx.key.algo !== allowedPubKey.type
475 || ctx.key.data.length !== allowedPubSSHKey.length
476 || !crypto.timingSafeEqual(ctx.key.data, allowedPubSSHKey)
477 || (ctx.signature && !allowedPubKey.verify(ctx.blob, ctx.signature))) {
478 return ctx.reject();
479 }
480 break;
481 default:
482 return ctx.reject();
483 }
484
485 ctx.accept();
486 }).on('ready', function() {
487 console.log('Client authenticated!');
488
489 client.on('session', function(accept, reject) {
490 var session = accept();
491 session.once('exec', function(accept, reject, info) {
492 console.log('Client wants to execute: ' + inspect(info.command));
493 var stream = accept();
494 stream.stderr.write('Oh no, the dreaded errors!\n');
495 stream.write('Just kidding about the errors!\n');
496 stream.exit(0);
497 stream.end();
498 });
499 });
500 }).on('end', function() {
501 console.log('Client disconnected');
502 });
503}).listen(0, '127.0.0.1', function() {
504 console.log('Listening on port ' + this.address().port);
505});
506```
507
508### SFTP-only server
509
510```js
511var fs = require('fs');
512var crypto = require('crypto');
513
514var ssh2 = require('ssh2');
515var OPEN_MODE = ssh2.SFTP_OPEN_MODE;
516var STATUS_CODE = ssh2.SFTP_STATUS_CODE;
517
518var allowedUser = Buffer.from('foo');
519var allowedPassword = Buffer.from('bar');
520
521new ssh2.Server({
522 hostKeys: [fs.readFileSync('host.key')]
523}, function(client) {
524 console.log('Client connected!');
525
526 client.on('authentication', function(ctx) {
527 var user = Buffer.from(ctx.username);
528 if (user.length !== allowedUser.length
529 || !crypto.timingSafeEqual(user, allowedUser)) {
530 return ctx.reject();
531 }
532
533 switch (ctx.method) {
534 case 'password':
535 var password = Buffer.from(ctx.password);
536 if (password.length !== allowedPassword.length
537 || !crypto.timingSafeEqual(password, allowedPassword)) {
538 return ctx.reject();
539 }
540 default:
541 return ctx.reject();
542 }
543
544 ctx.accept();
545 }).on('ready', function() {
546 console.log('Client authenticated!');
547
548 client.on('session', function(accept, reject) {
549 var session = accept();
550 session.on('sftp', function(accept, reject) {
551 console.log('Client SFTP session');
552 var openFiles = {};
553 var handleCount = 0;
554 // `sftpStream` is an `SFTPStream` instance in server mode
555 // see: https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
556 var sftpStream = accept();
557 sftpStream.on('OPEN', function(reqid, filename, flags, attrs) {
558 // only allow opening /tmp/foo.txt for writing
559 if (filename !== '/tmp/foo.txt' || !(flags & OPEN_MODE.WRITE))
560 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
561 // create a fake handle to return to the client, this could easily
562 // be a real file descriptor number for example if actually opening
563 // the file on the disk
564 var handle = new Buffer(4);
565 openFiles[handleCount] = true;
566 handle.writeUInt32BE(handleCount++, 0, true);
567 sftpStream.handle(reqid, handle);
568 console.log('Opening file for write')
569 }).on('WRITE', function(reqid, handle, offset, data) {
570 if (handle.length !== 4 || !openFiles[handle.readUInt32BE(0, true)])
571 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
572 // fake the write
573 sftpStream.status(reqid, STATUS_CODE.OK);
574 var inspected = require('util').inspect(data);
575 console.log('Write to file at offset %d: %s', offset, inspected);
576 }).on('CLOSE', function(reqid, handle) {
577 var fnum;
578 if (handle.length !== 4 || !openFiles[(fnum = handle.readUInt32BE(0, true))])
579 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
580 delete openFiles[fnum];
581 sftpStream.status(reqid, STATUS_CODE.OK);
582 console.log('Closing file');
583 });
584 });
585 });
586 }).on('end', function() {
587 console.log('Client disconnected');
588 });
589}).listen(0, '127.0.0.1', function() {
590 console.log('Listening on port ' + this.address().port);
591});
592```
593
594You can find more examples in the `examples` directory of this repository.
595
596## API
597
598`require('ssh2').Client` returns a **_Client_** constructor.
599
600`require('ssh2').Server` returns a **_Server_** constructor.
601
602`require('ssh2').utils` returns the [utility methods from `ssh2-streams`](https://github.com/mscdex/ssh2-streams#utility-methods).
603
604`require('ssh2').SFTP_STATUS_CODE` returns the [`SFTPStream.STATUS_CODE` from `ssh2-streams`](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md#sftpstream-static-constants).
605
606`require('ssh2').SFTP_OPEN_MODE` returns the [`SFTPStream.OPEN_MODE` from `ssh2-streams`](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md#sftpstream-static-constants).
607
608### Client
609
610#### Client events
611
612* **banner**(< _string_ >message, < _string_ >language) - A notice was sent by the server upon connection.
613
614* **ready**() - Authentication was successful.
615
616* **tcp connection**(< _object_ >details, < _function_ >accept, < _function_ >reject) - An incoming forwarded TCP connection is being requested. Calling `accept` accepts the connection and returns a `Channel` object. Calling `reject` rejects the connection and no further action is needed. `details` contains:
617
618 * **srcIP** - _string_ - The originating IP of the connection.
619
620 * **srcPort** - _integer_ - The originating port of the connection.
621
622 * **destIP** - _string_ - The remote IP the connection was received on (given in earlier call to `forwardIn()`).
623
624 * **destPort** - _integer_ - The remote port the connection was received on (given in earlier call to `forwardIn()`).
625
626* **x11**(< _object_ >details, < _function_ >accept, < _function_ >reject) - An incoming X11 connection is being requested. Calling `accept` accepts the connection and returns a `Channel` object. Calling `reject` rejects the connection and no further action is needed. `details` contains:
627
628 * **srcIP** - _string_ - The originating IP of the connection.
629
630 * **srcPort** - _integer_ - The originating port of the connection.
631
632* **keyboard-interactive**(< _string_ >name, < _string_ >instructions, < _string_ >instructionsLang, < _array_ >prompts, < _function_ >finish) - The server is asking for replies to the given `prompts` for keyboard-interactive user authentication. `name` is generally what you'd use as a window title (for GUI apps). `prompts` is an array of `{ prompt: 'Password: ', echo: false }` style objects (here `echo` indicates whether user input should be displayed on the screen). The answers for all prompts must be provided as an array of strings and passed to `finish` when you are ready to continue. Note: It's possible for the server to come back and ask more questions.
633
634* **unix connection**(< _object_ >details, < _function_ >accept, < _function_ >reject) - An incoming forwarded UNIX socket connection is being requested. Calling `accept` accepts the connection and returns a `Channel` object. Calling `reject` rejects the connection and no further action is needed. `details` contains:
635
636 * **socketPath** - _string_ - The originating UNIX socket path of the connection.
637
638* **change password**(< _string_ >message, < _string_ >language, < _function_ >done) - If using password-based user authentication, the server has requested that the user's password be changed. Call `done` with the new password.
639
640* **continue**() - Emitted when more requests/data can be sent to the server (after a `Client` method returned `false`).
641
642* **error**(< _Error_ >err) - An error occurred. A 'level' property indicates 'client-socket' for socket-level errors and 'client-ssh' for SSH disconnection messages. In the case of 'client-ssh' messages, there may be a 'description' property that provides more detail.
643
644* **end**() - The socket was disconnected.
645
646* **close**(< _boolean_ >hadError) - The socket was closed. `hadError` is set to `true` if this was due to error.
647
648#### Client methods
649
650* **(constructor)**() - Creates and returns a new Client instance.
651
652* **connect**(< _object_ >config) - _(void)_ - Attempts a connection to a server using the information given in `config`:
653
654 * **host** - _string_ - Hostname or IP address of the server. **Default:** `'localhost'`
655
656 * **port** - _integer_ - Port number of the server. **Default:** `22`
657
658 * **localAddress** - _string_ - IP address of the network interface to use to connect to the server. **Default:** (none -- determined by OS)
659
660 * **localPort** - _string_ - The local port number to connect from. **Default:** (none -- determined by OS)
661
662 * **forceIPv4** - _boolean_ - Only connect via resolved IPv4 address for `host`. **Default:** `false`
663
664 * **forceIPv6** - _boolean_ - Only connect via resolved IPv6 address for `host`. **Default:** `false`
665
666 * **hostHash** - _string_ - Any valid hash algorithm supported by node. The host's key is hashed using this algorithm and passed to the **hostVerifier** function. **Default:** (none)
667
668 * **hostVerifier** - _function_ - Function with parameters `(hashedKey[, callback])` where `hashedKey` is a string hex hash of the host's key for verification purposes. Return `true` to continue with the handshake or `false` to reject and disconnect, or call `callback()` with `true` or `false` if you need to perform asynchronous verification. **Default:** (auto-accept if `hostVerifier` is not set)
669
670 * **username** - _string_ - Username for authentication. **Default:** (none)
671
672 * **password** - _string_ - Password for password-based user authentication. **Default:** (none)
673
674 * **agent** - _string_ - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. **Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket."** **Default:** (none)
675
676 * **agentForward** - _boolean_ - Set to `true` to use OpenSSH agent forwarding (`auth-agent@openssh.com`) for the life of the connection. `agent` must also be set to use this feature. **Default:** `false`
677
678 * **privateKey** - _mixed_ - _Buffer_ or _string_ that contains a private key for either key-based or hostbased user authentication (OpenSSH format). **Default:** (none)
679
680 * **passphrase** - _string_ - For an encrypted private key, this is the passphrase used to decrypt it. **Default:** (none)
681
682 * **localHostname** - _string_ - Along with **localUsername** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
683
684 * **localUsername** - _string_ - Along with **localHostname** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
685
686 * **tryKeyboard** - _boolean_ - Try keyboard-interactive user authentication if primary user authentication method fails. If you set this to `true`, you need to handle the `keyboard-interactive` event. **Default:** `false`
687
688 * **authHandler** - _function_ - Function with parameters `(methodsLeft, partialSuccess, callback)` where `methodsLeft` and `partialSuccess` are `null` on the first authentication attempt, otherwise are an array and boolean respectively. Return or call `callback()` with the name of the authentication method to try next (pass `false` to signal no more methods to try). Valid method names are: `'none', 'password', 'publickey', 'agent', 'keyboard-interactive', 'hostbased'`. **Default:** function that follows a set method order: None -> Password -> Private Key -> Agent (-> keyboard-interactive if `tryKeyboard` is `true`) -> Hostbased
689
690 * **keepaliveInterval** - _integer_ - How often (in milliseconds) to send SSH-level keepalive packets to the server (in a similar way as OpenSSH's ServerAliveInterval config option). Set to 0 to disable. **Default:** `0`
691
692 * **keepaliveCountMax** - _integer_ - How many consecutive, unanswered SSH-level keepalive packets that can be sent to the server before disconnection (similar to OpenSSH's ServerAliveCountMax config option). **Default:** `3`
693
694 * **readyTimeout** - _integer_ - How long (in milliseconds) to wait for the SSH handshake to complete. **Default:** `20000`
695
696 * **sock** - _ReadableStream_ - A _ReadableStream_ to use for communicating with the server instead of creating and using a new TCP connection (useful for connection hopping).
697
698 * **strictVendor** - _boolean_ - Performs a strict server vendor check before sending vendor-specific requests, etc. (e.g. check for OpenSSH server when using `openssh_noMoreSessions()`) **Default:** `true`
699
700 * **algorithms** - _object_ - This option allows you to explicitly override the default transport layer algorithms used for the connection. Each value must be an array of valid algorithms for that category. The order of the algorithms in the arrays are important, with the most favorable being first. For a list of valid and default algorithm names, please review the documentation for the version of `ssh2-streams` used by this module. Valid keys:
701
702 * **kex** - _array_ - Key exchange algorithms.
703
704 * **cipher** - _array_ - Ciphers.
705
706 * **serverHostKey** - _array_ - Server host key formats.
707
708 * **hmac** - _array_ - (H)MAC algorithms.
709
710 * **compress** - _array_ - Compression algorithms.
711
712 * **compress** - _mixed_ - Set to `true` to enable compression if server supports it, `'force'` to force compression (disconnecting if server does not support it), or `false` to explicitly opt out of compression all of the time. Note: this setting is overridden when explicitly setting a compression algorithm in the `algorithms` configuration option. **Default:** (only use compression if that is only what the server supports)
713
714 * **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none)
715
716**Default authentication method order:** None -> Password -> Private Key -> Agent (-> keyboard-interactive if `tryKeyboard` is `true`) -> Hostbased
717
718* **exec**(< _string_ >command[, < _object_ >options], < _function_ >callback) - _boolean_ - Executes `command` on the server. Returns `false` if you should wait for the `continue` event before sending any more traffic. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Valid `options` properties are:
719
720 * **env** - _object_ - An environment to use for the execution of the command.
721
722 * **pty** - _mixed_ - Set to `true` to allocate a pseudo-tty with defaults, or an object containing specific pseudo-tty settings (see 'Pseudo-TTY settings'). Setting up a pseudo-tty can be useful when working with remote processes that expect input from an actual terminal (e.g. sudo's password prompt).
723
724 * **x11** - _mixed_ - Set to `true` to use defaults below, set to a number to specify a specific screen number, or an object with the following valid properties:
725
726 * **single** - _boolean_ - Allow just a single connection? **Default:** `false`
727
728 * **screen** - _number_ - Screen number to use **Default:** `0`
729
730 * **protocol** - _string_ - The authentication protocol name. **Default:** `'MIT-MAGIC-COOKIE-1'`
731
732 * **cookie** - _mixed_ - The authentication cookie. Can be a hex _string_ or a _Buffer_ containing the raw cookie value (which will be converted to a hex string). **Default:** (random 16 byte value)
733
734* **shell**([[< _mixed_ >window,] < _object_ >options]< _function_ >callback) - _boolean_ - Starts an interactive shell session on the server, with an optional `window` object containing pseudo-tty settings (see 'Pseudo-TTY settings'). If `window === false`, then no pseudo-tty is allocated. `options` supports the `x11` and `env` options as described in `exec()`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
735
736* **forwardIn**(< _string_ >remoteAddr, < _integer_ >remotePort, < _function_ >callback) - _boolean_ - Bind to `remoteAddr` on `remotePort` on the server and forward incoming TCP connections. `callback` has 2 parameters: < _Error_ >err, < _integer_ >port (`port` is the assigned port number if `remotePort` was 0). Returns `false` if you should wait for the `continue` event before sending any more traffic. Here are some special values for `remoteAddr` and their associated binding behaviors:
737
738 * '' - Connections are to be accepted on all protocol families supported by the server.
739
740 * '0.0.0.0' - Listen on all IPv4 addresses.
741
742 * '::' - Listen on all IPv6 addresses.
743
744 * 'localhost' - Listen on all protocol families supported by the server on loopback addresses only.
745
746 * '127.0.0.1' and '::1' - Listen on the loopback interfaces for IPv4 and IPv6, respectively.
747
748* **unforwardIn**(< _string_ >remoteAddr, < _integer_ >remotePort, < _function_ >callback) - _boolean_ - Unbind from `remoteAddr` on `remotePort` on the server and stop forwarding incoming TCP connections. Until `callback` is called, more connections may still come in. `callback` has 1 parameter: < _Error_ >err. Returns `false` if you should wait for the `continue` event before sending any more traffic.
749
750* **forwardOut**(< _string_ >srcIP, < _integer_ >srcPort, < _string_ >dstIP, < _integer_ >dstPort, < _function_ >callback) - _boolean_ - Open a connection with `srcIP` and `srcPort` as the originating address and port and `dstIP` and `dstPort` as the remote destination address and port. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
751
752* **sftp**(< _function_ >callback) - _boolean_ - Starts an SFTP session. `callback` has 2 parameters: < _Error_ >err, < _SFTPStream_ >sftp. For methods available on `sftp`, see the [`SFTPStream` client documentation](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) (except `read()` and `write()` are used instead of `readData()` and `writeData()` respectively, for convenience). Returns `false` if you should wait for the `continue` event before sending any more traffic.
753
754* **subsys**(< _string_ >subsystem, < _function_ >callback) - _boolean_ - Invokes `subsystem` on the server. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
755
756* **end**() - _(void)_ - Disconnects the socket.
757
758* **openssh_noMoreSessions**(< _function_ >callback) - _boolean_ - OpenSSH extension that sends a request to reject any new sessions (e.g. exec, shell, sftp, subsys) for this connection. `callback` has 1 parameter: < _Error_ >err. Returns `false` if you should wait for the `continue` event before sending any more traffic.
759
760* **openssh_forwardInStreamLocal**(< _string_ >socketPath, < _function_ >callback) - _boolean_ - OpenSSH extension that binds to a UNIX domain socket at `socketPath` on the server and forwards incoming connections. `callback` has 1 parameter: < _Error_ >err. Returns `false` if you should wait for the `continue` event before sending any more traffic.
761
762* **openssh_unforwardInStreamLocal**(< _string_ >socketPath, < _function_ >callback) - _boolean_ - OpenSSH extension that unbinds from a UNIX domain socket at `socketPath` on the server and stops forwarding incoming connections. `callback` has 1 parameter: < _Error_ >err. Returns `false` if you should wait for the `continue` event before sending any more traffic.
763
764* **openssh_forwardOutStreamLocal**(< _string_ >socketPath, < _function_ >callback) - _boolean_ - OpenSSH extension that opens a connection to a UNIX domain socket at `socketPath` on the server. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
765
766### Server
767
768#### Server events
769
770* **connection**(< _Connection_ >client, < _object_ >info) - A new client has connected. `info` contains the following properties:
771
772 * **ip** - _string_ - The `remoteAddress` of the connection.
773
774 * **family** - _string_ - The `remoteFamily` of the connection.
775
776 * **port** - _integer_ - The `remotePort` of the connection.
777
778 * **header** - _object_ - Information about the client's header:
779
780 * **identRaw** - _string_ - The raw client identification string.
781
782 * **versions** - _object_ - Various version information:
783
784 * **protocol** - _string_ - The SSH protocol version (always `1.99` or `2.0`).
785
786 * **software** - _string_ - The software name and version of the client.
787
788 * **comments** - _string_ - Any text that comes after the software name/version.
789
790 Example: the identification string `SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2` would be parsed as:
791
792```js
793 { identRaw: 'SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2',
794 version: {
795 protocol: '2.0',
796 software: 'OpenSSH_6.6.1p1'
797 },
798 comments: 'Ubuntu-2ubuntu2' }
799```
800
801#### Server methods
802
803* **(constructor)**(< _object_ >config[, < _function_ >connectionListener]) - Creates and returns a new Server instance. Server instances also have the same methods/properties/events as [`net.Server`](http://nodejs.org/docs/latest/api/net.html#net_class_net_server). `connectionListener` if supplied, is added as a `connection` listener. Valid `config` properties:
804
805 * **hostKeys** - _array_ - An array of either Buffers/strings that contain host private keys or objects in the format of `{ key: <Buffer/string>, passphrase: <string> }` for encrypted private keys. (**Required**) **Default:** (none)
806
807 * **algorithms** - _object_ - This option allows you to explicitly override the default transport layer algorithms used for incoming client connections. Each value must be an array of valid algorithms for that category. The order of the algorithms in the arrays are important, with the most favorable being first. For a list of valid and default algorithm names, please review the documentation for the version of `ssh2-streams` used by this module. Valid keys:
808
809 * **kex** - _array_ - Key exchange algorithms.
810
811 * **cipher** - _array_ - Ciphers.
812
813 * **serverHostKey** - _array_ - Server host key formats.
814
815 * **hmac** - _array_ - (H)MAC algorithms.
816
817 * **compress** - _array_ - Compression algorithms.
818
819 * **greeting** - _string_ - A message that is sent to clients immediately upon connection, before handshaking begins. **Note:** Most clients usually ignore this. **Default:** (none)
820
821 * **banner** - _string_ - A message that is sent to clients once, right before authentication begins. **Default:** (none)
822
823 * **ident** - _string_ - A custom server software name/version identifier. **Default:** `'ssh2js' + moduleVersion + 'srv'`
824
825 * **highWaterMark** - _integer_ - This is the `highWaterMark` to use for the parser stream. **Default:** `32 * 1024`
826
827 * **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none)
828
829#### Connection events
830
831* **authentication**(< _AuthContext_ >ctx) - The client has requested authentication. `ctx.username` contains the client username, `ctx.method` contains the requested authentication method, and `ctx.accept()` and `ctx.reject([< Array >authMethodsLeft[, < Boolean >isPartialSuccess]])` are used to accept or reject the authentication request respectively. `abort` is emitted if the client aborts the authentication request. Other properties/methods available on `ctx` depends on the `ctx.method` of authentication the client has requested:
832
833 * `password`:
834
835 * **password** - _string_ - This is the password sent by the client.
836
837 * `publickey`:
838
839 * **key** - _object_ - Contains information about the public key sent by the client:
840
841 * **algo** - _string_ - The name of the key algorithm (e.g. `ssh-rsa`).
842
843 * **data** - _Buffer_ - The actual key data.
844
845 * **sigAlgo** - _mixed_ - If the value is `undefined`, the client is only checking the validity of the `key`. If the value is a _string_, then this contains the signature algorithm that is passed to [`crypto.createVerify()`](http://nodejs.org/docs/latest/api/crypto.html#crypto_crypto_createverify_algorithm).
846
847 * **blob** - _mixed_ - If the value is `undefined`, the client is only checking the validity of the `key`. If the value is a _Buffer_, then this contains the data that is passed to [`verifier.update()`](http://nodejs.org/docs/latest/api/crypto.html#crypto_verifier_update_data).
848
849 * **signature** - _mixed_ - If the value is `undefined`, the client is only checking the validity of the `key`. If the value is a _Buffer_, then this contains a signature that is passed to [`verifier.verify()`](http://nodejs.org/docs/latest/api/crypto.html#crypto_verifier_verify_object_signature_signature_format).
850
851 * `keyboard-interactive`:
852
853 * **submethods** - _array_ - A list of preferred authentication "sub-methods" sent by the client. This may be used to determine what (if any) prompts to send to the client.
854
855 * **prompt**(< _array_ >prompts[, < _string_ >title[, < _string_ >instructions]], < _function_ >callback) - _boolean_ - Send prompts to the client. `prompts` is an array of `{ prompt: 'Prompt text', echo: true }` objects (`prompt` being the prompt text and `echo` indicating whether the client's response to the prompt should be echoed to their display). `callback` is called with `(err, responses)`, where `responses` is an array of string responses matching up to the `prompts`.
856
857* **ready**() - Emitted when the client has been successfully authenticated.
858
859* **session**(< _function_ >accept, < _function_ >reject) - Emitted when the client has requested a new session. Sessions are used to start interactive shells, execute commands, request X11 forwarding, etc. `accept()` returns a new _Session_ instance. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic.
860
861* **tcpip**(< _function_ >accept, < _function_ >reject, < _object_ >info) - Emitted when the client has requested an outbound (TCP) connection. `accept()` returns a new _Channel_ instance representing the connection. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic. `info` contains:
862
863 * **srcIP** - _string_ - Source IP address of outgoing connection.
864
865 * **srcPort** - _string_ - Source port of outgoing connection.
866
867 * **destIP** - _string_ - Destination IP address of outgoing connection.
868
869 * **destPort** - _string_ - Destination port of outgoing connection.
870
871* **openssh.streamlocal**(< _function_ >accept, < _function_ >reject, < _object_ >info) - Emitted when the client has requested a connection to a UNIX domain socket. `accept()` returns a new _Channel_ instance representing the connection. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic. `info` contains:
872
873 * **socketPath** - _string_ - Destination socket path of outgoing connection.
874
875* **request**(< _mixed_ >accept, < _mixed_ >reject, < _string_ >name, < _object_ >info) - Emitted when the client has sent a global request for `name` (e.g. `tcpip-forward` or `cancel-tcpip-forward`). `accept` and `reject` are functions if the client requested a response. If `bindPort === 0`, you should pass the chosen port to `accept()` so that the client will know what port was bound. `info` contains additional details about the request:
876
877 * `tcpip-forward` and `cancel-tcpip-forward`:
878
879 * **bindAddr** - _string_ - The IP address to start/stop binding to.
880
881 * **bindPort** - _integer_ - The port to start/stop binding to.
882
883 * `streamlocal-forward@openssh.com` and `cancel-streamlocal-forward@openssh.com`:
884
885 * **socketPath** - _string_ - The socket path to start/stop binding to.
886
887* **rekey**() - Emitted when the client has finished rekeying (either client or server initiated).
888
889* **continue**() - Emitted when more requests/data can be sent to the client (after a `Connection` method returned `false`).
890
891* **error**(< _Error_ >err) - An error occurred.
892
893* **end**() - The client socket disconnected.
894
895* **close**(< _boolean_ >hadError) - The client socket was closed. `hadError` is set to `true` if this was due to error.
896
897#### Connection methods
898
899* **end**() - _boolean_ - Closes the client connection. Returns `false` if you should wait for the `continue` event before sending any more traffic.
900
901* **x11**(< _string_ >originAddr, < _integer_ >originPort, < _function_ >callback) - _boolean_ - Alert the client of an incoming X11 client connection from `originAddr` on port `originPort`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
902
903* **forwardOut**(< _string_ >boundAddr, < _integer_ >boundPort, < _string_ >remoteAddr, < _integer_ >remotePort, < _function_ >callback) - _boolean_ - Alert the client of an incoming TCP connection on `boundAddr` on port `boundPort` from `remoteAddr` on port `remotePort`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
904
905* **openssh_forwardOutStreamLocal**(< _string_ >socketPath, < _function_ >callback) - _boolean_ - Alert the client of an incoming UNIX domain socket connection on `socketPath`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.
906
907* **rekey**([< _function_ >callback]) - _boolean_ - Initiates a rekeying with the client. If `callback` is supplied, it is added as a one-time handler for the `rekey` event. Returns `false` if you should wait for the `continue` event before sending any more traffic.
908
909#### Session events
910
911* **pty**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client requested allocation of a pseudo-TTY for this session. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
912
913 * **cols** - _integer_ - The number of columns for the pseudo-TTY.
914
915 * **rows** - _integer_ - The number of rows for the pseudo-TTY.
916
917 * **width** - _integer_ - The width of the pseudo-TTY in pixels.
918
919 * **height** - _integer_ - The height of the pseudo-TTY in pixels.
920
921 * **modes** - _object_ - Contains the requested terminal modes of the pseudo-TTY keyed on the mode name with the value being the mode argument. (See the table at the end for valid names).
922
923* **window-change**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client reported a change in window dimensions during this session. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
924
925 * **cols** - _integer_ - The new number of columns for the client window.
926
927 * **rows** - _integer_ - The new number of rows for the client window.
928
929 * **width** - _integer_ - The new width of the client window in pixels.
930
931 * **height** - _integer_ - The new height of the client window in pixels.
932
933* **x11**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client requested X11 forwarding. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
934
935 * **single** - _boolean_ - `true` if only a single connection should be forwarded.
936
937 * **protocol** - _string_ - The name of the X11 authentication method used (e.g. `MIT-MAGIC-COOKIE-1`).
938
939 * **cookie** - _string_ - The X11 authentication cookie encoded in hexadecimal.
940
941 * **screen** - _integer_ - The screen number to forward X11 connections for.
942
943* **env**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client requested an environment variable to be set for this session. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
944
945 * **key** - _string_ - The environment variable's name.
946
947 * **value** - _string_ - The environment variable's value.
948
949* **signal**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client has sent a signal. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
950
951 * **name** - _string_ - The signal name (e.g. `SIGUSR1`).
952
953* **auth-agent**(< _mixed_ >accept, < _mixed_ >reject) - The client has requested incoming ssh-agent requests be forwarded to them. `accept` and `reject` are functions if the client requested a response and return `false` if you should wait for the `continue` event before sending any more traffic.
954
955* **shell**(< _mixed_ >accept, < _mixed_ >reject) - The client has requested an interactive shell. `accept` and `reject` are functions if the client requested a response. `accept()` returns a _Channel_ for the interactive shell. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic.
956
957* **exec**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client has requested execution of a command string. `accept` and `reject` are functions if the client requested a response. `accept()` returns a _Channel_ for the command execution. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
958
959 * **command** - _string_ - The command line to be executed.
960
961* **sftp**(< _mixed_ >accept, < _mixed_ >reject) - The client has requested the SFTP subsystem. `accept` and `reject` are functions if the client requested a response. `accept()` returns an _SFTPStream_ in server mode (see the [`SFTPStream` documentation](https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md) for details). `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
962
963* **subsystem**(< _mixed_ >accept, < _mixed_ >reject, < _object_ >info) - The client has requested an arbitrary subsystem. `accept` and `reject` are functions if the client requested a response. `accept()` returns a _Channel_ for the subsystem. `reject()` Returns `false` if you should wait for the `continue` event before sending any more traffic. `info` has these properties:
964
965 * **name** - _string_ - The name of the subsystem.
966
967* **close**() - The session was closed.
968
969### Channel
970
971This is a normal **streams2** Duplex Stream (used both by clients and servers), with the following changes:
972
973* A boolean property `allowHalfOpen` exists and behaves similarly to the property of the same name for `net.Socket`. When the stream's end() is called, if `allowHalfOpen` is `true`, only EOF will be sent (the server can still send data if they have not already sent EOF). The default value for this property is `true`.
974
975* A `close` event is emitted once the channel is completely closed on both the client and server.
976
977* Client-specific:
978
979 * For exec():
980
981 * An `exit` event *may* (the SSH2 spec says it is optional) be emitted when the process finishes. If the process finished normally, the process's return value is passed to the `exit` callback. If the process was interrupted by a signal, the following are passed to the `exit` callback: null, < _string_ >signalName, < _boolean_ >didCoreDump, < _string_ >description.
982
983 * If there was an `exit` event, the `close` event will be passed the same arguments for convenience.
984
985 * For shell() and exec():
986
987 * The readable side represents stdout and the writable side represents stdin.
988
989 * A `stderr` property contains a Readable stream that represents output from stderr.
990
991 * **signal**(< _string_ >signalName) - _boolean_ - Sends a POSIX signal to the current process on the server. Valid signal names are: 'ABRT', 'ALRM', 'FPE', 'HUP', 'ILL', 'INT', 'KILL', 'PIPE', 'QUIT', 'SEGV', 'TERM', 'USR1', and 'USR2'. Some server implementations may ignore this request if they do not support signals. Note: If you are trying to send SIGINT and you find `signal()` doesn't work, try writing `'\x03'` to the Channel stream instead. Returns `false` if you should wait for the `continue` event before sending any more traffic.
992
993 * **setWindow**(< _integer_ >rows, < _integer_ >cols, < _integer_ >height, < _integer_ >width) - _boolean_ - Lets the server know that the local terminal window has been resized. The meaning of these arguments are described in the 'Pseudo-TTY settings' section. Returns `false` if you should wait for the `continue` event before sending any more traffic.
994
995* Server-specific:
996
997 * For exec-enabled channel instances there is an additional method available that may be called right before you close the channel. It has two different signatures:
998
999 * **exit**(< _integer_ >exitCode) - _boolean_ - Sends an exit status code to the client. Returns `false` if you should wait for the `continue` event before sending any more traffic.
1000
1001 * **exit**(< _string_ >signalName[, < _boolean_ >coreDumped[, < _string_ >errorMsg]]) - _boolean_ - Sends an exit status code to the client. Returns `false` if you should wait for the `continue` event before sending any more traffic.
1002
1003 * For exec and shell-enabled channel instances, `channel.stderr` is a writable stream.
1004
1005### Pseudo-TTY settings
1006
1007* **rows** - < _integer_ > - Number of rows. **Default:** `24`
1008
1009* **cols** - < _integer_ > - Number of columns. **Default:** `80`
1010
1011* **height** - < _integer_ > - Height in pixels. **Default:** `480`
1012
1013* **width** - < _integer_ > - Width in pixels. **Default:** `640`
1014
1015* **term** - < _string_ > - The value to use for $TERM. **Default:** `'vt100'`
1016
1017`rows` and `cols` override `width` and `height` when `rows` and `cols` are non-zero.
1018
1019Pixel dimensions refer to the drawable area of the window.
1020
1021Zero dimension parameters are ignored.
1022
1023### Terminal modes
1024
1025Name | Description
1026-------------- | ------------
1027VINTR | Interrupt character; 255 if none. Similarly for the other characters. Not all of these characters are supported on all systems.
1028VQUIT | The quit character (sends SIGQUIT signal on POSIX systems).
1029VERASE | Erase the character to left of the cursor.
1030VKILL | Kill the current input line.
1031VEOF | End-of-file character (sends EOF from the terminal).
1032VEOL | End-of-line character in addition to carriage return and/or linefeed.
1033VEOL2 | Additional end-of-line character.
1034VSTART | Continues paused output (normally control-Q).
1035VSTOP | Pauses output (normally control-S).
1036VSUSP | Suspends the current program.
1037VDSUSP | Another suspend character.
1038VREPRINT | Reprints the current input line.
1039VWERASE | Erases a word left of cursor.
1040VLNEXT | Enter the next character typed literally, even if it is a special character
1041VFLUSH | Character to flush output.
1042VSWTCH | Switch to a different shell layer.
1043VSTATUS | Prints system status line (load, command, pid, etc).
1044VDISCARD | Toggles the flushing of terminal output.
1045IGNPAR | The ignore parity flag. The parameter SHOULD be 0 if this flag is FALSE, and 1 if it is TRUE.
1046PARMRK | Mark parity and framing errors.
1047INPCK | Enable checking of parity errors.
1048ISTRIP | Strip 8th bit off characters.
1049INLCR | Map NL into CR on input.
1050IGNCR | Ignore CR on input.
1051ICRNL | Map CR to NL on input.
1052IUCLC | Translate uppercase characters to lowercase.
1053IXON | Enable output flow control.
1054IXANY | Any char will restart after stop.
1055IXOFF | Enable input flow control.
1056IMAXBEL | Ring bell on input queue full.
1057ISIG | Enable signals INTR, QUIT, [D]SUSP.
1058ICANON | Canonicalize input lines.
1059XCASE | Enable input and output of uppercase characters by preceding their lowercase equivalents with "\".
1060ECHO | Enable echoing.
1061ECHOE | Visually erase chars.
1062ECHOK | Kill character discards current line.
1063ECHONL | Echo NL even if ECHO is off.
1064NOFLSH | Don't flush after interrupt.
1065TOSTOP | Stop background jobs from output.
1066IEXTEN | Enable extensions.
1067ECHOCTL | Echo control characters as ^(Char).
1068ECHOKE | Visual erase for line kill.
1069PENDIN | Retype pending input.
1070OPOST | Enable output processing.
1071OLCUC | Convert lowercase to uppercase.
1072ONLCR | Map NL to CR-NL.
1073OCRNL | Translate carriage return to newline (output).
1074ONOCR | Translate newline to carriage return-newline (output).
1075ONLRET | Newline performs a carriage return (output).
1076CS7 | 7 bit mode.
1077CS8 | 8 bit mode.
1078PARENB | Parity enable.
1079PARODD | Odd parity, else even.
1080TTY_OP_ISPEED | Specifies the input baud rate in bits per second.
1081TTY_OP_OSPEED | Specifies the output baud rate in bits per second.