UNPKG

52.7 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[Changes from v0.4.x-v0.5.x](https://github.com/mscdex/ssh2/wiki/Changes-from-0.4.x-to-0.5.x)
8
9[![Build Status](https://travis-ci.org/mscdex/ssh2.svg?branch=master)](https://travis-ci.org/mscdex/ssh2)
10
11# Table of Contents
12
13* [Requirements](#requirements)
14* [Installation](#installation)
15* [Client Examples](#client-examples)
16 * [Execute `uptime` on a server](#execute-uptime-on-a-server)
17 * [Start an interactive shell session](#start-an-interactive-shell-session)
18 * [Send a raw HTTP request to port 80 on the server](#send-a-raw-http-request-to-port-80-on-the-server)
19 * [Forward local connections to port 8000 on the server to us](#forward-local-connections-to-port-8000-on-the-server-to-us)
20 * [Get a directory listing via SFTP](#get-a-directory-listing-via-sftp)
21 * [Connection hopping](#connection-hopping)
22 * [Forward remote X11 connections](#forward-remote-x11-connections)
23 * [Dynamic (1:1) port forwarding using a SOCKSv5 proxy (using `socksv5`)](#dynamic-11-port-forwarding-using-a-socksv5-proxy-using-socksv5)
24 * [Invoke an arbitrary subsystem (e.g. netconf)](#invoke-an-arbitrary-subsystem)
25* [Server Examples](#server-examples)
26 * [Password and public key authentication and non-interactive (exec) command execution](#password-and-public-key-authentication-and-non-interactive-exec-command-execution)
27 * [SFTP-only server](#sftp-only-server)
28* [API](#api)
29 * [Client](#client)
30 * [Client events](#client-events)
31 * [Client methods](#client-methods)
32 * [Server](#server)
33 * [Server events](#server-events)
34 * [Server methods](#server-methods)
35 * [Connection events](#connection-events)
36 * [Connection methods](#connection-methods)
37 * [Session events](#session-events)
38 * [Channel](#channel)
39 * [Pseudo-TTY settings](#pseudo-tty-settings)
40 * [Terminal modes](#terminal-modes)
41
42## Requirements
43
44* [node.js](http://nodejs.org/) -- v4.5.0 or newer
45
46## Installation
47
48 npm install ssh2
49
50## Client Examples
51
52### Execute `uptime` on a server
53
54```js
55var Client = require('ssh2').Client;
56
57var conn = new Client();
58conn.on('ready', function() {
59 console.log('Client :: ready');
60 conn.exec('uptime', function(err, stream) {
61 if (err) throw err;
62 stream.on('close', function(code, signal) {
63 console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
64 conn.end();
65 }).on('data', function(data) {
66 console.log('STDOUT: ' + data);
67 }).stderr.on('data', function(data) {
68 console.log('STDERR: ' + data);
69 });
70 });
71}).connect({
72 host: '192.168.100.100',
73 port: 22,
74 username: 'frylock',
75 privateKey: require('fs').readFileSync('/here/is/my/key')
76});
77
78// example output:
79// Client :: ready
80// STDOUT: 17:41:15 up 22 days, 18:09, 1 user, load average: 0.00, 0.01, 0.05
81//
82// Stream :: exit :: code: 0, signal: undefined
83// Stream :: close
84```
85
86### Start an interactive shell session
87
88```js
89var Client = require('ssh2').Client;
90
91var conn = new Client();
92conn.on('ready', function() {
93 console.log('Client :: ready');
94 conn.shell(function(err, stream) {
95 if (err) throw err;
96 stream.on('close', function() {
97 console.log('Stream :: close');
98 conn.end();
99 }).on('data', function(data) {
100 console.log('STDOUT: ' + data);
101 }).stderr.on('data', function(data) {
102 console.log('STDERR: ' + data);
103 });
104 stream.end('ls -l\nexit\n');
105 });
106}).connect({
107 host: '192.168.100.100',
108 port: 22,
109 username: 'frylock',
110 privateKey: require('fs').readFileSync('/here/is/my/key')
111});
112
113// example output:
114// Client :: ready
115// STDOUT: Last login: Sun Jun 15 09:37:21 2014 from 192.168.100.100
116//
117// STDOUT: ls -l
118// exit
119//
120// STDOUT: frylock@athf:~$ ls -l
121//
122// STDOUT: total 8
123//
124// STDOUT: drwxr-xr-x 2 frylock frylock 4096 Nov 18 2012 mydir
125//
126// STDOUT: -rw-r--r-- 1 frylock frylock 25 Apr 11 2013 test.txt
127//
128// STDOUT: frylock@athf:~$ exit
129//
130// STDOUT: logout
131//
132// Stream :: close
133```
134
135### Send a raw HTTP request to port 80 on the server
136
137```js
138var Client = require('ssh2').Client;
139
140var conn = new Client();
141conn.on('ready', function() {
142 console.log('Client :: ready');
143 conn.forwardOut('192.168.100.102', 8000, '127.0.0.1', 80, function(err, stream) {
144 if (err) throw err;
145 stream.on('close', function() {
146 console.log('TCP :: CLOSED');
147 conn.end();
148 }).on('data', function(data) {
149 console.log('TCP :: DATA: ' + data);
150 }).end([
151 'HEAD / HTTP/1.1',
152 'User-Agent: curl/7.27.0',
153 'Host: 127.0.0.1',
154 'Accept: */*',
155 'Connection: close',
156 '',
157 ''
158 ].join('\r\n'));
159 });
160}).connect({
161 host: '192.168.100.100',
162 port: 22,
163 username: 'frylock',
164 password: 'nodejsrules'
165});
166
167// example output:
168// Client :: ready
169// TCP :: DATA: HTTP/1.1 200 OK
170// Date: Thu, 15 Nov 2012 13:52:58 GMT
171// Server: Apache/2.2.22 (Ubuntu)
172// X-Powered-By: PHP/5.4.6-1ubuntu1
173// Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
174// Content-Encoding: gzip
175// Vary: Accept-Encoding
176// Connection: close
177// Content-Type: text/html; charset=UTF-8
178//
179//
180// TCP :: CLOSED
181```
182
183### Forward local connections to port 8000 on the server to us
184
185```js
186var Client = require('ssh2').Client;
187
188var conn = new Client();
189conn.on('ready', function() {
190 console.log('Client :: ready');
191 conn.forwardIn('127.0.0.1', 8000, function(err) {
192 if (err) throw err;
193 console.log('Listening for connections on server on port 8000!');
194 });
195}).on('tcp connection', function(info, accept, reject) {
196 console.log('TCP :: INCOMING CONNECTION:');
197 console.dir(info);
198 accept().on('close', function() {
199 console.log('TCP :: CLOSED');
200 }).on('data', function(data) {
201 console.log('TCP :: DATA: ' + data);
202 }).end([
203 'HTTP/1.1 404 Not Found',
204 'Date: Thu, 15 Nov 2012 02:07:58 GMT',
205 'Server: ForwardedConnection',
206 'Content-Length: 0',
207 'Connection: close',
208 '',
209 ''
210 ].join('\r\n'));
211}).connect({
212 host: '192.168.100.100',
213 port: 22,
214 username: 'frylock',
215 password: 'nodejsrules'
216});
217
218// example output:
219// Client :: ready
220// Listening for connections on server on port 8000!
221// (.... then from another terminal on the server: `curl -I http://127.0.0.1:8000`)
222// TCP :: INCOMING CONNECTION: { destIP: '127.0.0.1',
223// destPort: 8000,
224// srcIP: '127.0.0.1',
225// srcPort: 41969 }
226// TCP DATA: HEAD / HTTP/1.1
227// User-Agent: curl/7.27.0
228// Host: 127.0.0.1:8000
229// Accept: */*
230//
231//
232// TCP :: CLOSED
233```
234
235### Get a directory listing via SFTP
236
237```js
238var Client = require('ssh2').Client;
239
240var conn = new Client();
241conn.on('ready', function() {
242 console.log('Client :: ready');
243 conn.sftp(function(err, sftp) {
244 if (err) throw err;
245 sftp.readdir('foo', function(err, list) {
246 if (err) throw err;
247 console.dir(list);
248 conn.end();
249 });
250 });
251}).connect({
252 host: '192.168.100.100',
253 port: 22,
254 username: 'frylock',
255 password: 'nodejsrules'
256});
257
258// example output:
259// Client :: ready
260// [ { filename: 'test.txt',
261// longname: '-rw-r--r-- 1 frylock frylock 12 Nov 18 11:05 test.txt',
262// attrs:
263// { size: 12,
264// uid: 1000,
265// gid: 1000,
266// mode: 33188,
267// atime: 1353254750,
268// mtime: 1353254744 } },
269// { filename: 'mydir',
270// longname: 'drwxr-xr-x 2 frylock frylock 4096 Nov 18 15:03 mydir',
271// attrs:
272// { size: 1048576,
273// uid: 1000,
274// gid: 1000,
275// mode: 16877,
276// atime: 1353269007,
277// mtime: 1353269007 } } ]
278```
279
280### Connection hopping
281
282```js
283var Client = require('ssh2').Client;
284
285var conn1 = new Client();
286var conn2 = new Client();
287
288conn1.on('ready', function() {
289 console.log('FIRST :: connection ready');
290 conn1.exec('nc 192.168.1.2 22', function(err, stream) {
291 if (err) {
292 console.log('FIRST :: exec error: ' + err);
293 return conn1.end();
294 }
295 conn2.connect({
296 sock: stream,
297 username: 'user2',
298 password: 'password2',
299 });
300 });
301}).connect({
302 host: '192.168.1.1',
303 username: 'user1',
304 password: 'password1',
305});
306
307conn2.on('ready', function() {
308 console.log('SECOND :: connection ready');
309 conn2.exec('uptime', function(err, stream) {
310 if (err) {
311 console.log('SECOND :: exec error: ' + err);
312 return conn1.end();
313 }
314 stream.on('end', function() {
315 conn1.end(); // close parent (and this) connection
316 }).on('data', function(data) {
317 console.log(data.toString());
318 });
319 });
320});
321```
322
323### Forward remote X11 connections
324
325```js
326var net = require('net');
327
328var Client = require('ssh2').Client;
329
330var conn = new Client();
331
332conn.on('x11', function(info, accept, reject) {
333 var xserversock = new net.Socket();
334 xserversock.on('connect', function() {
335 var xclientsock = accept();
336 xclientsock.pipe(xserversock).pipe(xclientsock);
337 });
338 // connects to localhost:0.0
339 xserversock.connect(6000, 'localhost');
340});
341
342conn.on('ready', function() {
343 conn.exec('xeyes', { x11: true }, function(err, stream) {
344 if (err) throw err;
345 var code = 0;
346 stream.on('end', function() {
347 if (code !== 0)
348 console.log('Do you have X11 forwarding enabled on your SSH server?');
349 conn.end();
350 }).on('exit', function(exitcode) {
351 code = exitcode;
352 });
353 });
354}).connect({
355 host: '192.168.1.1',
356 username: 'foo',
357 password: 'bar'
358});
359```
360
361### Dynamic (1:1) port forwarding using a SOCKSv5 proxy (using [socksv5](https://github.com/mscdex/socksv5))
362
363```js
364var socks = require('socksv5');
365var Client = require('ssh2').Client;
366
367var ssh_config = {
368 host: '192.168.100.1',
369 port: 22,
370 username: 'nodejs',
371 password: 'rules'
372};
373
374socks.createServer(function(info, accept, deny) {
375 // NOTE: you could just use one ssh2 client connection for all forwards, but
376 // you could run into server-imposed limits if you have too many forwards open
377 // at any given time
378 var conn = new Client();
379 conn.on('ready', function() {
380 conn.forwardOut(info.srcAddr,
381 info.srcPort,
382 info.dstAddr,
383 info.dstPort,
384 function(err, stream) {
385 if (err) {
386 conn.end();
387 return deny();
388 }
389
390 var clientSocket;
391 if (clientSocket = accept(true)) {
392 stream.pipe(clientSocket).pipe(stream).on('close', function() {
393 conn.end();
394 });
395 } else
396 conn.end();
397 });
398 }).on('error', function(err) {
399 deny();
400 }).connect(ssh_config);
401}).listen(1080, 'localhost', function() {
402 console.log('SOCKSv5 proxy server started on port 1080');
403}).useAuth(socks.auth.None());
404
405// test with cURL:
406// curl -i --socks5 localhost:1080 google.com
407```
408
409### Invoke an arbitrary subsystem
410
411```js
412var Client = require('ssh2').Client;
413var xmlhello = '<?xml version="1.0" encoding="UTF-8"?>' +
414 '<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">' +
415 ' <capabilities>' +
416 ' <capability>urn:ietf:params:netconf:base:1.0</capability>' +
417 ' </capabilities>' +
418 '</hello>]]>]]>';
419
420var conn = new Client();
421
422conn.on('ready', function() {
423 console.log('Client :: ready');
424 conn.subsys('netconf', function(err, stream) {
425 if (err) throw err;
426 stream.on('data', function(data) {
427 console.log(data);
428 }).write(xmlhello);
429 });
430}).connect({
431 host: '1.2.3.4',
432 port: 22,
433 username: 'blargh',
434 password: 'honk'
435});
436```
437
438## Server Examples
439
440### Password and public key authentication and non-interactive (exec) command execution
441
442```js
443var fs = require('fs');
444var crypto = require('crypto');
445var inspect = require('util').inspect;
446
447var buffersEqual = require('buffer-equal-constant-time');
448var ssh2 = require('ssh2');
449var utils = ssh2.utils;
450
451var pubKey = utils.genPublicKey(utils.parseKey(fs.readFileSync('user.pub')));
452
453new ssh2.Server({
454 hostKeys: [fs.readFileSync('host.key')]
455}, function(client) {
456 console.log('Client connected!');
457
458 client.on('authentication', function(ctx) {
459 if (ctx.method === 'password'
460 // Note: Don't do this in production code, see
461 // https://www.brendanlong.com/timing-attacks-and-usernames.html
462 // In node v6.0.0+, you can use `crypto.timingSafeEqual()` to safely
463 // compare two values.
464 && ctx.username === 'foo'
465 && ctx.password === 'bar')
466 ctx.accept();
467 else if (ctx.method === 'publickey'
468 && ctx.key.algo === pubKey.fulltype
469 && buffersEqual(ctx.key.data, pubKey.public)) {
470 if (ctx.signature) {
471 var verifier = crypto.createVerify(ctx.sigAlgo);
472 verifier.update(ctx.blob);
473 if (verifier.verify(pubKey.publicOrig, ctx.signature))
474 ctx.accept();
475 else
476 ctx.reject();
477 } else {
478 // if no signature present, that means the client is just checking
479 // the validity of the given public key
480 ctx.accept();
481 }
482 } else
483 ctx.reject();
484 }).on('ready', function() {
485 console.log('Client authenticated!');
486
487 client.on('session', function(accept, reject) {
488 var session = accept();
489 session.once('exec', function(accept, reject, info) {
490 console.log('Client wants to execute: ' + inspect(info.command));
491 var stream = accept();
492 stream.stderr.write('Oh no, the dreaded errors!\n');
493 stream.write('Just kidding about the errors!\n');
494 stream.exit(0);
495 stream.end();
496 });
497 });
498 }).on('end', function() {
499 console.log('Client disconnected');
500 });
501}).listen(0, '127.0.0.1', function() {
502 console.log('Listening on port ' + this.address().port);
503});
504```
505
506### SFTP-only server
507
508```js
509var fs = require('fs');
510
511var ssh2 = require('ssh2');
512var OPEN_MODE = ssh2.SFTP_OPEN_MODE;
513var STATUS_CODE = ssh2.SFTP_STATUS_CODE;
514
515new ssh2.Server({
516 hostKeys: [fs.readFileSync('host.key')]
517}, function(client) {
518 console.log('Client connected!');
519
520 client.on('authentication', function(ctx) {
521 if (ctx.method === 'password'
522 // Note: Don't do this in production code, see
523 // https://www.brendanlong.com/timing-attacks-and-usernames.html
524 // In node v6.0.0+, you can use `crypto.timingSafeEqual()` to safely
525 // compare two values.
526 && ctx.username === 'foo'
527 && ctx.password === 'bar')
528 ctx.accept();
529 else
530 ctx.reject();
531 }).on('ready', function() {
532 console.log('Client authenticated!');
533
534 client.on('session', function(accept, reject) {
535 var session = accept();
536 session.on('sftp', function(accept, reject) {
537 console.log('Client SFTP session');
538 var openFiles = {};
539 var handleCount = 0;
540 // `sftpStream` is an `SFTPStream` instance in server mode
541 // see: https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md
542 var sftpStream = accept();
543 sftpStream.on('OPEN', function(reqid, filename, flags, attrs) {
544 // only allow opening /tmp/foo.txt for writing
545 if (filename !== '/tmp/foo.txt' || !(flags & OPEN_MODE.WRITE))
546 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
547 // create a fake handle to return to the client, this could easily
548 // be a real file descriptor number for example if actually opening
549 // the file on the disk
550 var handle = new Buffer(4);
551 openFiles[handleCount] = true;
552 handle.writeUInt32BE(handleCount++, 0, true);
553 sftpStream.handle(reqid, handle);
554 console.log('Opening file for write')
555 }).on('WRITE', function(reqid, handle, offset, data) {
556 if (handle.length !== 4 || !openFiles[handle.readUInt32BE(0, true)])
557 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
558 // fake the write
559 sftpStream.status(reqid, STATUS_CODE.OK);
560 var inspected = require('util').inspect(data);
561 console.log('Write to file at offset %d: %s', offset, inspected);
562 }).on('CLOSE', function(reqid, handle) {
563 var fnum;
564 if (handle.length !== 4 || !openFiles[(fnum = handle.readUInt32BE(0, true))])
565 return sftpStream.status(reqid, STATUS_CODE.FAILURE);
566 delete openFiles[fnum];
567 sftpStream.status(reqid, STATUS_CODE.OK);
568 console.log('Closing file');
569 });
570 });
571 });
572 }).on('end', function() {
573 console.log('Client disconnected');
574 });
575}).listen(0, '127.0.0.1', function() {
576 console.log('Listening on port ' + this.address().port);
577});
578```
579
580You can find more examples in the `examples` directory of this repository.
581
582## API
583
584`require('ssh2').Client` returns a **_Client_** constructor.
585
586`require('ssh2').Server` returns a **_Server_** constructor.
587
588`require('ssh2').utils` returns the [utility methods from `ssh2-streams`](https://github.com/mscdex/ssh2-streams#utility-methods).
589
590`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).
591
592`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).
593
594### Client
595
596#### Client events
597
598* **banner**(< _string_ >message, < _string_ >language) - A notice was sent by the server upon connection.
599
600* **ready**() - Authentication was successful.
601
602* **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:
603
604 * **srcIP** - _string_ - The originating IP of the connection.
605
606 * **srcPort** - _integer_ - The originating port of the connection.
607
608 * **destIP** - _string_ - The remote IP the connection was received on (given in earlier call to `forwardIn()`).
609
610 * **destPort** - _integer_ - The remote port the connection was received on (given in earlier call to `forwardIn()`).
611
612* **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:
613
614 * **srcIP** - _string_ - The originating IP of the connection.
615
616 * **srcPort** - _integer_ - The originating port of the connection.
617
618* **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.
619
620* **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:
621
622 * **socketPath** - _string_ - The originating UNIX socket path of the connection.
623
624* **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.
625
626* **continue**() - Emitted when more requests/data can be sent to the server (after a `Client` method returned `false`).
627
628* **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.
629
630* **end**() - The socket was disconnected.
631
632* **close**(< _boolean_ >hadError) - The socket was closed. `hadError` is set to `true` if this was due to error.
633
634#### Client methods
635
636* **(constructor)**() - Creates and returns a new Client instance.
637
638* **connect**(< _object_ >config) - _(void)_ - Attempts a connection to a server using the information given in `config`:
639
640 * **host** - _string_ - Hostname or IP address of the server. **Default:** `'localhost'`
641
642 * **port** - _integer_ - Port number of the server. **Default:** `22`
643
644 * **forceIPv4** - _boolean_ - Only connect via resolved IPv4 address for `host`. **Default:** `false`
645
646 * **forceIPv6** - _boolean_ - Only connect via resolved IPv6 address for `host`. **Default:** `false`
647
648 * **hostHash** - _string_ - 'md5' or 'sha1'. The host's key is hashed using this method and passed to the **hostVerifier** function. **Default:** (none)
649
650 * **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)
651
652 * **username** - _string_ - Username for authentication. **Default:** (none)
653
654 * **password** - _string_ - Password for password-based user authentication. **Default:** (none)
655
656 * **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)
657
658 * **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`
659
660 * **privateKey** - _mixed_ - _Buffer_ or _string_ that contains a private key for either key-based or hostbased user authentication (OpenSSH format). **Default:** (none)
661
662 * **passphrase** - _string_ - For an encrypted private key, this is the passphrase used to decrypt it. **Default:** (none)
663
664 * **localHostname** - _string_ - Along with **localUsername** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
665
666 * **localUsername** - _string_ - Along with **localHostname** and **privateKey**, set this to a non-empty string for hostbased user authentication. **Default:** (none)
667
668 * **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`
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**Authentication method priorities:** 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.