SSH: Running Commands
Summary
This page describes the process this plugin uses to:
- Run SSH commands
- Interpret prompts
- Clean & return command output
Starting the Session
When the session starts, PPA waits to see the command prompt (line 15).
It uses the base_prompt
expression in the SSH Server dictionary to do this.
Wait for Initial Prompt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Base Prompt
See the SSHPasswordAuth & SSHKeyAuth dictionaries for more information on base_prompt.
Running Commands
Once the opening prompt is found, commands are run using the following process.
Each step references a line number from the example.
- Type a command and run it (line 1)
- Any questions prompted by the command are answered (line 2)
- The command is complete when the
base_prompt
expression is found (line 14)
Steps 1-3 are repeated when running multiple commands.
Running Commands
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Getting Command Output
Anything seen before the prompt, excluding questions, is the command output.
Output from Command
total 36K
4.0K drwxr-xr-x 5 ubuntu ubuntu 4.0K Mar 20 13:00 .
4.0K drwxr-xr-x 4 root root 4.0K Apr 16 07:01 ..
4.0K -rw------- 1 ubuntu ubuntu 3.4K Apr 16 11:21 .bash_history
4.0K -rw-r--r-- 1 ubuntu ubuntu 220 Apr 4 2018 .bash_logout
4.0K -rw-r--r-- 1 ubuntu ubuntu 3.7K Apr 4 2018 .bashrc
4.0K drwx------ 2 ubuntu ubuntu 4.0K Feb 6 10:59 .cache
4.0K drwx------ 3 ubuntu ubuntu 4.0K Feb 6 10:59 .gnupg
4.0K -rw-r--r-- 1 ubuntu ubuntu 807 Apr 4 2018 .profile
4.0K drwx------ 2 ubuntu ubuntu 4.0K Feb 6 10:52 .ssh
0 -rw-r--r-- 1 ubuntu ubuntu 0 Feb 6 12:11 .sudo_as_admin_successful
Sanitising Command Output
Cleaning Sensitive Data
Characters sent over SSH are echoed back to the client automatically.
Leaving the command in the output can expose sensitive information.
This plugin will remove any occurrence of the issued command from the output.
Exceptions
Terminal size may change the response, making it impossible to find & remove the command.
Most cases are caused by line wrapping when a command is longer than the terminal width.
You can avoid this issue by using run_commands & setting terminal width.
Terminal Width - Ubuntu
1 2 3 |
|
Terminal Width - Cisco
1 2 3 |
|