Shared secrets suit hobby and R&D projects. For production, use certificates. See Device certificates.
Prerequisites
- A working Nerves installation, including
fwup. The CLI usesfwupto sign firmware. - Hardware to run it on, and an SD card. A Raspberry Pi 4 is a good option, and any of the Nerves supported targets works well.
- An account on NervesCloud or on a self-hosted NervesHub.
- An instance with shared secret authentication turned on. See Feature prerequisites.
manage.nervescloud.com for you and devices.nervescloud.com for devices. Use your own hosts if you self-host.
1
Install the CLI and sign in
Install If you self-host, point the CLI at your instance first:Sign in. This opens your browser and shows a code to enter there:Save your organization as a default so you can leave out
nh with Homebrew, or see CLI installation for other methods:--org:2
Create the project
3
Create a product and a shared secret
In the web UI:
- Open your organization. If it has no products yet, enter
my_appin the Create your first product form and click Create product. Otherwise click New product, name itmy_app, and click Create Product. The CLI refuses to upload firmware built for a different product name. - Open Product settings.
- In the Shared secrets card, click Create secret.
- Copy the key. The secret is not displayed: click the copy button next to the key, labelled Copy secret, to copy it.
4
Create a firmware signing key
~/.nh/keys/<org>/, and registers the public key with your organization. The private key stays on your machine. You are asked for an optional passphrase to encrypt it.List your keys to get the public key:KEY column for my_app_key.5
Add and configure NervesHubLink
Add the library inside the Configure it in
deps function in mix.exs:config/target.exs:fwup_public_keys lists the signing keys the device trusts. The device refuses firmware that is not signed by one of them.6
Build and burn
mix firmware builds a .fw file and mix burn writes it to the SD card. Insert the card and power on the device. It boots, joins the network and connects to NervesHub.7
Confirm the device connected
In the web UI, open the product and go to Devices. A device that connects with a product’s shared secret is created on its first connection, so it appears in the list without being added first.You can also list devices from the CLI. Run it inside the project directory, or pass Note the device’s identifier. You need it later.
--product my_app:8
Build, sign and upload an update
Make a visible change and raise the version in Inside a Nerves project,
mix.exs, for example to "0.2.0". Then build, sign and upload:nh finds the built image under _build/ and asks you to confirm it. It signs the file with my_app_key, uploads it, and prints the firmware’s version and UUID. Copy the UUID.Add --password <passphrase> if you set a passphrase on the key.9
Create a deployment group and turn it on
A deployment group says which devices get which firmware. Create one for the firmware you uploaded and turn it on:This group has no tag or version conditions, so it matches every device in the product that runs the same platform and architecture as the firmware.A new group has delta updates on. This first update still downloads the full firmware. The firmware you burned was never uploaded to NervesHub, so there is nothing to build a delta from.
The web UI calls these deployment groups. The
nh CLI and the HTTP API use the name deployment. They are the same thing.10
Watch the device update
NervesHub places a device in a matching deployment group when the device connects. Your device connected before the group existed, so ask it to reconnect:The device then:
- Receives the update over its WebSocket connection.
- Downloads the firmware.
- Verifies the signature against
fwup_public_keysand applies the update withfwup. - Reboots into the new firmware and reconnects.
nh device show <identifier>, to see the new firmware version.Ship the next update
Once the group exists, one command signs, uploads and points the group at new firmware:Next steps
Device certificates
Move from a shared secret to X.509 certificates for production.
Applying updates
Decide in your firmware when an update is applied, and report progress.
Deployment groups
Target devices by tag and version, and control how a rollout proceeds.
Remote console
Open an IEx session on a connected device.

