Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Shell

Index

Properties

Static Readonly connRefusedFlag

connRefusedFlag: "ECONNREFUSED" = "ECONNREFUSED"

Static Readonly expiredPasswordFlag

expiredPasswordFlag: "FOTS1668" = "FOTS1668"

Static Readonly startCmdFlag

startCmdFlag: "@@START OF COMMAND@@" = "@@START OF COMMAND@@"

Methods

Static Private authenticationHandler

  • authenticationHandler(authsAllowed: string[]): (Anonymous function)

Static Private connect

  • connect(connection: Client, session: SshSession, connState?: IConnectionState): void

Static executeExec

  • executeExec(session: SshSession, command: string, stdoutHandler: (data: string) => void): Promise<number>
  • Execute a command using exec mode (no shell wrapping, faster)

    Parameters

    • session: SshSession

      SSH session

    • command: string

      Command to execute

    • stdoutHandler: (data: string) => void

      Handler for stdout data

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    Returns Promise<number>

    Promise with exit code

Static executeExecCwd

  • executeExecCwd(session: SshSession, command: string, cwd: string, stdoutHandler: (data: string) => void): Promise<number>
  • Execute a command in a specific directory using exec mode

    Parameters

    • session: SshSession

      SSH session

    • command: string

      Command to execute

    • cwd: string

      Working directory

    • stdoutHandler: (data: string) => void

      Handler for stdout data

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    Returns Promise<number>

    Promise with exit code

Static executeSsh

  • executeSsh(session: SshSession, command: string, stdoutHandler: (data: string) => void, removeExtraCharactersFromOutput?: boolean, useExecMode?: boolean): Promise<any>
  • Parameters

    • session: SshSession
    • command: string
    • stdoutHandler: (data: string) => void
        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Default value removeExtraCharactersFromOutput: boolean = false
    • Default value useExecMode: boolean = false

    Returns Promise<any>

Static executeSshCwd

  • executeSshCwd(session: SshSession, command: string, cwd: string, stdoutHandler: (data: string) => void, removeExtraCharactersFromOutput?: boolean, useExecMode?: boolean): Promise<any>
  • Parameters

    • session: SshSession
    • command: string
    • cwd: string
    • stdoutHandler: (data: string) => void
        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Default value removeExtraCharactersFromOutput: boolean = false
    • Default value useExecMode: boolean = false

    Returns Promise<any>

Static Private getHostKeyAlgorithm

  • getHostKeyAlgorithm(keyBuf: Buffer): string | undefined
  • Extract the algorithm name from an SSH public key blob. The blob is self-describing: it begins with a 4-byte big-endian length followed by the algorithm name, e.g. "ssh-ed25519" or "ssh-rsa".

    Parameters

    • keyBuf: Buffer

      the raw host key blob

    Returns string | undefined

    the algorithm name, or undefined if the blob cannot be parsed

Static Private getHostKeyFingerprint

  • getHostKeyFingerprint(keyBuf: Buffer): string
  • Compute the OpenSSH-style SHA256 fingerprint of a host key for display to the user, e.g. "SHA256:Xn5vB...". Matches the format shown by the standard ssh client.

    Parameters

    • keyBuf: Buffer

      the raw host key blob presented by the server

    Returns string

    the fingerprint string

Static Private getPinnedHostKeyAlgorithms

  • getPinnedHostKeyAlgorithms(session: SshSession): string[] | undefined
  • Determine which host key algorithm to request from the server, based on the pinned host key. Returns undefined when verification is disabled, no key is pinned, or the pinned key cannot be parsed - in which case ssh2's default algorithm negotiation applies.

    Parameters

    • session: SshSession

      the SSH session being connected

    Returns string[] | undefined

    the host key algorithm names to request, or undefined to use the default negotiation

Static Private getPinnedHostKeyType

  • getPinnedHostKeyType(session: SshSession): string | undefined
  • Return the algorithm name of the pinned host key (e.g. "ssh-ed25519", "ssh-rsa"), or undefined when verification is disabled, no key is pinned, or the pinned key cannot be parsed.

    Parameters

    • session: SshSession

      the SSH session being connected

    Returns string | undefined

    the pinned host key algorithm name, or undefined

Static Private handleConnectionError

  • handleConnectionError(err: Error, hasAuthFailed: boolean, reject: (reason?: any) => void, session: SshSession, connState?: IConnectionState): void
  • Handle SSH connection errors with appropriate error messages

    Parameters

    • err: Error

      The error object

    • hasAuthFailed: boolean

      Flag indicating if authentication has failed

    • reject: (reason?: any) => void

      Promise reject function

        • (reason?: any): void
        • Parameters

          • Optional reason: any

          Returns void

    • session: SshSession
    • Optional connState: IConnectionState

      Optional connection state carrying host key verification results

    Returns void

Static Private hostVerifier

  • hostVerifier(session: SshSession, connState?: IConnectionState): (Anonymous function)
  • Build the ssh2 host key verifier callback. Host key verification runs during the SSH handshake, before any credentials are sent, so an untrusted server never receives the user's password.

    The presented key is trusted when:

    • host key verification is disabled (insecure === true), or
    • it matches the pinned ISshSession.hostKey.

    Otherwise (no pinned key, or the key changed) the decision is delegated to the session's interactive SshSession.hostKeyVerifier hook if one is set (trust on first use); when no hook is available (e.g. non-interactive SDK usage) the connection is rejected.

    Parameters

    • session: SshSession

      the SSH session being connected

    • Optional connState: IConnectionState

      optional state updated when a key is rejected, so a clear error can be surfaced

    Returns (Anonymous function)

    an ssh2 hostVerifier callback

Static isConnectionValid

  • Check whether a session can establish a working SSH connection. Resolves true on success, false for non-host-key failures, and rejects with a host-key ImperativeError when the key is untrusted or changed, so callers can tell that apart from bad credentials.

    Parameters

    Returns Promise<boolean>

    a promise resolving to true/false, or rejecting with a host-key error

Generated using TypeDoc