Skip to main content
With certificate authentication, each device presents its own X.509 client certificate when it opens the TLS connection to NervesHub. Each device has its own key, so one leaked device exposes only itself. This is the method to use for production fleets. This page covers a certificate and private key stored on the device filesystem. To keep the key in hardware, see NervesKey or TPM.

How NervesHub decides

NervesHub keeps device certificates on file.
  • The certificate is on file. The device is allowed. NervesHub does not check the expiry of a certificate it has on file.
  • The certificate is new, and a CA signed it. NervesHub looks up the signing CA among the registered certificate authorities and validates the certificate against it. The certificate’s common name must match the identifier of a device in the CA’s organization. NervesHub then records the certificate for that device. If no such device exists, the connection is refused unless the CA has a just-in-time provisioning profile.
  • The certificate is new, and it is self-signed. The connection is refused. A self-signed certificate is only accepted when it is already on file for the device.
So there are three ways to get a certificate accepted: A deleted device is refused, whatever certificate it presents.

Requirements

  • The device certificate’s common name is the device identifier.
  • A CA-signed device certificate needs an Authority Key Identifier. NervesHub matches it against the Subject Key Identifier of the registered CA, so the CA certificate needs a Subject Key Identifier.
  • Registering, editing and deleting certificate authorities need the Manage role or higher from NervesHub 2.5.3. Earlier versions need Admin in the web UI.

Register a certificate authority

You register the CA certificate only. NervesHub never sees the CA private key. To prove you hold the key, you sign a short-lived verification certificate with it.
Generate a CA on your machine and register it:
nh ca generate writes the key and certificate to <data-dir>/ca/<org>/, named by the generation time, for example 2026-06-11-16-41-10-cert.pem and 2026-06-11-16-41-10-key.pem. The data directory defaults to ~/.nh. The common name defaults to the organization name. Change it with --name, and the validity with --valid-for.To register a CA you already have, give its certificate and key:
The key is used locally to sign the verification certificate.

Check expiration

By default NervesHub does not check the CA certificate’s validity period when it registers a device certificate. Turn on Check expiration to stop an expired CA from registering new device certificates. You cannot turn it on while registering a CA that has already expired.

Create device certificates

nh device certificates generate creates a private key (secp256r1) on your machine. What else it creates depends on the flags:
The certificate carries the device identifier as its common name. Files are written to <data-dir>/certificates/<org>/, named <identifier>-<timestamp>-key.pem and <identifier>-<timestamp>-cert.pem. --valid-for sets the validity, for example 90d. The default is 31y. --upload registers the certificate with the device, so the device must already exist. To upload a certificate from another source:
In the web UI, open the device’s Settings tab and click Upload certificate in the Certificates card. It takes a PEM or DER file.
A self-signed certificate must be uploaded before the device connects.
If you use Microchip Trust&Go secure elements, nh device import creates the devices and their certificates from the manifest. See Devices. Select the LocalCertKey configurator. It is never chosen automatically.
The configurator looks for the certificate in this order:
  1. cert or certfile in the ssl option
  2. nerves_hub_cert in the Nerves key-value store, as PEM
  3. cert.pem in the data_path directory, which defaults to /data/nerves-hub
It looks for the key the same way:
  1. key or keyfile in the ssl option
  2. nerves_hub_key in the Nerves key-value store, as a PEM EC private key
  3. key.pem in the data_path directory
So with no other configuration, put the files at /data/nerves-hub/cert.pem and /data/nerves-hub/key.pem.

Put the files on the device

NervesHub and nh do not copy the certificate and key to the device for you. /data is the device’s application data partition, so files there are not part of the firmware image and you write them once per device. Two ways that need no extra tooling:
  • A device on your bench. If the firmware includes an SSH server with SFTP, copy the two files over SFTP. nerves_ssh starts an SFTP subsystem by default.
    Use the host name or address your device answers on in place of nerves.local.
  • A device that already connects to NervesHub. A device that connects another way, for example with a shared secret, can be given the files over the remote console. Its firmware needs remote_iex: true. Rename your copies of the files to cert.pem and key.pem, then drop each one on the device’s Console tab. nerves_hub_link saves a dropped file under its own name in the data_path directory, which is where LocalCertKey looks. This needs nerves_hub_link 2.1.0 or later. You can also write the files from the console prompt:
    Then send the device firmware that selects LocalCertKey.
A firmware update over the air leaves /data alone. Writing a complete image does not: on the official Nerves systems, such as nerves_system_rpi4, the complete task that mix burn runs invalidates the application data partition so that it is formatted on the next boot. After you burn an SD card again, copy the files again. To use other paths:

Check that it works

Open the device’s Settings tab. The Certificates card lists the certificate with its serial, the CA that signed it, its validity and when it was last used. The CA’s page shows how many devices use a certificate it signed, by product. If the device does not connect, check:
  • The CA is registered in the same organization as the device.
  • The certificate’s common name is exactly the device identifier.
  • The device exists and is not deleted, or the CA has a just-in-time provisioning profile.
  • A self-signed certificate has been uploaded to the device.

Limits

  • One key per device. A device that has a certificate on file cannot register a certificate with a different public key by connecting with it. Upload the new certificate instead.
  • Renewing a certificate with the same key is automatic. When a device presents a new certificate for a public key NervesHub already knows, NervesHub records it if the common name still matches the device and a CA registered in the device’s organization signed it.
  • Deleting a certificate does not block a CA-signed device. When a device has no certificate on file and its CA is still registered, NervesHub records its certificate again the next time it connects. To keep a device out, delete the device. See Devices.
  • Certificates stay with a device when it moves to another product or organization.