> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectdiscovery.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Ssh.SSHClient

# Class: SSHClient

[ssh](/templates/protocols/javascript/modules/ssh).SSHClient

SSHClient is a client for SSH servers.
Internally client uses github.com/zmap/zgrab2/lib/ssh driver.

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
```

## Table of contents

### Constructors

* [constructor](/templates/protocols/javascript/modules/ssh.SSHClient#constructor)

### Methods

* [Close](/templates/protocols/javascript/modules/ssh.SSHClient#close)
* [Connect](/templates/protocols/javascript/modules/ssh.SSHClient#connect)
* [ConnectSSHInfoMode](/templates/protocols/javascript/modules/ssh.SSHClient#connectsshinfomode)
* [ConnectWithKey](/templates/protocols/javascript/modules/ssh.SSHClient#connectwithkey)
* [Run](/templates/protocols/javascript/modules/ssh.SSHClient#run)
* [SetTimeout](/templates/protocols/javascript/modules/ssh.SSHClient#settimeout)

## Constructors

### constructor

• **new SSHClient**(): [`SSHClient`](/templates/protocols/javascript/modules/ssh.SSHClient)

#### Returns

[`SSHClient`](/templates/protocols/javascript/modules/ssh.SSHClient)

#### Defined in

ssh.ts:16

## Methods

### Close

▸ **Close**(): `boolean`

Close closes the SSH connection and destroys the client
Returns the success state and error. If error is not nil,
state will be false

#### Returns

`boolean`

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.Connect('acme.com', 22, 'username', 'password');
const closed = client.Close();
```

#### Defined in

ssh.ts:118

***

### Connect

▸ **Connect**(`host`, `port`, `username`): `boolean`

Connect tries to connect to provided host and port
with provided username and password with ssh.
Returns state of connection and error. If error is not nil,
state will be false

#### Parameters

| Name       | Type     |
| :--------- | :------- |
| `host`     | `string` |
| `port`     | `number` |
| `username` | `string` |

#### Returns

`boolean`

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const connected = client.Connect('acme.com', 22, 'username', 'password');
```

#### Defined in

ssh.ts:43

***

### ConnectSSHInfoMode

▸ **ConnectSSHInfoMode**(`host`, `port`): [`HandshakeLog`](/templates/protocols/javascript/modules/ssh.HandshakeLog)

ConnectSSHInfoMode tries to connect to provided host and port
with provided host and port
Returns HandshakeLog and error. If error is not nil,
state will be false
HandshakeLog is a struct that contains information about the
ssh connection

#### Parameters

| Name   | Type     |
| :----- | :------- |
| `host` | `string` |
| `port` | `number` |

#### Returns

[`HandshakeLog`](/templates/protocols/javascript/modules/ssh.HandshakeLog)

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const info = client.ConnectSSHInfoMode('acme.com', 22);
log(to_json(info));
```

#### Defined in

ssh.ts:81

***

### ConnectWithKey

▸ **ConnectWithKey**(`host`, `port`, `username`): `boolean`

ConnectWithKey tries to connect to provided host and port
with provided username and private\_key.
Returns state of connection and error. If error is not nil,
state will be false

#### Parameters

| Name       | Type     |
| :--------- | :------- |
| `host`     | `string` |
| `port`     | `number` |
| `username` | `string` |

#### Returns

`boolean`

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const privateKey = `-----BEGIN RSA PRIVATE KEY----- ...`;
const connected = client.ConnectWithKey('acme.com', 22, 'username', privateKey);
```

#### Defined in

ssh.ts:61

***

### Run

▸ **Run**(`cmd`): `string`

Run tries to open a new SSH session, then tries to execute
the provided command in said session
Returns string and error. If error is not nil,
state will be false
The string contains the command output

#### Parameters

| Name  | Type     |
| :---- | :------- |
| `cmd` | `string` |

#### Returns

`string`

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.Connect('acme.com', 22, 'username', 'password');
const output = client.Run('id');
log(output);
```

#### Defined in

ssh.ts:101

***

### SetTimeout

▸ **SetTimeout**(`sec`): `void`

SetTimeout sets the timeout for the SSH connection in seconds

#### Parameters

| Name  | Type     |
| :---- | :------- |
| `sec` | `number` |

#### Returns

`void`

**`Example`**

```javascript theme={null}
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.SetTimeout(10);
```

#### Defined in

ssh.ts:26
