Free TLS scripts / Linux
Linux post-quantum TLS for nginx, Apache and HAProxy - free TLS script
Reads the TLS and post-quantum settings of nginx, Apache and HAProxy, sets the recommended ones with the hybrid group X25519MLKEM768, and puts everything back on request.
What it does
- Without options it only reads: the TLS library, every site and listener, the protocols, cipher suites and groups the configuration sets, and what a handshake agrees on, with a rating, a verdict and the next step.
- With --apply it sets the Mozilla intermediate profile and post-quantum key exchange for the parts you choose, in one place of its own. --dry-run shows the change and writes nothing.
- Tests the configuration before a graceful reload, and puts the previous settings back when the reload or the TLS handshake fails.
- Keeps what was there before; --undo puts back exactly that.
- Never restarts a server, and sends nothing anywhere.
Requires
- nginx, Apache httpd 2.4 or HAProxy on Linux, with bash 4.2 or later, awk and openssl. Run as root.
- Post-quantum key exchange needs the server to run on OpenSSL 3.5 or later (Debian 13, Ubuntu 26.04, RHEL 10.1). On an older OpenSSL the script says so and sets protocols and cipher suites.
- Version
- 1.0.0
- SHA-256
- fa501a913ee42ea3069d8d4492fced33961fa73f7daf916f2d7fde565afebe79
- Licence
- Apache License 2.0, copyright FairSSL A/S. Use it, change it and share it, also commercially.
Download the file. Run chmod +x set-linux-server-tls and run the script as root.
Commands
sudo ./set-linux-server-tls | Read the server. Nothing is changed. |
|---|---|
sudo ./set-linux-server-tls --apply --dry-run | See what the recommended settings would change. |
sudo ./set-linux-server-tls --apply | Set them. |
sudo ./set-linux-server-tls --report html --report-file /root/tls-report.html | Writes the report as HTML or JSON to a file. |
sudo ./set-linux-server-tls --apply --parts groups | Switches on post-quantum key exchange only, and leaves protocols and cipher suites alone. |
sudo ./set-linux-server-tls --apply --pqc ignore | Sets protocols and cipher suites and leaves the groups alone. |
sudo ./set-linux-server-tls --apply --pqc only | Accepts only TLS 1.3 with a post-quantum hybrid group. Clients without one can no longer connect. |
sudo ./set-linux-server-tls --undo | Puts back everything the script changed. |
How it decides (details)
The script uses the same code as the sslbrain agents for nginx, Apache and HAProxy to find the server, read its configuration, write the settings, reload and check, so the script and sslbrain give the same answer on the same server.
Reading (no options). Nothing is written. For each product that is installed the report shows its version, the TLS library it runs on, the TLS directives of its configuration with file and line, and for each TLS site or listener what a local handshake gives: TLS 1.3 and the group it agrees on, TLS 1.2, whether TLS 1.0 or 1.1 is answered, and whether a cipher suite outside the profile is accepted. The verdict for each item is one of:
- OK: already active
- APPLY: the script can set it; the line gives the command
- UPGRADE: the TLS library is older than OpenSSL 3.5 and has no post-quantum key exchange
- CONFIG: a site keeps a setting of its own, which the script does not change; the line names it
- INFO: something to know
The rating. For each site or listener that answers, the report also rates the protocols it answers, each group it agrees to (the script offers them one at a time), the cipher suite it chooses for TLS 1.3 and for TLS 1.2, the old kinds of cipher suite it accepts when offered one kind at a time (RSA key transport, CBC, 3DES, RC4, NULL, anonymous), DHE with its size, and the key and the signature hash of its certificate, with one of four levels:
- Use: TLS 1.3; the hybrid groups X25519MLKEM768, SecP256r1MLKEM768 and SecP384r1MLKEM1024; AES-256-GCM; a certificate key of RSA 3072 or larger or ECC P-384; SHA-256 and SHA-384
- Works in a transition: TLS 1.2 with ECDHE and an AEAD cipher, so no cipher suite of TLS 1.2 is rated higher; the curves P-384 and P-521; AES-128-GCM and ChaCha20-Poly1305; an RSA 2048 key, for old equipment only
- Remove now (our interpretation)*: X25519 or P-256 alone, DHE, CBC cipher suites, ECC P-256 and Ed25519 keys
- Removal recommended long ago: TLS 1.0 and TLS 1.1; RSA key transport, DHE of 1024 bits, static DH; RC4, 3DES, NULL, EXPORT and anonymous suites; RSA 1024 and smaller; SHA-1 and MD5
* May be broken. The list is sslbrain's of 4 December 2026, after NSA's "Immediate Actions to Push Toward Post-Quantum" (2 December 2026) and Mozilla's TLS guidelines; "Remove now" is our interpretation of NSA's text. The recommended level keeps X25519, P-256 and P-384 after the hybrid group, for clients without post-quantum key exchange, so the report says Remove now for X25519 and P-256 there too; --pqc only leaves only the hybrid groups. The handshakes are made by this server's own openssl, so what it can no longer offer (SSL 3.0 and older, on many systems 3DES and RC4) is not in the rating.
The profile (--apply) is Mozilla's intermediate configuration, version 6.0:
- Protocols: TLS 1.2 and TLS 1.3
- Cipher suites: ECDHE with AES-GCM and ChaCha20-Poly1305 for TLS 1.2; TLS 1.3 keeps its own three
- Groups: X25519MLKEM768, X25519, prime256v1, secp384r1
--pqc chooses the level of post-quantum key exchange:
- ignore: the groups are not touched
- when-possible: the group list with X25519MLKEM768 first, where the server runs on OpenSSL 3.5 or later; elsewhere the script says why not and leaves the groups alone (default)
- only: TLS 1.3 only, and only the three hybrid groups of RFC 10024 (X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024). A server that cannot is not changed.
--parts chooses what is written: protocols, ciphers, groups (default: all three). A part that is not chosen keeps what the script's place held for it.
Where it writes. One place per product, and nothing else in the configuration is changed:
- nginx: conf.d/sslbrain-tls.conf beside nginx.conf (ssl_conf_command, from nginx 1.19.4)
- Apache: conf-enabled/sslbrain-tls.conf (Debian, Ubuntu) or conf.d/sslbrain-tls.conf (RHEL)
- HAProxy: a global section between "# BEGIN sslbrain-tls" and "# END sslbrain-tls" in haproxy.cfg
A site, VirtualHost or bind line that sets the same thing itself keeps its own setting; the script names it with file and line. A server managed by the sslbrain agent keeps the agent's settings unless you add --force.
Safety. Before it writes, the configuration must pass the product's own test and a local TLS handshake must answer (name the listener with --host, --port and --sni when the script cannot find one; --force goes on without). After the write the configuration is tested again, the product is reloaded gracefully, and the handshake must answer again and agree on the group that was set. With --pqc only, a client that offers only X25519 or only TLS 1.2 must be refused, so it needs an openssl 3.5 or later on the server to check with. If any of this fails, the previous content is put back and reloaded. A product that is not running is not started: the settings are written and tested, and apply when it starts. One --apply or --undo runs at a time.
Undo. /var/lib/sslbrain-tls (root only) keeps, per product, what the script's place held before the script's first change and what the script wrote. --undo puts the first back, with the same test, reload and handshake, when the place still holds what the script wrote. When someone has changed it since, it is left alone and named; --undo --force puts it back anyway. Run again, --undo has nothing left to do.
Exit codes:
- 0: done, or nothing to do
- 1: failed; the previous settings are back
- 2: refused; nothing was changed for that product
- 3: wrong option, not root, or no supported product found
Parameters
| --apply | Sets the recommended profile for the parts in --parts, at the level in --pqc. |
|---|---|
| --dry-run | With --apply or --undo: shows what would change and writes nothing. |
| --undo | Puts back what the script's place held before the script changed it. |
| --pqc | Post-quantum key exchange: ignore, when-possible (default) or only. |
| --parts | What --apply writes: protocols, ciphers, groups, separated by commas. Default: all three. |
| --product | Only this product: nginx, apache or haproxy. Default: every one that is installed. |
| --report | The report's format: text (default), json or html. |
| --report-file | Writes the report to this file instead of the screen. |
| --host | The address of the listener the handshake is made with. Default: the first TLS site found, on 127.0.0.1. |
| --port | The port of that listener. |
| --sni | The server name sent in the handshake. |
| --wait | Seconds to wait for the server to answer after a reload while nothing moves. Default: 300. |
| --force | Goes on where the script would refuse, and with --undo also puts back a place someone changed since. |
Writing a guide or answering a question? Link to this page instead of copying the script: it always has the newest version and its SHA-256.
[Linux post-quantum TLS for nginx, Apache and HAProxy - free TLS script](https://sslbrain.com/free-tls-scripts/linux-post-quantum-tls-nginx-apache-haproxy/) <a href="https://sslbrain.com/free-tls-scripts/linux-post-quantum-tls-nginx-apache-haproxy/">Linux post-quantum TLS for nginx, Apache and HAProxy - free TLS script</a> One script per server, or sslbrain does it for all your servers without scripts.
Feedback and improvements are welcome: info@fairssl.dk