> Source: https://docs.cyberelements.io/saas/hu/Security/Ssh/

# SSH

SSH (*Secure Shell*) is the application protocol used for the **remote administration** of CyberElements servers. It addresses the known shortcomings of the legacy protocols FTP, RSH, RCP and TELNET.

This chapter sets out the recommendations for hardening the OpenSSH configuration of the Edge Gateway servers. Removing the legacy services (`telnet`, `rsh`, `rlogin`, `ftp`) is covered in [Installation and security maintenance](https://docs.cyberelements.io/saas/hu/Security/SystemHardening/SystemInstallation/#r4).

> **Information**
>
> The ANSSI reference for this chapter is the technical note **DAT-NT-007/ANSSI/SDE/NP** "Recommandations pour un usage sécurisé d'(Open)SSH". It was last updated on **17 August 2015**: unlike ANSSI-BP-028 (2022), it has not been revised since. The directives that have become obsolete in current versions of OpenSSH are pointed out below.

## Summary

| # | Recommendation | Edge Gateway |
|---|---|---|
| [**R25**](#r25) | Protocol and cryptographic algorithms | ✅ |
| [**R26**](#r26) | Authentication and user access control | ✅ |
| [**R27**](#r27) | SSH key authentication and disabling of passwords | ✅ |
| [**R28**](#r28) | Restriction of network and forwarding features | ✅ |
| [**R29**](#r29) | Network listening and exposure of the SSH service | ✅ |
| [**R30**](#r30) | Limitation of sessions and connection timeouts | ✅ |
| [**R31**](#r31) | Banner and logging of SSH connections | ✅ |
| [**R32**](#r32) | Size and robustness of host and user keys | ✅ |
| [**R33**](#r33) | Entropy quality and uniqueness of host keys | ✅ |
| [**R34**](#r34) | Advanced features not retained by default | ✅ |

> **Information**
>
> So as to limit direct changes to the main files shipped with OpenSSH, server hardening should be placed in a **dedicated file** `/etc/ssh/sshd_config.d/00-cyberelements-bastion-hardening.conf`.

> **Warning!**
>
> **Before any change to the SSH configuration**, keep an administration session open and have emergency console access available. After making changes, run `sshd -t`. Only reload the service if there is no error, then open a **second session** to validate before closing the first.

```
1
2
3
```

## R25. Protocol and cryptographic algorithms

**Applies to**: Edge Gateway ✅

SSHv1 is obsolete and has been removed from the OpenSSH code: only **SSHv2** is now supported. The historical `Protocol 2` directive is no longer recognised and **must not** be added to the configuration.

The encryption, integrity and key exchange algorithms must be limited to a robust core. The **server** configuration protects incoming connections; the **client** configuration applies when the server itself initiates an outgoing SSH connection.

Recommended server configuration in `/etc/ssh/sshd_config.d/00-cyberelements-bastion-hardening.conf`:

```
1
2
3
```

Recommended system client configuration in `/etc/ssh/ssh_config.d/00-cyberelements-bastion-hardening.conf`:

```
1
2
3
4
5
6
7
```

> **Information**
>
> The proposed core keeps the **hybrid post-quantum** mechanisms available in current OpenSSH, as well as Curve25519 as a widely compatible fallback.

> **Warning!**
>
> An explicit list of algorithms can make certain older SSH clients or certain administration appliances **incompatible**. Before applying it in production, check the algorithms available and test the administration workstations actually in use.

```
1
2
3
```

For the RSA keys used in user or host authentication, a minimum size can be enforced:

```
1
```

> **Warning!**
>
> `RequiredRSASize 3072` is classified **"to be validated"**. Any existing RSA key of a smaller size would be **rejected**. Take an inventory of the keys used by administrators, maintenance accounts and any automated exchanges before applying it (see [Classification of recommendations](https://docs.cyberelements.io/saas/hu/Security/Classification/#reserved-or-to-be-validated)).

## R26. Authentication and user access control

**Applies to**: Edge Gateway ✅

Recommended configuration in the server hardening file:

```
1
2
3
4
5
6
7
8
```

- `PermitRootLogin no`: direct SSH access to the root account is disabled;
- `PermitEmptyPasswords no`: forbids any authentication with an empty password;
- `StrictModes yes`: checks the permissions and owners of home directories and SSH files before accepting an authentication;
- `PermitUserEnvironment no`: prevents a user from injecting environment variables through `~/.ssh/environment` or `authorized_keys`;
- `KbdInteractiveAuthentication no`: avoids exposing a second interactive mechanism equivalent to the password where it is not explicitly needed;
- `UsePAM yes`: keeps PAM account and session controls in force, notably the `pam_faillock` policy defined in [R10](https://docs.cyberelements.io/saas/hu/Security/SystemHardening/SystemAccounts/#r10).

SSH access must be limited **to authorised accounts only**. A **single main restriction model** should be chosen (either by users or by groups) so as to avoid combinations that are hard to maintain:

```
1
2
3
```

> **Information**
>
> A restriction by origin can be added directly in `AllowUsers`, for instance `admin@192.168.17.0/24`, where an administration network has been identified. **Network filtering** nonetheless remains the main control.

> **Warning!**
>
> In the case of an OVA carrying a **`systancia` maintenance account**, that account must remain covered by the access policy in line with the applicable support procedure.

## R27. SSH key authentication and disabling of passwords

**Applies to**: Edge Gateway ✅

SSH key authentication should be preferred for administration accounts. Keys must be **named after their holder**, protected on the administrator's workstation and **never shared** between several people.

Recommended server configuration **once the keys have been deployed and validated**:

```
1
2
3
```

> **Warning!**
>
> `PasswordAuthentication no` must only be applied **once the public key of every authorised administrator has been deposited and validated**. On a newly deployed machine, keep the administration session active, test a key-based connection in a second terminal, and only then disable password authentication.

Audit of the authorised public keys:

```
1
```

Checking the effective configuration:

```
1
```

> **Information**
>
> Where the workstations and the security policy allow it, keys protected by a **FIDO hardware authenticator** can also be considered (types `ed25519-sk` or `ecdsa-sk`). This measure remains optional and must be integrated into the administration policy.

## R28. Restriction of network and forwarding features

**Applies to**: Edge Gateway ✅

The forwarding mechanisms provided by SSH are not required for the standard administration role of CyberElements and can **turn the server into a network relay**. They must be neutralised unless a need is explicitly identified and validated.

```
1
2
3
4
5
6
7
8
9
```

> **Information**
>
> `DisableForwarding yes` neutralises X11, agent, TCP and Unix socket forwarding. The individual directives are kept so as to make the expected policy **explicit**. `PermitTunnel no` deals separately with network-level tunnels.

> **Warning!**
>
> If an operational procedure or a product mechanism **genuinely** requires SSH forwarding, `DisableForwarding yes` must not be used as it stands. The need must then be identified precisely and only the strictly necessary functions re-enabled.

> **Classification**
>
> **To be validated**: `AllowTcpForwarding no`, to be checked against maintenance tools. See the [Classification of recommendations](https://docs.cyberelements.io/saas/hu/Security/Classification/#reserved-or-to-be-validated) appendix.

## R29. Network listening and exposure of the SSH service

**Applies to**: Edge Gateway ✅

The SSH service must be reachable **only from authorised administration networks or addresses**. Where several interfaces are present, listening should be limited to the address dedicated to administration:

```
1
```

Restricting exposure must be complemented by the [firewall rules](https://docs.cyberelements.io/saas/hu/Security/LocalFirewall/), network ACLs and, where possible, a **dedicated administration VLAN**. The SSH service **must not be exposed directly to the Internet** without source address filtering.

> **Information**
>
> Changing the SSH port can reduce the noise generated by automated scans, but **it is not in itself a security measure**. The real control rests on network filtering, robust authentication, limiting the authorised accounts, and logging.

> **Classification**
>
> **To be validated**: Dedicated SSH port < 1024 (ANSSI nuance). See the [Classification of recommendations](https://docs.cyberelements.io/saas/hu/Security/Classification/#reserved-or-to-be-validated) appendix.

## R30. Limitation of sessions and connection timeouts

**Applies to**: Edge Gateway ✅

```
1
2
3
4
```

`ClientAliveInterval` and `ClientAliveCountMax` make it possible to detect and close a connection whose client **no longer responds** to the messages sent over the encrypted channel. They are **not** a mechanism for closing a merely idle user session: a client still connected answers keep-alive messages even if the user types no command.

Closing idle shells is handled through `TMOUT` in [Accounts and privileges](https://docs.cyberelements.io/saas/hu/Security/SystemHardening/SystemAccounts/). The `ChannelTimeout` directive can be used to impose an inactivity delay at SSH channel level, but it is classified **"to be validated"**, because the `session` type also covers remote commands, SCP and SFTP and can therefore interrupt long-running operations.

```
1
2
```

> **Information**
>
> OpenSSH also applies **per-source-address penalties** to certain abnormal behaviours or repeated failures. That native mechanism must stay active; it complements `pam_faillock` and [fail2ban](https://docs.cyberelements.io/saas/hu/Security/Fail2ban/) **without replacing them**.

## R31. Banner and logging of SSH connections

**Applies to**: Edge Gateway ✅

```
1
2
3
4
5
```

- `Banner /etc/issue.net`: reuses the generic banner defined in [R18](https://docs.cyberelements.io/saas/hu/Security/SystemHardening/SystemIntegrity/#r18);
- `LogLevel VERBOSE`: improves the traceability of authentications and key fingerprints without enabling the `DEBUG` levels, too verbose for production;
- `PrintLastLog yes`: shows the user the date of their last interactive login;
- `UseDNS no`: avoids reverse DNS resolution when the connection is established;
- `DebianBanner no`: avoids adding the distribution suffix to the protocol version banner presented by the server.

After reloading, SSH events can be checked with:

```
1
```

## R32. Size and robustness of host and user keys

**Applies to**: Edge Gateway ✅

For new administration keys, **Ed25519** is preferred where the cryptographic policy and tooling allow it. **RSA** remains a robust compatibility mechanism with a size of at least 3072 bits; **4096 bits** is recommended for new RSA keys.

Examples of generating a user key protected by a passphrase:

```
1
2
```

> **Information**
>
> The `-a` option increases the number of rounds of the derivation function used to protect a private key when a passphrase is set. It **does not replace** the requirement for a strong passphrase and proper protection of the administration workstation.

The host keys present on the server can be inventoried and checked with:

```
1
2
```

**DSA** keys must not be used or re-enabled. **ECDSA** keys remain usable where required by the cryptographic policy or by compatibility constraints, but they are no longer the primary choice for new keys in this guide.

> **Warning!**
>
> Any **rotation of an SSH host key** changes the fingerprint presented to administrators and can trigger a *host key changed* alert. A rotation must be planned, documented and accompanied by a controlled update of the `known_hosts` files concerned.

> **Classification**
>
> **To be validated**: Preferring ECDSA over RSA. See the [Classification of recommendations](https://docs.cyberelements.io/saas/hu/Security/Classification/#reserved-or-to-be-validated) appendix.

## R33. Entropy quality and uniqueness of host keys

**Applies to**: Edge Gateway ✅

The robustness of host keys depends on the **quality of the random generator** at the time they are created. In virtualised environments and **cloned images**, the essential point is to guarantee that each instance has its own random state and **unique host keys**.

Useful checks:

```
1
2
3
4
```

> **Information**
>
> The `entropy_avail` value is **only an indicator** of the kernel's entropy pool and must not be used on its own as a criterion for deciding whether a key is sufficiently safe. Current kernels have reinforced initialisation and randomness collection mechanisms.

## R34. Advanced features not retained by default

**Applies to**: Edge Gateway ✅

Several features described by the ANSSI note remain possible but are **not retained by default** for CyberElements. They are documented so that their exclusion is **explicit**.

- **Authentication agent forwarding** for SSH hops: not retained by default, in line with `AllowAgentForwarding no` and `DisableForwarding yes`;
- **OpenSSH PKI and key certificates**: to be reserved for organisations that already have an SSH certification authority and a certificate lifecycle management process;
- **Publication of SSH fingerprints through DNS (SSHFP)**: depends on the deployment and DNSSEC validation; not retained as a product requirement;
- **chroot confinement** for dedicated SFTP accounts: not relevant for the standard administration of CyberElements, whose SSH access relies on named administration accounts.

## Final validation of the SSH configuration

```
1
2
3
4
```

> **Warning!**
>
> The administration session used to carry out the hardening must only be closed **once a new SSH connection, `sudo` elevation, the necessary maintenance accounts and, where applicable, synchronisation between nodes have been validated**.
