ssh2shell 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,37 +6,37 @@ Ssh2shell uses [ssh2](https://www.npmjs.org/package/ssh2) to open a ssh shell se
|
|
|
6
6
|
|
|
7
7
|
Index:
|
|
8
8
|
------------
|
|
9
|
-
* [Instalation](#installation)
|
|
10
|
-
* [Minimal Example](#minimal-example)
|
|
11
|
-
* [Host Configuration](#host-configuration)
|
|
12
|
-
* [ssh2shell API](#ssh2shell-api)
|
|
13
|
-
* [
|
|
14
|
-
* [Authentication](#authentication)
|
|
15
|
-
* [Default Cyphers](#default-cyphers)
|
|
16
|
-
* [Fingerprint Validation](#fingerprint-validation)
|
|
17
|
-
* [Keyboard-interactive](#keyboard-interactive)
|
|
18
|
-
* [Trouble shooting](#trouble-shooting)
|
|
19
|
-
* [Verbose and Debug](#verbose-and-debug)
|
|
20
|
-
* [Notification commands](#notification-commands)
|
|
21
|
-
* [Sudo and su Commands](#sudo-and-su-commands)
|
|
22
|
-
* [Prompt detection override](#prompt-detection-override)
|
|
23
|
-
* [Text regular expression filters](#text-regular-expression-filters)
|
|
24
|
-
* [Responding to non-standard command prompts](#responding-to-non-standard-command-prompts)
|
|
25
|
-
* [Command Time-out event](#command-time-out-event)
|
|
26
|
-
* [Multiple Primary Hosts](#multiple-primary-hosts)
|
|
27
|
-
* [Tunnelling nested host objects](#tunnelling-nested-host-objects)
|
|
28
|
-
* [Event Handlers](#event-handlers)
|
|
29
|
-
* [Bash scripts on the fly](#bash-scripts-on-the-fly)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Installation:
|
|
9
|
+
* [Instalation](#installation-)
|
|
10
|
+
* [Minimal Example](#minimal-example-)
|
|
11
|
+
* [Host Configuration](#host-configuration-)
|
|
12
|
+
* [ssh2shell API](#ssh2shell-api-)
|
|
13
|
+
* [Usage](#usage-)
|
|
14
|
+
* [Authentication](#authentication-)
|
|
15
|
+
* [Default Cyphers](#default-cyphers-)
|
|
16
|
+
* [Fingerprint Validation](#fingerprint-validation-)
|
|
17
|
+
* [Keyboard-interactive](#keyboard-interactive-)
|
|
18
|
+
* [Trouble shooting](#trouble-shooting-)
|
|
19
|
+
* [Verbose and Debug](#verbose-and-debug-)
|
|
20
|
+
* [Notification commands](#notification-commands-)
|
|
21
|
+
* [Sudo and su Commands](#sudo-and-su-commands-)
|
|
22
|
+
* [Prompt detection override](#prompt-detection-override-)
|
|
23
|
+
* [Text regular expression filters](#text-regular-expression-filters-)
|
|
24
|
+
* [Responding to non-standard command prompts](#responding-to-non-standard-command-prompts-)
|
|
25
|
+
* [Command Time-out event](#command-time-out-event-)
|
|
26
|
+
* [Multiple Primary Hosts](#multiple-primary-hosts-)
|
|
27
|
+
* [Tunnelling nested host objects](#tunnelling-nested-host-objects-)
|
|
28
|
+
* [Event Handlers](#event-handlers-)
|
|
29
|
+
* [Bash scripts on the fly](#bash-scripts-on-the-fly-)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[Installation: ^](#index)
|
|
33
33
|
------------
|
|
34
34
|
```
|
|
35
35
|
npm install ssh2shell
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
Minimal Example:
|
|
39
|
+
[Minimal Example: ^](#index)
|
|
40
40
|
------------
|
|
41
41
|
```javascript
|
|
42
42
|
//host configuration with connection settings and commands
|
|
@@ -60,7 +60,7 @@ SSH.connect(callback);
|
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
Host Configuration:
|
|
63
|
+
[Host Configuration: ^](#index)
|
|
64
64
|
------------
|
|
65
65
|
SSH2Shell requires an object with the following structure:
|
|
66
66
|
```javascript
|
|
@@ -217,7 +217,7 @@ host = {
|
|
|
217
217
|
variables and the current array of commands for the host. The sshObj.commands array changes with each host connection.
|
|
218
218
|
|
|
219
219
|
|
|
220
|
-
ssh2shell API
|
|
220
|
+
[ssh2shell API: ^](#index)
|
|
221
221
|
-------------
|
|
222
222
|
SSH2Shell extends events.EventEmitter
|
|
223
223
|
|
|
@@ -240,11 +240,9 @@ SSH2Shell extends events.EventEmitter
|
|
|
240
240
|
* .command is the current command being run until a new prompt is detected and the next command replaces it.
|
|
241
241
|
|
|
242
242
|
|
|
243
|
-
Usage:
|
|
244
|
-
|
|
245
|
-
Connecting to a single host
|
|
246
|
-
----------------------------
|
|
247
|
-
|
|
243
|
+
[Usage: ^](#index)
|
|
244
|
+
--------
|
|
245
|
+
*Connecting to a single host*
|
|
248
246
|
|
|
249
247
|
*app.js*
|
|
250
248
|
```javascript
|
|
@@ -274,7 +272,7 @@ SSH.connect(callback);
|
|
|
274
272
|
```
|
|
275
273
|
|
|
276
274
|
|
|
277
|
-
Authentication:
|
|
275
|
+
[Authentication: ^](#index)
|
|
278
276
|
---------------
|
|
279
277
|
* Each host authenticates with its own host.server parameters.
|
|
280
278
|
* When using key authentication you may require a valid pass phrase if your key was created with one.
|
|
@@ -284,7 +282,7 @@ Authentication:
|
|
|
284
282
|
function...) or host.onKeyboardInteractive() must be defined.
|
|
285
283
|
* Set the default cyphers and keys.
|
|
286
284
|
|
|
287
|
-
Default Cyphers:
|
|
285
|
+
[Default Cyphers: ^](#index)
|
|
288
286
|
---------------
|
|
289
287
|
Default Cyphers and Keys used in the initial ssh connection can be redefined by setting the ssh2.connect.algorithms through the host.server.algorithms option.
|
|
290
288
|
As with this property all ssh2.connect properties are set in the host.server object.
|
|
@@ -324,7 +322,7 @@ var host = {
|
|
|
324
322
|
}
|
|
325
323
|
```
|
|
326
324
|
|
|
327
|
-
Fingerprint Validation:
|
|
325
|
+
[Fingerprint Validation: ^](#index)
|
|
328
326
|
---------------
|
|
329
327
|
At connection time the hash of the server’s public key can be compared with the hash the client had previously recorded
|
|
330
328
|
for that server. This stops "man in the middle" attacks where you are redirected to a different server as you connect
|
|
@@ -392,14 +390,14 @@ host.server.hashMethod only supports md5 or sha1 according to the current SSH2 d
|
|
|
392
390
|
undesired results.__
|
|
393
391
|
|
|
394
392
|
|
|
395
|
-
Keyboard-interactive
|
|
393
|
+
[Keyboard-interactive: ^](#index)
|
|
396
394
|
----------------------
|
|
397
395
|
Keyboard-interactive authentication is available when both host.server.tryKeyboard is set to true and the event handler
|
|
398
396
|
keyboard-interactive is defined as below. The keyboard-interactive event handler can only be used on the first connection.
|
|
399
397
|
|
|
400
398
|
Also see [test/keyboard-interactivetest.js](https://github.com/cmp-202/ssh2shell/blob/master/test/keyboard-interactivetest.js) for the full example
|
|
401
399
|
|
|
402
|
-
*Defining the event handler
|
|
400
|
+
*Defining the event handler*
|
|
403
401
|
```javascript
|
|
404
402
|
//this is required
|
|
405
403
|
host.server.tryKeyboard = true;
|
|
@@ -446,7 +444,7 @@ host = {
|
|
|
446
444
|
```
|
|
447
445
|
|
|
448
446
|
|
|
449
|
-
Trouble shooting:
|
|
447
|
+
[Trouble shooting: ^](#index)
|
|
450
448
|
-----------------
|
|
451
449
|
|
|
452
450
|
* Adding msg command `"msg:Doing something"` to your commands array at key points will help you track the sequence of
|
|
@@ -466,7 +464,7 @@ Trouble shooting:
|
|
|
466
464
|
(1000 = 1 sec)
|
|
467
465
|
|
|
468
466
|
|
|
469
|
-
Verbose and Debug:
|
|
467
|
+
[Verbose and Debug: ^](#index)
|
|
470
468
|
------------------
|
|
471
469
|
* When host.verbose is set to true each command complete raises a msg event outputting the response text.
|
|
472
470
|
* When host.debug is set to true each process step raises a msg event to help identify what the internal processes were.
|
|
@@ -480,7 +478,7 @@ Add your own verbose messages as follows:
|
|
|
480
478
|
Add your own debug messages as follows:
|
|
481
479
|
`if(this.sshObj.debug){this.emit("msg", this.sshObj.server.host + ": eventName");} //where eventName is the text identifying what happened`
|
|
482
480
|
|
|
483
|
-
Notification commands:
|
|
481
|
+
[Notification commands: ^](#index)
|
|
484
482
|
----------------------
|
|
485
483
|
There are two notification commands that are added to the host.commands array but are not run as a command on the host.
|
|
486
484
|
|
|
@@ -489,7 +487,7 @@ There are two notification commands that are added to the host.commands array bu
|
|
|
489
487
|
* The reason for not using echo or printf commands as a normal command is that you see both the command and the message in the sessionText which is pointless when all you want is the message.
|
|
490
488
|
|
|
491
489
|
|
|
492
|
-
Sudo and su Commands:
|
|
490
|
+
[Sudo and su Commands: ^](#index)
|
|
493
491
|
--------------
|
|
494
492
|
It is possible to use `sudo [command]`, `sudo su`, `su [username]` and `sudo -u [username] -i`.
|
|
495
493
|
Sudo commands uses the password for the current session and is processed by ssh2shell. Su on the other hand uses the password
|
|
@@ -501,7 +499,7 @@ See: [su VS sudo su VS sudo -u -i](http://johnkpaul.tumblr.com/post/19841381351/
|
|
|
501
499
|
See: [test/sudosutest.js](https://github.com/cmp-202/ssh2shell/blob/master/test/sudosutest.js) for a working code example.
|
|
502
500
|
|
|
503
501
|
|
|
504
|
-
Prompt detection override:
|
|
502
|
+
[Prompt detection override: ^](#index)
|
|
505
503
|
-------------------------
|
|
506
504
|
Used to detect different prompts.
|
|
507
505
|
|
|
@@ -513,7 +511,7 @@ These are optional settings.
|
|
|
513
511
|
```
|
|
514
512
|
|
|
515
513
|
|
|
516
|
-
Text regular expression filters:
|
|
514
|
+
[Text regular expression filters: ^](#index)
|
|
517
515
|
-------------------------------
|
|
518
516
|
There are two regular expression filters that remove unwanted text from response data.
|
|
519
517
|
|
|
@@ -528,7 +526,7 @@ host.textColorFilter = "(\[{1}[0-9;]+m{1})"
|
|
|
528
526
|
```
|
|
529
527
|
|
|
530
528
|
|
|
531
|
-
Responding to non-standard command prompts:
|
|
529
|
+
[Responding to non-standard command prompts: ^](#index)
|
|
532
530
|
----------------------
|
|
533
531
|
In host.onCommandProcessing event handler the prompt can be detected and a response can be sent via `stream.write("y\n")`.
|
|
534
532
|
|
|
@@ -568,7 +566,7 @@ __*Note:*
|
|
|
568
566
|
If no prompt is detected `commandTimeout` will be raised after the idleTimeOut period.__
|
|
569
567
|
|
|
570
568
|
|
|
571
|
-
Command Time-out event
|
|
569
|
+
[Command Time-out event: ^](#index)
|
|
572
570
|
---------------
|
|
573
571
|
When onCommandTimeout event triggers after the host.idleTimeOut is exceeded.
|
|
574
572
|
This is because there is no new data and no prompt is detected to run the next command.
|
|
@@ -637,7 +635,7 @@ SSH.connect();
|
|
|
637
635
|
```
|
|
638
636
|
|
|
639
637
|
|
|
640
|
-
Multiple Primary Hosts:
|
|
638
|
+
[Multiple Primary Hosts: ^](#index)
|
|
641
639
|
-----------------------
|
|
642
640
|
Multiple hosts can be connected to one after the other as you would connecting to a single host.
|
|
643
641
|
Each host config is independant of each other but can share thingsa like commands and handlers.
|
|
@@ -709,7 +707,7 @@ SSH.connect(callback);
|
|
|
709
707
|
```
|
|
710
708
|
|
|
711
709
|
|
|
712
|
-
Tunnelling nested host objects:
|
|
710
|
+
[Tunnelling nested host objects: ^](#index)
|
|
713
711
|
---------------------------------
|
|
714
712
|
`hosts: [ host1, host2]` setting can make multiple host connections possible.
|
|
715
713
|
Each host config object has its own server settings, commands, command handlers and
|
|
@@ -918,7 +916,7 @@ SSH.connect();
|
|
|
918
916
|
```
|
|
919
917
|
|
|
920
918
|
|
|
921
|
-
Event Handlers:
|
|
919
|
+
[Event Handlers: ^](#index)
|
|
922
920
|
---------------
|
|
923
921
|
There are a number of event handlers that enable you to add your own code to be run when those events are triggered.
|
|
924
922
|
Most of these you have already encountered in the host object. You do not have to add event handlers unless you want
|
|
@@ -1038,7 +1036,7 @@ ssh2shell.on ("Unpipe", function onUnpipe(source){
|
|
|
1038
1036
|
});
|
|
1039
1037
|
```
|
|
1040
1038
|
|
|
1041
|
-
Bash scripts on the fly:
|
|
1039
|
+
[Bash scripts on the fly: ^](#index)
|
|
1042
1040
|
------------------------
|
|
1043
1041
|
If the commands you need to run would be better suited to a bash script as part of the process it is possible to generate
|
|
1044
1042
|
or get the script on the fly. You can echo/printf the script content into a file as a command, ensure it is executable,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2shell",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"author": "cmp-202",
|
|
5
5
|
"description": "A wrapper class for ssh2 to run multiple sequential commands in an SSH shell session, handle command responses, and tunnel through to other hosts using nested host objects",
|
|
6
6
|
"main": "./lib/ssh2shell.js",
|