}` for encrypted private keys. (**Required**) **Default:** (none)
* **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:
* **kex** - _array_ - Key exchange algorithms.
* **cipher** - _array_ - Ciphers.
* **serverHostKey** - _array_ - Server host key formats.
* **hmac** - _array_ - (H)MAC algorithms.
* **compress** - _array_ - Compression algorithms.
* **greeting** - _string_ - A message that is sent to clients immediately upon connection, before handshaking begins. **Note:** Most clients usually ignore this. **Default:** (none)
* **banner** - _string_ - A message that is sent to clients once, right before authentication begins. **Default:** (none)
* **ident** - _string_ - A custom server software name/version identifier. **Default:** `'ssh2js' + moduleVersion + 'srv'`
* **highWaterMark** - _integer_ - This is the `highWaterMark` to use for the parser stream. **Default:** `32 * 1024`
* **debug** - _function_ - Set this to a function that receives a single string argument to get detailed (local) debug information. **Default:** (none)
Connection events
-----------------
* **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:
* `password`:
* **password** - _string_ - This is the password sent by the client.
* `publickey`:
* **key** - _object_ - Contains information about the public key sent by the client:
* **algo** - _string_ - The name of the key algorithm (e.g. `ssh-rsa`).
* **data** - _Buffer_ - The actual key data.
* **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).
* **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).
* **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).
* `keyboard-interactive`:
* **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.
* **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`.
* **ready**() - Emitted when the client has been successfully authenticated.
* **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.
* **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:
* **srcIP** - _string_ - Source IP address of outgoing connection.
* **srcPort** - _string_ - Source port of outgoing connection.
* **destIP** - _string_ - Destination IP address of outgoing connection.
* **destPort** - _string_ - Destination port of outgoing connection.
* **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:
* **socketPath** - _string_ - Destination socket path of outgoing connection.
* **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:
* `tcpip-forward` and `cancel-tcpip-forward`:
* **bindAddr** - _string_ - The IP address to start/stop binding to.
* **bindPort** - _integer_ - The port to start/stop binding to.
* `streamlocal-forward@openssh.com` and `cancel-streamlocal-forward@openssh.com`:
* **socketPath** - _string_ - The socket path to start/stop binding to.
* **rekey**() - Emitted when the client has finished rekeying (either client or server initiated).
* **continue**() - Emitted when more requests/data can be sent to the client (after a `Connection` method returned `false`).
* **error**(< _Error_ >err) - An error occurred.
* **end**() - The client socket disconnected.
* **close**(< _boolean_ >hadError) - The client socket was closed. `hadError` is set to `true` if this was due to error.
Connection methods
------------------
* **end**() - _boolean_ - Closes the client connection. Returns `false` if you should wait for the `continue` event before sending any more traffic.
* **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.
* **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.
* **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.
* **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.
Session events
--------------
* **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:
* **cols** - _integer_ - The number of columns for the pseudo-TTY.
* **rows** - _integer_ - The number of rows for the pseudo-TTY.
* **width** - _integer_ - The width of the pseudo-TTY in pixels.
* **height** - _integer_ - The height of the pseudo-TTY in pixels.
* **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).
* **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:
* **cols** - _integer_ - The new number of columns for the client window.
* **rows** - _integer_ - The new number of rows for the client window.
* **width** - _integer_ - The new width of the client window in pixels.
* **height** - _integer_ - The new height of the client window in pixels.
* **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:
* **single** - _boolean_ - `true` if only a single connection should be forwarded.
* **protocol** - _string_ - The name of the X11 authentication method used (e.g. `MIT-MAGIC-COOKIE-1`).
* **cookie** - _string_ - The X11 authentication cookie encoded in hexadecimal.
* **screen** - _integer_ - The screen number to forward X11 connections for.
* **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:
* **key** - _string_ - The environment variable's name.
* **value** - _string_ - The environment variable's value.
* **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:
* **name** - _string_ - The signal name (e.g. `SIGUSR1`).
* **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.
* **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.
* **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:
* **command** - _string_ - The command line to be executed.
* **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:
* **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:
* **name** - _string_ - The name of the subsystem.
* **close**() - The session was closed.
Channel
-------
This is a normal **streams2** Duplex Stream, with the following changes:
* 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`.
* A `close` event is emitted once the channel is completely closed on both the client and server.
* Client-only:
* For exec():
* 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.
* If there was an `exit` event, the `close` event will be passed the same arguments for convenience.
* For shell() and exec():
* The readable side represents stdout and the writable side represents stdin.
* A `stderr` property contains a Readable stream that represents output from stderr.
* **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.
* **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.
* Server-only:
* 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:
* **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.
* **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.
* For exec and shell-enabled channel instances, `channel.stderr` is a writable stream.
Pseudo-TTY settings
-------------------
* **rows** - < _integer_ > - Number of rows **Default:** `24`
* **cols** - < _integer_ > - Number of columns **Default:** `80`
* **height** - < _integer_ > - Height in pixels **Default:** `480`
* **width** - < _integer_ > - Width in pixels **Default:** `640`
* **term** - < _string_ > - The value to use for $TERM **Default:** `'vt100'`
`rows` and `cols` override `width` and `height` when `rows` and `cols` are non-zero.
Pixel dimensions refer to the drawable area of the window.
Zero dimension parameters are ignored.
Terminal modes
--------------
Name Description
------------------------------------------------------------
VINTR Interrupt character; 255 if none. Similarly
for the other characters. Not all of these
characters are supported on all systems.
VQUIT The quit character (sends SIGQUIT signal on
POSIX systems).
VERASE Erase the character to left of the cursor.
VKILL Kill the current input line.
VEOF End-of-file character (sends EOF from the
terminal).
VEOL End-of-line character in addition to
carriage return and/or linefeed.
VEOL2 Additional end-of-line character.
VSTART Continues paused output (normally
control-Q).
VSTOP Pauses output (normally control-S).
VSUSP Suspends the current program.
VDSUSP Another suspend character.
VREPRINT Reprints the current input line.
VWERASE Erases a word left of cursor.
VLNEXT Enter the next character typed literally,
even if it is a special character
VFLUSH Character to flush output.
VSWTCH Switch to a different shell layer.
VSTATUS Prints system status line (load, command,
pid, etc).
VDISCARD Toggles the flushing of terminal output.
IGNPAR The ignore parity flag. The parameter
SHOULD be 0 if this flag is FALSE,
and 1 if it is TRUE.
PARMRK Mark parity and framing errors.
INPCK Enable checking of parity errors.
ISTRIP Strip 8th bit off characters.
INLCR Map NL into CR on input.
IGNCR Ignore CR on input.
ICRNL Map CR to NL on input.
IUCLC Translate uppercase characters to
lowercase.
IXON Enable output flow control.
IXANY Any char will restart after stop.
IXOFF Enable input flow control.
IMAXBEL Ring bell on input queue full.
ISIG Enable signals INTR, QUIT, [D]SUSP.
ICANON Canonicalize input lines.
XCASE Enable input and output of uppercase
characters by preceding their lowercase
equivalents with "\".
ECHO Enable echoing.
ECHOE Visually erase chars.
ECHOK Kill character discards current line.
ECHONL Echo NL even if ECHO is off.
NOFLSH Don't flush after interrupt.
TOSTOP Stop background jobs from output.
IEXTEN Enable extensions.
ECHOCTL Echo control characters as ^(Char).
ECHOKE Visual erase for line kill.
PENDIN Retype pending input.
OPOST Enable output processing.
OLCUC Convert lowercase to uppercase.
ONLCR Map NL to CR-NL.
OCRNL Translate carriage return to newline
(output).
ONOCR Translate newline to carriage
return-newline (output).
ONLRET Newline performs a carriage return
(output).
CS7 7 bit mode.
CS8 8 bit mode.
PARENB Parity enable.
PARODD Odd parity, else even.
TTY_OP_ISPEED Specifies the input baud rate in
bits per second.
TTY_OP_OSPEED Specifies the output baud rate in
bits per second.