UNPKG

53.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 buffersEqual = require('buffer-equal-constant-time');
446var ssh2 = require('ssh2');
447var utils = ssh2.utils;
448
449var pubKey = utils.genPublicKey(utils.parseKey(fs.readFileSync('user.pub')));
450
451new ssh2.Server({
452 hostKeys: [fs.readFileSync('host.key')]
453}, function(client) {
454 console.log('Client connected!');
455
456 client.on('authentication', function(ctx) {
457 if (ctx.method === 'password'
458 // Note: Don't do this in production code, see
459 // https://www.brendanlong.com/timing-attacks-and-usernames.html
460 // In node v6.0.0+, you can use `crypto.timingSafeEqual()` to safely
461 // compare two values.
462 && ctx.username === 'foo'
463 && ctx.password === 'bar')
464 ctx.accept();
465 else if (ctx.method === 'publickey'
466 && ctx.key.algo === pubKey.fulltype
467 && buffersEqual(ctx.key.data, pubKey.public)) {
468 if (ctx.signature) {
469 var verifier = crypto.createVerify(ctx.sigAlgo);
470 verifier.update(ctx.blob);
471 if (verifier.verify(pubKey.publicOrig, ctx.signature))
472 ctx.accept();
473 else
474 ctx.reject();
475 } else {
476 // if no signature present, that means the client is just checking
477 // the validity of the given public key
478 ctx.accept();
479 }
480 } else
481 ctx.reject();
482 }).on('ready', function() {
483 console.log('Client authenticated!');
484
485 client.on('session', function(accept, reject) {
486 var session = accept();
487 session.once('exec', function(accept, reject, info) {
488 console.log('Client wants to execute: ' + inspect(info.command));
489 var stream = accept();
490 stream.stderr.write('Oh no, the dreaded errors!\n');
491 stream.write('Just kidding about the errors!\n');
492 stream.exit(0);
493 stream.end();
494 });
495 });
496 }).on('end', function() {
497 console.log('Client disconnected');
498 });
499}).listen(0, '127.0.0.1', function() {
500 console.log('Listening on port ' + this.address().port);
501});
502```
503
504### SFTP-only server
505
506```js
507var fs = require('fs');
508
509var ssh2 = require('ssh2');
510var OPEN_MODE = ssh2.SFTP_OPEN_MODE;
511var STATUS_CODE = ssh2.SFTP_STATUS_CODE;
512
513new ssh2.Server({
514 hostKeys: [fs.readFileSync('host.key')]
515}, function(client) {
516 console.log('Client connected!');
517
518 client.on('authentication', function(ctx) {
519 if (ctx.method === 'password'
520 // Note: Don't do this in production code, see
521 // https://www.brendanlong.com/timing-attacks-and-usernames.html
522 // In node v6.0.0+, you can use `crypto.timingSafeEqual()` to safely
523 // compare two values.
524 && ctx.username === 'foo'
525 && ctx.password === 'bar')
526 ctx.accept();
527 else
528 ctx.reject();
529 }).on('ready', function() {
530 console.log('Client authenticated!');
531
532 client.on('session', function(accept, reject) {
533 var session = accept();
534 session.on('sftp', function(accept, reject) {
535 console.log('Client SFTP session');
536 var openFiles = {};
537 var handleCount = 0;
538 // `sftpStream` is an `SFTPStream` instance in server mode
539 // see: https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
540 var sftpStream = accept();
541 sftpStream.on('OPEN', function(reqid, filename, flags, attrs) {
542 // only allow opening /tmp/foo.txt for writing
543 if (filename !== '/tmp/foo.txt' || !(flags & OPEN_MODE.WRITE))
544 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
545 // create a fake handle to return to the client, this could easily
546 // be a real file descriptor number for example if actually opening
547 // the file on the disk
548 var handle = new Buffer(4);
549 openFiles[handleCount] = true;
550 handle.writeUInt32BE(handleCount++, 0, true);
551 sftpStream.handle(reqid, handle);
552 console.log('Opening file for write')
553 }).on('WRITE', function(reqid, handle, offset, data) {
554 if (handle.length !== 4 || !openFiles[handle.readUInt32BE(0, true)])
555 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
556 // fake the write
557 sftpStream.status(reqid, STATUS_CODE.OK);
558 var inspected = require('util').inspect(data);
559 console.log('Write to file at offset %d: %s', offset, inspected);
560 }).on('CLOSE', function(reqid, handle) {
561 var fnum;
562 if (handle.length !== 4 || !openFiles[(fnum = handle.readUInt32BE(0, true))])
563 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
564 delete openFiles[fnum];
565 sftpStream.status(reqid, STATUS_CODE.OK);
566 console.log('Closing file');
567 });
568 });
569 });
570 }).on('end', function() {
571 console.log('Client disconnected');
572 });
573}).listen(0, '127.0.0.1', function() {
574 console.log('Listening on port ' + this.address().port);
575});
576```
577
578You can find more examples in the `examples` directory of this repository.
579
580## API
581
582`require('ssh2').Client` returns a **_Client_** constructor.
583
584`require('ssh2').Server` returns a **_Server_** constructor.
585
586`require('ssh2').utils` returns the [utility methods from `ssh2-streams`](https://github.com/mscdex/ssh2-streams#utility-methods).
587
588`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).
589
590`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).
591
592### Client
593
594#### Client events
595
596* **banner**(< _string_ >message, < _string_ >language) - A notice was sent by the server upon connection.
597
598* **ready**() - Authentication was successful.
599
600* **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:
601
602 * **srcIP** - _string_ - The originating IP of the connection.
603
604 * **srcPort** - _integer_ - The originating port of the connection.
605
606 * **destIP** - _string_ - The remote IP the connection was received on (given in earlier call to `forwardIn()`).
607
608 * **destPort** - _integer_ - The remote port the connection was received on (given in earlier call to `forwardIn()`).
609
610* **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:
611
612 * **srcIP** - _string_ - The originating IP of the connection.
613
614 * **srcPort** - _integer_ - The originating port of the connection.
615
616* **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.
617
618* **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:
619
620 * **socketPath** - _string_ - The originating UNIX socket path of the connection.
621
622* **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.
623
624* **continue**() - Emitted when more requests/data can be sent to the server (after a `Client` method returned `false`).
625
626* **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.
627
628* **end**() - The socket was disconnected.
629
630* **close**(< _boolean_ >hadError) - The socket was closed. `hadError` is set to `true` if this was due to error.
631
632#### Client methods
633
634* **(constructor)**() - Creates and returns a new Client instance.
635
636* **connect**(< _object_ >config) - _(void)_ - Attempts a connection to a server using the information given in `config`:
637
638 * **host** - _string_ - Hostname or IP address of the server. **Default:** `'localhost'`
639
640 * **port** - _integer_ - Port number of the server. **Default:** `22`
641
642 * **forceIPv4** - _boolean_ - Only connect via resolved IPv4 address for `host`. **Default:** `false`
643
644 * **forceIPv6** - _boolean_ - Only connect via resolved IPv6 address for `host`. **Default:** `false`
645
646 * **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)
647
648 * **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)
649
650 * **username** - _string_ - Username for authentication. **Default:** (none)
651
652 * **password** - _string_ - Password for password-based user authentication. **Default:** (none)
653
654 * **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)
655
656 * **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`
657
658 * **privateKey** - _mixed_ - _Buffer_ or _string_ that contains a private key for either key-based or hostbased user authentication (OpenSSH format). **Default:** (none)
659
660 * **passphrase** - _string_ - For an encrypted private key, this is the passphrase used to decrypt it. **Default:** (none)
661
662 * **localHostname** - _string_ - Along with **localUsername** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
663
664 * **localUsername** - _string_ - Along with **localHostname** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
665
666 * **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`
667
668 * **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). **Default:** function that follows a set method order: None -> Password -> Private Key -> Agent (-> keyboard-interactive if `tryKeyboard` is `true`) -> Hostbased
669
670 * **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`
671
672 * **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`
673
674 * **readyTimeout** - _integer_ - How long (in milliseconds) to wait for the SSH handshake to complete. **Default:** `20000`
675
676 * **sock** - _ReadableStream_ - A _ReadableStream_ to use for communicating with the server instead of creating and using a new TCP connection (useful for connection hopping).
677
678 * **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`
679
680 * **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:
681
682 * **kex** - _array_ - Key exchange algorithms.
683
684 * **cipher** - _array_ - Ciphers.
685
686 * **serverHostKey** - _array_ - Server host key formats.
687
688 * **hmac** - _array_ - (H)MAC algorithms.
689
690 * **compress** - _array_ - Compression algorithms.
691
692 * **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)
693
694 * **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none)
695
696**Default authentication method order:** None -> Password -> Private Key -> Agent (-> keyboard-interactive if `tryKeyboard` is `true`) -> Hostbased
697
698* **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:
699
700 * **env** - _object_ - An environment to use for the execution of the command.
701
702 * **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).
703
704 * **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:
705
706 * **single** - _boolean_ - Allow just a single connection? **Default:** `false`
707
708 * **screen** - _number_ - Screen number to use **Default:** `0`
709
710* **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.
711
712* **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:
713
714 * '' - Connections are to be accepted on all protocol families supported by the server.
715
716 * '0.0.0.0' - Listen on all IPv4 addresses.
717
718 * '::' - Listen on all IPv6 addresses.
719
720 * 'localhost' - Listen on all protocol families supported by the server on loopback addresses only.
721
722 * '127.0.0.1' and '::1' - Listen on the loopback interfaces for IPv4 and IPv6, respectively.
723
724* **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.
725
726* **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.
727
728* **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.
729
730* **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.
731
732* **end**() - _(void)_ - Disconnects the socket.
733
734* **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.
735
736* **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.
737
738* **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.
739
740* **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.
741
742### Server
743
744#### Server events
745
746* **connection**(< _Connection_ >client, < _object_ >info) - A new client has connected. `info` contains the following properties:
747
748 * **ip** - _string_ - The remoteAddress of the connection.
749
750 * **header** - _object_ - Information about the client's header:
751
752 * **identRaw** - _string_ - The raw client identification string.
753
754 * **versions** - _object_ - Various version information:
755
756 * **protocol** - _string_ - The SSH protocol version (always `1.99` or `2.0`).
757
758 * **software** - _string_ - The software name and version of the client.
759
760 * **comments** - _string_ - Any text that comes after the software name/version.
761
762 Example: the identification string `SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2` would be parsed as:
763
764```js
765 { identRaw: 'SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2',
766 version: {
767 protocol: '2.0',
768 software: 'OpenSSH_6.6.1p1'
769 },
770 comments: 'Ubuntu-2ubuntu2' }
771```
772
773#### Server methods
774
775* **(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:
776
777 * **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)
778
779 * **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:
780
781 * **kex** - _array_ - Key exchange algorithms.
782
783 * **cipher** - _array_ - Ciphers.
784
785 * **serverHostKey** - _array_ - Server host key formats.
786
787 * **hmac** - _array_ - (H)MAC algorithms.
788
789 * **compress** - _array_ - Compression algorithms.
790
791 * **greeting** - _string_ - A message that is sent to clients immediately upon connection, before handshaking begins. **Note:** Most clients usually ignore this. **Default:** (none)
792
793 * **banner** - _string_ - A message that is sent to clients once, right before authentication begins. **Default:** (none)
794
795 * **ident** - _string_ - A custom server software name/version identifier. **Default:** `'ssh2js' + moduleVersion + 'srv'`
796
797 * **highWaterMark** - _integer_ - This is the `highWaterMark` to use for the parser stream. **Default:** `32 * 1024`
798
799 * **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none)
800
801#### Connection events
802
803* **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:
804
805 * `password`:
806
807 * **password** - _string_ - This is the password sent by the client.
808
809 * `publickey`:
810
811 * **key** - _object_ - Contains information about the public key sent by the client:
812
813 * **algo** - _string_ - The name of the key algorithm (e.g. `ssh-rsa`).
814
815 * **data** - _Buffer_ - The actual key data.
816
817 * **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).
818
819 * **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).
820
821 * **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).
822
823 * `keyboard-interactive`:
824
825 * **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.
826
827 * **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`.
828
829* **ready**() - Emitted when the client has been successfully authenticated.
830
831* **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.
832
833* **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:
834
835 * **srcIP** - _string_ - Source IP address of outgoing connection.
836
837 * **srcPort** - _string_ - Source port of outgoing connection.
838
839 * **destIP** - _string_ - Destination IP address of outgoing connection.
840
841 * **destPort** - _string_ - Destination port of outgoing connection.
842
843* **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:
844
845 * **socketPath** - _string_ - Destination socket path of outgoing connection.
846
847* **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:
848
849 * `tcpip-forward` and `cancel-tcpip-forward`:
850
851 * **bindAddr** - _string_ - The IP address to start/stop binding to.
852
853 * **bindPort** - _integer_ - The port to start/stop binding to.
854
855 * `streamlocal-forward@openssh.com` and `cancel-streamlocal-forward@openssh.com`:
856
857 * **socketPath** - _string_ - The socket path to start/stop binding to.
858
859* **rekey**() - Emitted when the client has finished rekeying (either client or server initiated).
860
861* **continue**() - Emitted when more requests/data can be sent to the client (after a `Connection` method returned `false`).
862
863* **error**(< _Error_ >err) - An error occurred.
864
865* **end**() - The client socket disconnected.
866
867* **close**(< _boolean_ >hadError) - The client socket was closed. `hadError` is set to `true` if this was due to error.
868
869#### Connection methods
870
871* **end**() - _boolean_ - Closes the client connection. Returns `false` if you should wait for the `continue` event before sending any more traffic.
872
873* **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.
874
875* **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.
876
877* **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.
878
879* **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.
880
881#### Session events
882
883* **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:
884
885 * **cols** - _integer_ - The number of columns for the pseudo-TTY.
886
887 * **rows** - _integer_ - The number of rows for the pseudo-TTY.
888
889 * **width** - _integer_ - The width of the pseudo-TTY in pixels.
890
891 * **height** - _integer_ - The height of the pseudo-TTY in pixels.
892
893 * **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).
894
895* **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:
896
897 * **cols** - _integer_ - The new number of columns for the client window.
898
899 * **rows** - _integer_ - The new number of rows for the client window.
900
901 * **width** - _integer_ - The new width of the client window in pixels.
902
903 * **height** - _integer_ - The new height of the client window in pixels.
904
905* **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:
906
907 * **single** - _boolean_ - `true` if only a single connection should be forwarded.
908
909 * **protocol** - _string_ - The name of the X11 authentication method used (e.g. `MIT-MAGIC-COOKIE-1`).
910
911 * **cookie** - _string_ - The X11 authentication cookie encoded in hexadecimal.
912
913 * **screen** - _integer_ - The screen number to forward X11 connections for.
914
915* **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:
916
917 * **key** - _string_ - The environment variable's name.
918
919 * **value** - _string_ - The environment variable's value.
920
921* **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:
922
923 * **name** - _string_ - The signal name (e.g. `SIGUSR1`).
924
925* **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.
926
927* **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.
928
929* **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:
930
931 * **command** - _string_ - The command line to be executed.
932
933* **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:
934
935* **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:
936
937 * **name** - _string_ - The name of the subsystem.
938
939* **close**() - The session was closed.
940
941### Channel
942
943This is a normal **streams2** Duplex Stream (used both by clients and servers), with the following changes:
944
945* 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`.
946
947* A `close` event is emitted once the channel is completely closed on both the client and server.
948
949* Client-specific:
950
951 * For exec():
952
953 * 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.
954
955 * If there was an `exit` event, the `close` event will be passed the same arguments for convenience.
956
957 * For shell() and exec():
958
959 * The readable side represents stdout and the writable side represents stdin.
960
961 * A `stderr` property contains a Readable stream that represents output from stderr.
962
963 * **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.
964
965 * **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.
966
967* Server-specific:
968
969 * 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:
970
971 * **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.
972
973 * **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.
974
975 * For exec and shell-enabled channel instances, `channel.stderr` is a writable stream.
976
977### Pseudo-TTY settings
978
979* **rows** - < _integer_ > - Number of rows. **Default:** `24`
980
981* **cols** - < _integer_ > - Number of columns. **Default:** `80`
982
983* **height** - < _integer_ > - Height in pixels. **Default:** `480`
984
985* **width** - < _integer_ > - Width in pixels. **Default:** `640`
986
987* **term** - < _string_ > - The value to use for $TERM. **Default:** `'vt100'`
988
989`rows` and `cols` override `width` and `height` when `rows` and `cols` are non-zero.
990
991Pixel dimensions refer to the drawable area of the window.
992
993Zero dimension parameters are ignored.
994
995### Terminal modes
996
997Name | Description
998-------------- | ------------
999VINTR | Interrupt character; 255 if none. Similarly for the other characters. Not all of these characters are supported on all systems.
1000VQUIT | The quit character (sends SIGQUIT signal on POSIX systems).
1001VERASE | Erase the character to left of the cursor.
1002VKILL | Kill the current input line.
1003VEOF | End-of-file character (sends EOF from the terminal).
1004VEOL | End-of-line character in addition to carriage return and/or linefeed.
1005VEOL2 | Additional end-of-line character.
1006VSTART | Continues paused output (normally control-Q).
1007VSTOP | Pauses output (normally control-S).
1008VSUSP | Suspends the current program.
1009VDSUSP | Another suspend character.
1010VREPRINT | Reprints the current input line.
1011VWERASE | Erases a word left of cursor.
1012VLNEXT | Enter the next character typed literally, even if it is a special character
1013VFLUSH | Character to flush output.
1014VSWTCH | Switch to a different shell layer.
1015VSTATUS | Prints system status line (load, command, pid, etc).
1016VDISCARD | Toggles the flushing of terminal output.
1017IGNPAR | The ignore parity flag. The parameter SHOULD be 0 if this flag is FALSE, and 1 if it is TRUE.
1018PARMRK | Mark parity and framing errors.
1019INPCK | Enable checking of parity errors.
1020ISTRIP | Strip 8th bit off characters.
1021INLCR | Map NL into CR on input.
1022IGNCR | Ignore CR on input.
1023ICRNL | Map CR to NL on input.
1024IUCLC | Translate uppercase characters to lowercase.
1025IXON | Enable output flow control.
1026IXANY | Any char will restart after stop.
1027IXOFF | Enable input flow control.
1028IMAXBEL | Ring bell on input queue full.
1029ISIG | Enable signals INTR, QUIT, [D]SUSP.
1030ICANON | Canonicalize input lines.
1031XCASE | Enable input and output of uppercase characters by preceding their lowercase equivalents with "\".
1032ECHO | Enable echoing.
1033ECHOE | Visually erase chars.
1034ECHOK | Kill character discards current line.
1035ECHONL | Echo NL even if ECHO is off.
1036NOFLSH | Don't flush after interrupt.
1037TOSTOP | Stop background jobs from output.
1038IEXTEN | Enable extensions.
1039ECHOCTL | Echo control characters as ^(Char).
1040ECHOKE | Visual erase for line kill.
1041PENDIN | Retype pending input.
1042OPOST | Enable output processing.
1043OLCUC | Convert lowercase to uppercase.
1044ONLCR | Map NL to CR-NL.
1045OCRNL | Translate carriage return to newline (output).
1046ONOCR | Translate newline to carriage return-newline (output).
1047ONLRET | Newline performs a carriage return (output).
1048CS7 | 7 bit mode.
1049CS8 | 8 bit mode.
1050PARENB | Parity enable.
1051PARODD | Odd parity, else even.
1052TTY_OP_ISPEED | Specifies the input baud rate in bits per second.
1053TTY_OP_OSPEED | Specifies the output baud rate in bits per second.