Previous Topic: new-comObject Command--Instantiate a COM Object (Funclet)Next Topic: new-webService Command--Create a Web Service Object (Funclet)


new-SSHSession Command--Create a new Secure SSH Session (Funclet)

The new-SSHSession command creates a session on an SSH server and returns a CASSHELL object that represents the session. This object must be saved to perform any future action on the session. This command is typically used with the run-SSHCommand or run-SSHShell commands.

The command has the following syntax:

new-SSHSession -host hostname [-user username] [-pass password] [-key key] 
[-prompt prompt][-port portnumber]
-host hostname

The name of the SSH server.

-user username

(Optional) Specifies the user name to use to log in to the remote node. A user name is required when either password or public key authentication is used. If no user name is specified, the user name entered during AutoShell login is used. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$User

-pass password

(Optional) Specifies password to use to log in to the remote node. If no password is specified, the password entered during AutoShell login is used. To enter a hidden password after issuing this command, specify PW_GET() with an optional prompt as argument. unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$Pass

-key key

(Optional) Specifies an absolute or relative path to a file containing a private RSA key to use to log in to the remote node. If a private key and password are specified, AutoShell attempts a public key logon first, and if that fails, a password logon. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses. This parameter is only required when creating an SSH session on the fly using public key authentication.

Default: ""

-prompt prompt

(Optional) Specifies the fixed portion at the end of the prompt string displayed by the SSH server to indicate it is ready for input (for example: "::->" for AutoShell). This information is required to determine the completion of commands executed during the SSH session. Specify as many fixed characters as possible. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: "::->"

-port portnumber

(Optional) Port on which to connect to the target system.

Default: SSH standard port 22.

Return value

Returns a CASSHELL object. This object can be passed to the run-SSHCommand funclet to execute commands or to run-SSHSession to run an interactive session on the SSH server.

Example

Create an SSH session, assuming the server has AutoShell configured as SSH shell for the specified account. Run a command and disconnect:

ssh=new-SSHSession -host client8 -user bob -pass xyz42 -prompt ::->
? run-SSHCommand -session ssh -command "! ver"
ssh.disconnect();

See also:

run-SSHCommand Command--Run a Remote Command Through SSH (Funclet)

run-SSHShell Command--Run an Interactive SSH Command Line (Funclet)