Skip to main content

Connection Factory Methods

connectWithPassword

Connects to an SSH server using password authentication.

Parameters

string
required
The hostname or IP address of the SSH server.
number
required
The port number of the SSH server (typically 22).
string
required
The username for authentication.
string
required
The password for authentication.
CallbackFunction<SSHClient>
Optional callback function to handle any errors during the connection process.

Returns

Promise<SSHClient>
A Promise that resolves to an instance of SSHClient if the connection is successful.

Example


connectWithKey

Connects to an SSH server using a private key for authentication.

Parameters

string
required
The hostname or IP address of the SSH server.
number
required
The port number of the SSH server (typically 22).
string
required
The username for authentication.
string
required
The private key for authentication in PEM format.
string
The passphrase for the private key (optional). Required if the private key is encrypted.
CallbackFunction<SSHClient>
A callback function to handle the connection result (optional).

Returns

Promise<SSHClient>
A Promise that resolves to an instance of SSHClient if the connection is successful. Otherwise, it rejects with an error.

Example


Key Management Methods

generateKeyPair

Generates a new SSH key pair for authentication.

Parameters

string
required
The type of key to generate (e.g., ‘rsa’, ‘ed25519’, ‘ecdsa’).
string
Optional passphrase to encrypt the private key.
number
Optional key size in bits (e.g., 2048, 4096 for RSA). Defaults vary by key type.
string
Optional comment to include with the key pair.

Returns

Promise<GeneratedKeyPair>
A Promise that resolves to an object containing the generated key pair.

Example


getKeyDetails

Retrieves the details of an SSH private key.

Parameters

string
required
The SSH private key as a string in PEM format.

Returns

Promise<{ keyType: string; keySize: number }>
A Promise that resolves to the details of the key.Properties:
  • keyType (string): The type of the key (e.g., ‘RSA’, ‘ED25519’, ‘ECDSA’)
  • keySize (number): The size of the key in bits

Example

Types

CallbackFunction

Represents a callback function with an optional response.

genKeyPair

Represents the result of generating a key pair.

keyDetail

Represents the details of an SSH key.
Last modified on July 4, 2026