> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/pam/administration/sessions/ssh.md).

# SSH sessions

How a user reaches a Linux, Unix, or network-device asset over SSH — from the browser or from their own client on port 2222 — and the connection string, authentication order, and global switches that

## What this is and when to use it

For SSH the solution behaves as a **bastion host**. The user connects to the solution, not to the asset: the solution authenticates them, checks the authorization, opens the connection to the target with the stored credential, and records everything that follows. The user never needs the asset's password.

There are two ways in, and both produce the same recorded session:

| Method            | Where it runs                                          | Typical use                                                                |
| ----------------- | ------------------------------------------------------ | -------------------------------------------------------------------------- |
| **Web CLI**       | A terminal in the browser                              | Day-to-day access, third parties, anyone without a client installed        |
| **Native client** | PuTTY, MobaXterm, Termius, OpenSSH, VS Code Remote-SSH | Engineers who want their own tooling, key-based access, an SFTP side panel |

{% hint style="warning" %}
Two ports are involved and confusing them is the most common mistake here. Port **22** is the asset's own SSH port, used by the solution to reach the target. Port **2222** is the solution's own SSH listener — that is what a native client connects to. The default is 2222 rather than 22 so that it does not collide with the sshd of the host the solution runs on.
{% endhint %}

Native-client access can be switched off for the whole platform, which forces every SSH session through the recorded browser terminal. See **Client connection** in the field reference.

## Before you start

