OpenSSH Configuration
This page describes:
- how OpenSSH is configured on XCP-ng dom0
- what you can safely customize
- which SSH key authentication options are available
This page applies to XCP-ng 8.3. Configuration file layout and defaults may differ on other versions.
Do not edit the main SSH configuration files
XCP-ng ships two configuration files:
/etc/ssh/sshd_config(server configuration)/etc/ssh/ssh_config(client configuration)
These files are provided by XCP-ng and are overwritten with every update to keep ciphers, key exchange algorithms, and other OpenSSH security settings up to date. Do not modify them. Any manual changes will be silently lost on the upcoming updates and may conflict with the configuration XCP-ng ships in the meantime.
If you need your own configuration, use the drop-in directories instead. These are never modified by updates:
/etc/ssh/sshd_config.d/for the server/etc/ssh/ssh_config.d/for the client
When using these drop-in directories, the file name prefix matters: OpenSSH reads the files in lexical order, and the first value it encounters for a given directive is the one that is applied.
Create a file there with a .conf extension. The example below makes sshd listen on port 2222.
Before applying this example: the dom0 firewall only allows incoming SSH connections on port 22. If you change the SSH port, first allow the new port in /etc/sysconfig/iptables (change the existing --dport 22 rule with your new port) and, if the host is reachable over IPv6, in /etc/sysconfig/ip6tables as well. Then restart iptables (and ip6tables) and sshd. Otherwise, you will lock yourself out of SSH.
# cat > /etc/ssh/sshd_config.d/50-port.conf <<'EOF' # XCP-ng's user configuration file (Refer to https://docs.xcp-ng.org/guides/openssh ) # User custom port # Port 2222 # EOF
Settings to leave as shipped
Overriding XCP-ng's settings weakens security. The security level of any parameter overridden by the user is no longer guaranteed to match the level XCP-ng maintains and updates over time. Deviating from XCP-ng's defined settings may result in unauthorized access or insecure key exchange, and the user will be entirely responsible for the resulting configuration.
It is strongly discouraged to use a drop-in file to override a parameter that is already defined in /etc/ssh/sshd_config or /etc/ssh/ssh_config (ciphers, key exchange algorithms, MACs, host key types, etc.).
The only exception documented here is PubkeyAcceptedAlgorithms, which you must override to enable FIDO2 security keys or SSH certificates: follow Enabling FIDO2 keys or SSH user certificates to do it without removing the algorithms enabled by default.
Forwarding
Since the openssh-9.9p1-33.3 package of XCP-ng 8.3, forwarding is restricted to the host itself:
- Local port forwarding to the host itself works (
ssh -L <LOCAL_PORT>:localhost:<REMOTE_PORT>). This is what procedures such as connecting a VNC client to a VM console or reaching XO Lite or the XAPI through a tunnel (ssh -L <LOCAL_PORT>:localhost:443) rely on. - The destination of
ssh -Lmust belocalhost,127.0.0.1or[::1]. Names are matched literally, without any DNS lookup: a tunnel to the host's own management IP address is refused, even though it points to the same machine. - Forwards to other machines are refused, whatever the method:
ssh -Lto another address,ssh -W,ssh -J/ProxyJumpandssh -D(SOCKS proxy). - Remote port forwarding (
ssh -R), agent forwarding and Unix socket forwarding are refused. - X11 forwarding is not possible on XCP-ng hosts.
This is done with the following settings in /etc/ssh/sshd_config:
AllowTcpForwarding local
PermitOpen localhost:* 127.0.0.1:* [::1]:*
AllowAgentForwarding no
AllowStreamLocalForwarding no
AllowTcpForwarding local refers to the direction of the forward (client to server, as with ssh -L), not to its destination: PermitOpen is what restricts the destination to the host itself. All three forms are listed because hosts with IPv6 can resolve localhost to ::1.
As a consequence, an XCP-ng host can no longer be used as a gateway to other machines (SSH jump host, SOCKS proxy, access to VMs behind a single public IP address). This use has never been recommended: dom0 is not meant to give access to other machines, and restricting forwarding reduces its attack surface. Agent forwarding is refused because it would let anyone with root access on the host use the keys loaded in your SSH agent.
Altering the forwarding configuration
Changing the forwarding settings shipped by XCP-ng is your responsibility. XCP-ng does not document nor recommend any use of forwarding beyond the one described above, and the security level of an altered configuration is no longer guaranteed.
If you need to change these settings, do it with a drop-in file, never by editing /etc/ssh/sshd_config:
- Why a drop-in wins:
/etc/ssh/sshd_configincludes/etc/ssh/sshd_config.d/*.confat its very top, and for each directivesshdapplies the first value it reads. A value set in a drop-in is therefore read before the one in/etc/ssh/sshd_configand takes precedence. - Lists are replaced, not merged: the first
PermitOpenline read replaces the whole list. If you setPermitOpenin a drop-in, it must contain every destination you want to allow, includinglocalhost:* 127.0.0.1:* [::1]:*if you still need local tunnels to the host. - File name: the file must end in
.conf, otherwise it is ignored. Drop-in files are read in name order, so a file with a lower prefix (for example00-) is read before the others. - Persistence: the drop-in survives updates. Updates only replace
/etc/ssh/sshd_configand/etc/ssh/ssh_config, and XAPI does not touch/etc/ssh/sshd_config.d/.
To apply a drop-in safely:
- Check the configuration syntax with
sshd -t. It must return no error before you go further. - Keep your current session open: restarting
sshdapplies the new configuration to new connections only, so this session lets you revert the change if needed. - Restart
sshdwithsystemctl restart sshd. - From another terminal, open a new SSH connection and check that you can still log in.
- Check the values actually applied with
sshd -T, for example:
# sshd -T | grep -Ei 'forwarding|permitopen'
If something fails, remove the drop-in file from your original session and restart sshd again.
What you can safely customize
Some parameters can be changed as needed. However, once you change one, you are responsible for maintaining it over time. This includes ensuring that it remains compatible with future OpenSSH updates:
- The SSH port, via
Portin ansshd_config.ddrop-in. (default:22) - The number of authentication attempts, via
MaxAuthTries. (default:3) - The time allowed to log in, via
LoginGraceTime. (default:60seconds) - Connection penalties (rate-limiting/blocking of abusive source addresses), via
PerSourcePenaltiesand related directives (PerSourceNetBlockSize,PerSourcePenaltyExemptList). (default:persourcepenalties crash:90 authfail:5 noauth:1 grace-exceeded:10 refuseconnection:10 max:600 min:15 max-sources4:65536 max-sources6:65536 overflow:permissive overflow6:permissive)
Connection penalties are enabled in the OpenSSH 9.9p1 package of XCP-ng as a protection against brute-force attacks: when an address repeatedly fails to authenticate, or opens connections that never authenticate, sshd refuses new connections from it for a while, even with valid credentials. This can affect several users or scripts behind the same NAT address, monitoring tools that only check that port 22 is open, or SSH agents offering several wrong keys before the right one. If you are affected, exempt the trusted addresses with PerSourcePenaltyExemptList rather than disabling penalties entirely.
Example:
# cat > /etc/ssh/sshd_config.d/60-penalties.conf <<'EOF' # PerSourcePenalties crash:120 authfail:30 noauth:5 grace-exceeded:60 refuseconnection:60 max:1200 min:10 max-sources4:65536 max-sources6:65536 overflow:deny-all overflow6:deny-all # PerSourcePenaltyExemptList 192.0.2.10,198.51.100.0/24 # EOF
Then restart sshd to apply it:
# systemctl restart sshd
Post-quantum key exchange
The OpenSSH 9.9p1 version included in XCP-ng 8.3 automatically negotiates a hybrid post-quantum-resistant key exchange method (such as mlkem768x25519-sha256 or sntrup761x25519-sha512), provided your SSH client also supports it. If it does not, the exchange method used will not be post-quantum, but this has no impact on your ability to manage your server. No configuration is required on your side: this happens as part of the normal algorithm negotiation at connection time.
SSH key authentication
OpenSSH on XCP-ng supports public-key authentication, which is more convenient than password login and helps protect against certain attacks, such as password brute-force. A key pair is made of a private key, which stays on your client machine and must be kept secret, and a public key, which you install on the XCP-ng host in /root/.ssh/authorized_keys.
Several key types are supported: Ed25519, ECDSA (nistp256, nistp384, nistp521) and RSA (with SHA-2 signatures only: rsa-sha2-256 and rsa-sha2-512). The exact list of accepted key types is defined by PubkeyAcceptedAlgorithms in the configuration shipped in /etc/ssh/sshd_config.
What you can do with it:
- Generate a key pair on your client machine, optionally protected by a passphrase
- Install the public key on one or more XCP-ng hosts (with
ssh-copy-idor by adding it to/root/.ssh/authorized_keysmanually) - Load the key into an SSH agent so you do not have to type the passphrase for every connection
- Once key authentication works, disable password login entirely (see Key-only authentication)
For the actual key generation and installation steps, follow the documentation of your SSH client and operating system, as tools and procedures vary. For example:
- OpenSSH (Linux, macOS, BSD):
ssh-keygen(1),ssh-agent(1) - Other clients (PuTTY, terminal emulators, password managers with an SSH agent, etc.): refer to their own documentation.
The server limits the number of failed authentication attempts per connection (MaxAuthTries). Since the openssh-9.9p1-33.3 package, keys offered by your client and refused by the server have their own allowance: they only start counting against MaxAuthTries once a given number of keys has been refused (the max-pk-ok option of PubkeyAuthOptions).
If your SSH agent holds many keys, the connection may still be closed with Too many authentication failures before the right key is tried, and repeated failures can get your address temporarily blocked (see PerSourcePenalties). To avoid this, tell your client which key to use, for example with IdentityFile and IdentitiesOnly yes in your OpenSSH client configuration.
To check the values applied on your host, run sshd -T | grep -Ei 'maxauthtries|pubkeyauthoptions'.
FIDO2/U2F security keys
OpenSSH on XCP-ng also supports FIDO2/U2F hardware security keys (such as YubiKey, SoloKey or Nitrokey) as SSH keys, via the ed25519-sk and ecdsa-sk key types. This support is available but not enabled by default: see Enabling FIDO2 keys. The private key material can be generated on the hardware token and will never leave it. Each authentication requires you to physically touch the device. As a result, the private key cannot be stolen or silently reused, even from a compromised client machine.
This requires a FIDO2/U2F-capable security key and an SSH client with security-key support. OpenSSH clients support this since version 8.2, so any recent Linux, macOS, or Windows OpenSSH client should work.
For the actual key generation and enrollment steps, follow the official documentation for your security key model and operating system. Procedures vary by manufacturer and by OS.
Available FIDO2 algorithms
FIDO2 algorithms are not enabled in the configuration shipped by XCP-ng. The following algorithms exist for FIDO2 keys:
- Plain keys, where the server trusts the public key listed in
/root/.ssh/authorized_keys:sk-ssh-ed25519@openssh.com(fored25519-skkeys)sk-ecdsa-sha2-nistp256@openssh.com(forecdsa-skkeys)
- Certificates (
-cert-v01), where the public key is signed by an SSH certificate authority (CA). The server trusts the CA (viaTrustedUserCAKeys) instead of each individual key, and the certificate can carry a validity period and a list of allowed principals:sk-ssh-ed25519-cert-v01@openssh.comsk-ecdsa-sha2-nistp256-cert-v01@openssh.com
Only enable the algorithms matching the keys you actually use. If you do not use an SSH certificate authority, you do not need the -cert-v01 variants.
Enabling FIDO2 keys
PubkeyAcceptedAlgorithms replaces the whole list of accepted algorithms. Therefore, you must also include the algorithms enabled by default (ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256). Otherwise, only FIDO2 keys will be accepted: you may lock yourself out, and your configuration will no longer be supported.
The following ready-to-use drop-in enables plain FIDO2 keys while keeping the default algorithms.
The 00- prefix makes this file load first, provided no other drop-in file matches 00-[0-e]*; such files are read before it:
# cat > /etc/ssh/sshd_config.d/00-fido.conf <<'EOF' # FIDO2 security keys (as suggested at https://docs.xcp-ng.org/guides/openssh) # PubkeyAcceptedAlgorithms sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256 # EOF # sshd -t
If you use SSH certificates, add sk-ssh-ed25519-cert-v01@openssh.com and/or sk-ecdsa-sha2-nistp256-cert-v01@openssh.com to this list.
Only the first PubkeyAcceptedAlgorithms value read is applied. If you also need SSH user certificates, put all the algorithms in this single drop-in file instead of creating a second one.
sshd -t checks the configuration syntax without applying it. It must return no error before you go further.
Restarting sshd applies the new configuration to new connections only: sessions that are already open are kept. Keep your current session open until you have confirmed that you can still log in, so you can revert the change if needed.
Once the configuration is validated and your current session is kept open, restart sshd:
# systemctl restart sshd
Then, from another terminal, open a new SSH connection with your FIDO2 key, and another one with a regular key. Only close your original session once both work.
If you are hardening SSH more aggressively, keep the configuration precise and minimal:
- Stay informed of developments in OpenSSH on XCP-ng: this documentation will be updated if necessary.
- If you are using a key-only setup, combine this with
PasswordAuthentication noand keep a validated backup access path before disabling password login.
SSH user certificates
SSH user certificates (*-cert-v01@openssh.com key types, used with TrustedUserCAKeys) were accepted by previous OpenSSH packages of XCP-ng 8.3. Since the openssh-9.9p1-33.3 package, PubkeyAcceptedAlgorithms only lists plain keys, so certificate logins are refused after the update.
If you log in with SSH certificates, create this drop-in before updating (it is harmless on the previous version), while keeping the algorithms enabled by default:
# cat > /etc/ssh/sshd_config.d/00-certificates.conf <<'EOF' # SSH user certificates (as suggested at https://docs.xcp-ng.org/guides/openssh) # PubkeyAcceptedAlgorithms ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256 # EOF # sshd -t
Only keep the certificate types you actually use. Only the first PubkeyAcceptedAlgorithms value read is applied: if you also use FIDO2 keys, add their algorithms (sk-ssh-ed25519@openssh.com, sk-ecdsa-sha2-nistp256@openssh.com and their -cert-v01 variants) to this same list instead of creating a second drop-in file.
sshd -t checks the configuration syntax without applying it. It must return no error before you go further.
Restarting sshd applies the new configuration to new connections only: sessions that are already open are kept. Keep your current session open until you have confirmed that you can still log in, so you can revert the change if needed.
Once the configuration is validated and your current session is kept open, restart sshd:
# systemctl restart sshd
Then, from another terminal, open a new SSH connection with your certificate. Only close your original session once it works. If it fails, remove the drop-in file from your original session and restart sshd again.
Key-only authentication
Xen Orchestra (XOA or self-hosted XO) does not use SSH to manage your hosts: it talks to hosts over XAPI (HTTPS). This means you can freely harden SSH without affecting Xen Orchestra's ability to manage the pool.
In particular, you can enforce public-key authentication and disable password authentication, which XCP-ng supports.
Disabling password authentication can prevent technical support from connecting to your hosts. Prepare a way to grant support access when needed, for example by temporarily adding a public key provided by the support team to /root/.ssh/authorized_keys, and removing it once the intervention is over.
To avoid locking yourself out, make sure your public key is installed and working (test a new connection in a separate session) before disabling password authentication. Keep your current session open until you have confirmed that you can still log in: restarting sshd does not close sessions that are already open.
Create the following drop-in file and check the configuration:
# cat > /etc/ssh/sshd_config.d/70-auth.conf <<'EOF' # User hardening (as suggested at https://docs.xcp-ng.org/guides/openssh) # PasswordAuthentication no # PubkeyAuthentication yes # EOF # sshd -t
Once sshd -t returns no error and your current session is kept open, restart sshd:
# systemctl restart sshd
Then, from another terminal, open a new SSH connection with your key. Only close your original session once it works. If it fails, remove the drop-in file from your original session and restart sshd again.
Staying up to date
This page describes the behavior of OpenSSH as shipped in XCP-ng 8.3; it may differ on other versions.
OpenSSH security recommendations evolve over time, and so does the configuration XCP-ng ships in /etc/ssh/sshd_config and /etc/ssh/ssh_config. These settings are updated to keep them aligned with current security recommendations.
Keep an eye on XCP-ng release notes and OpenSSH updates, as the measures described here may change over time to maintain an up-to-date level of security.