Requirements
- Shared secrets must be turned on for the NervesHub instance with
DEVICE_SHARED_SECRETS_ENABLED=true. It is off by default, and only certificate authentication works without it. See Feature prerequisites. - Product keys need NervesHub 2.0.0 or later and
nerves_hub_link2.1.0 or later. Shared secret is the default configurator fromnerves_hub_link2.4.0. - Device keys need NervesHub 2.5.0 or later.
- Your firmware must not include the
nerves_keyortpmlibraries, or you must set the configurator explicitly. See Choose the configurator.
Use a product key
1
Create the secret
Open Product settings in the product sidebar. In the Shared secrets card, click Create secret. This needs the Manage role or higher.
2
Copy the key and secret
The card lists each key. Copy the key, which starts with
nhp_. Use the copy button next to the key to copy its secret.3
Configure the firmware
System.fetch_env!/1 runs when you build the firmware, so the values are compiled into it. Set both variables in the shell or CI job that runs mix firmware.4
Boot the device
The device connects with its serial number as its identifier. If no device with that identifier exists in the product, NervesHub creates one.
Use a device key
A device key is issued to a device that already exists. A provisioning station typically creates the device and its key together and writes the key and secret to the device.1
Issue the key
- New device, web UI
- Existing device, web UI
- CLI
Open Devices, click Add device, and under How it connects choose A shared secret of its own. After you click Add device, the dialog shows the Key and Secret.
2
Put the key and secret on the device
NervesHubLink reads a device key from the Compiling a device key into firmware ties that firmware to one device. To keep one firmware image for the fleet, store the values in the Nerves key-value store instead. NervesHubLink reads
key and secret options:nh_shared_key and nh_shared_secret from it, and they take priority over the config.3
Boot the device
The device must connect with the identifier of the device the key was issued to.
Where NervesHubLink looks for the key and secret
NervesHubLink uses the first key it finds, in this order:nh_shared_keyin the Nerves key-value storekeyin theshared_secretconfignh_shared_product_keyin the Nerves key-value storeproduct_keyin theshared_secretconfig
nhp_, the secret comes from nh_shared_product_secret in the key-value store, then product_secret in the config. For any other key, it comes from nh_shared_secret in the key-value store, then secret in the config.
Choose the configurator
NervesHubLink.Configurator.SharedSecret is the default only when neither nerves_key nor tpm is in your project. If one of them is, select shared secrets explicitly:
Check that it works
Open Devices in the product. The device shows as Online once it connects. For a device key, the Shared secrets card on the device’s Settings tab lists each key with who created it. If the device does not connect:- Check the device clock. NervesHub accepts a signature for 90 seconds after it was made. From
nerves_hub_link2.13.0, a device whose connection is refused reads the time from the server’s response and signs its next attempt with it, so a device that boots with a wrong clock connects on a retry. - Check that the key is active. A deactivated key shows as Deactivated in the card.
- Check that the device has not been deleted. A deleted device’s keys stop authenticating, and a product key cannot create a new device under a deleted device’s identifier.
Options
Set these insideshared_secret:
The number of PBKDF2 iterations. From NervesHub 2.5.3, a device asking for more than 10,000 is refused.
The derived key length in bytes. From NervesHub 2.5.3, a device asking for more than 64 is refused.
nerves_hub_link 2.13.1 or later. Earlier versions reused a custom configurator’s first signature on reconnect, and NervesHub refused it once it expired.
Deactivate a key
Keys are deactivated, not deleted. A deactivated key stays in the list.
Issuing and deactivating device keys are recorded in the device’s audit log.
To replace a key, create a new one, move your devices to it, then deactivate the old one.
Limits
- A device key stays with the device when it moves to another product or organization. Whoever holds the secret can still connect as the device. When a device moves to an organization that should not share credentials with the one it left, issue a new key there and deactivate the old ones.
- A product key lets its holder connect as any identifier in the product, including identifiers that do not exist yet. Use device keys or certificates for production fleets.