* The asset registered with the **SSH** protocol on a reachable port, running OpenSSH — on Windows too, if you intend to reach a Windows host over SSH.
* An account on the asset, registered in the solution.
* An authorization granting the user that asset, that account, the **SSH** protocol, and the **Connect** action. See [Authorizations](https://wiki.datadike.com/pam/administration/access/authorizations.md).
* Port **2222** open from the user's workstation to the solution's address, if they will use their own client.
* No [connect method](https://wiki.datadike.com/pam/administration/sessions/connection-methods.md) rule denying the client they intend to use.

## Connecting from the browser

1. Open the device access list, right-click the asset, and choose to connect.
2. Select the **SSH** protocol in the left-hand menu of the **Connect** dialog.
3. Choose the account under **Select account**.
4. Set the connection method to **Web**, and click **Connect**.

## Connecting from a native client

Every client is configured the same way: the host is the **solution's** address, the port is **2222**, and the username carries the routing information. Two string formats exist:

```
# Interactive: lands in a menu listing the assets you are authorized for
ssh -p 2222 <pamUser>@<pamAddress>

# Direct: goes straight to one asset and account, no menu
ssh -p 2222 <pamUser>@<assetAccount>@<assetAddress>@<pamAddress>
```

| Parameter      | Meaning                         | Example         |
| -------------- | ------------------------------- | --------------- |
| `pamUser`      | Your username in the solution   | `joao.silva`    |
| `assetAccount` | The account on the target asset | `root`          |
| `assetAddress` | The asset's address             | `192.168.1.100` |
| `pamAddress`   | The solution's address          | `10.0.0.50`     |
| `-p 2222`      | The solution's SSH port         | `2222`          |

The console can generate the string for you, in two further forms that identify the asset by its UUID rather than by its address:

```
# Permanent credential
ssh <pamUser>#<accountName>#<assetUUID>@<pamAddress> -p 2222

# One-off connection token
ssh <token>@<pamAddress> -p 2222
```

{% hint style="warning" %}
A connection token is short-lived and comes with a one-time password of its own. Do not save a token in `~/.ssh/config` — the entry will look correct and stop working the moment the token expires. Keep permanent entries for the credential form and the manual form only.
{% endhint %}

### Putting the string into `~/.ssh/config`

Clients that ask for host, port, and user separately — including the VS Code **Remote-SSH** extension — need the string broken up. The rule is the same whichever format you started from:

* everything **before the last `@`** goes in `User`
* the address **after the last `@`** goes in `HostName`
* the number after `-p` goes in `Port`

```
Host pam-prod-web
  HostName 10.0.0.50
  User joao.silva@root@192.168.1.100
  Port 2222
```

Then connect with `ssh pam-prod-web`.

### Authentication order

The client prompts in sequence, and what it asks for is not what the prompt names suggest:

1. **Password** — your password *in the solution*, never the asset's password.
2. **OTP code** — the six-digit code from your authenticator app, requested only when MFA is enabled on your account. In a plain terminal this arrives as an `[MFA verify]` prompt.

To authenticate with a key instead, generate a pair, register the public half under **Personal settings › SSH keys**, and connect with `-i`:

```
ssh-keygen -t rsa -b 4096 -f ~/.ssh/datadike_key
ssh -p 2222 -i ~/.ssh/datadike_key joao.silva@10.0.0.50
```

The solution can also generate the pair for you. In that case the private key is downloadable **once**, immediately after creation; miss that download and the only remedy is to create another key.

## What you should see

The interactive form opens a menu of the assets you are authorized for, and picking one drops you into a shell on the target. The direct form skips the menu. Either way you are on the asset as the account you chose, and `whoami` and `hostname` should confirm it — if they report the solution's own host, the routing part of the username was wrong and you never left the bastion.

## How to verify it worked

1. Type something identifiable in the session, then disconnect.
2. Open **Audit › Sessions** and confirm a record exists with protocol **SSH**, the account you used, and your workstation as the source address.
3. Open the session's **Commands** tab, or **Audit › Commands**, and confirm the command you typed is listed. This is the check that proves the session was really brokered — a connection that reached the asset directly leaves no command record.
4. Confirm **Replay** is offered on the finished session. See [Session recordings](https://wiki.datadike.com/pam/administration/audit/recordings.md).

If what you changed was native-client access, verify from the user's side instead: the **Connect** dialog must no longer offer the client method for any asset.

## Common errors

| Symptom                                      | Cause                                                                             | Fix                                                                                                                         |
| -------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| Connection refused, or times out on 2222     | The solution's SSH listener is unreachable                                        | Test `telnet <pamAddress> 2222`; check the firewall along the path and that the platform's services are running             |
| Credentials rejected                         | The asset's password was typed instead of the solution's                          | Use your password in the solution; the asset credential is injected for you                                                 |
| Credentials rejected with the right password | No authorization covers this user, asset, and account                             | Check the rule — asset, account, and the SSH protocol all have to be in it                                                  |
| `Permission denied (publickey)`              | The private key file is readable by others, or the key is not registered          | `chmod 400 key.pem` on Linux and macOS; `icacls "key.pem" /inheritance:r /grant:r "%username%:R"` on Windows                |
| The client rejects the connection string     | The `@` segments are in the wrong order, or one is missing                        | Rebuild it as *pamUser\@assetAccount\@assetAddress\@pamAddress* and check that the last `@` precedes the solution's address |
| A user removed from AD still gets in         | Their SSH public key is still registered and public-key authentication is enabled | Disable **Public key** when identities come from AD or LDAP — see the warning below                                         |
| The session drops while idle                 | The idle timeout closed it                                                        | Raise **Max idle time** in **System settings › Security › Sessions**, or accept the behaviour                               |
| "Session in use" when connecting             | Another session already holds the asset                                           | Wait, or have an administrator end the earlier one from **Audit › Sessions › Online**                                       |

{% hint style="danger" %}
If users are authenticated through AD or LDAP, turn **Public key** off. A user removed from the directory whose public key is still registered in the solution can keep opening SSH sessions, walking straight past your offboarding process. Password authentication follows the directory; a registered key does not.
{% endhint %}

## Field reference

Global terminal settings, at **System settings › Components › Basic** under **SSH & Terminal protocol**. They apply to every SSH, Telnet, and SFTP session on the platform:

| Field             | Default | What it does                                                                                                                                                      |
| ----------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Client connection | Enabled | Allows connections from native SSH clients. Disabling it removes the client option from the **Connect** dialog and forces every session into the browser terminal |
| Password          | Enabled | Allows password authentication against the terminal connector. The asset's own credential is injected by the solution either way and is never shown to the user   |
| Public key        | Enabled | Allows SSH public-key authentication. Turn it off when identities come from AD or LDAP                                                                            |
| Asset sorting     | Name    | Order of the asset list offered at connection time: **Name** alphabetically, or **Address** by IP or hostname                                                     |
| Asset page size   | Auto    | Assets per page in that list. **Auto** sizes it to the user's window; set a number for very large inventories                                                     |

Session limits, at **System settings › Security › Sessions**:

| Field                  | Default | What it does                                               |
| ---------------------- | ------- | ---------------------------------------------------------- |
| Max idle time (minute) | 30      | Disconnects a session idle for longer than this            |
| Max online time (hour) | —       | Disconnects a session open longer than this, active or not |

The port the solution listens on for SSH belongs to the TCP port policy and defaults to **2222**.

## Related pages

* [Connection methods](https://wiki.datadike.com/pam/administration/sessions/connection-methods.md) — removing the native client for a given audience
* [File transfer](https://wiki.datadike.com/pam/administration/sessions/file-transfer.md) — SFTP over the same account and port
* [Command filtering](https://wiki.datadike.com/pam/administration/access/command-filtering.md) — blocking commands inside the session
* [Session recording](https://wiki.datadike.com/pam/administration/sessions/recording.md) — what an SSH session leaves behind
* [Ports and protocols](https://wiki.datadike.com/pam/reference/ports.md) — the port used to reach each platform
