CLI reference (nh)

Command reference for the nh CLI: auth, config, orgs, products, devices, firmware, signing keys, deployments, and CA certificates.

Written By Josh Kalderimis

Last updated About 2 months ago

nh is the NervesHub / NervesCloud command-line tool. Use it to sign and publish firmware, manage signing keys, and script fleet operations from CI.

Run nh help for the top-level list and nh help <command> for detail on any command.

Install

brew install nerves-hub/tap/nh

# or:

curl --proto '=https' --tlsv1.2 -fsSL \
  https://raw.githubusercontent.com/nerves-hub/nerves_hub_cli/master/install.sh | sh

The curl installer places the nh binary in /usr/local/bin.

Connect and authenticate

nh defaults to NervesCloud (https://manage.nervescloud.com). Point it at a self-hosted instance, then authenticate:

nh config set uri "https://my.selfhosted.instance/"

nh user auth

Global commands

Command

What it does

nh help [COMMAND]

Show help, optionally for one command.

nh version

Print the CLI version.

nh user: account

Command

What it does

nh user auth

Authenticate this machine with the platform.

nh user whoami

Show the authenticated user.

nh user logout

Remove stored credentials.

nh config: local settings

Valid keys: uri, org, product.

Command

What it does

nh config set KEY VALUE

Set a config value (e.g. uri).

nh config get KEY

Print a config value.

nh config clear KEY

Unset a config value.

nh org: organization members

Command

What it does

nh org user list

List members.

nh org user add USERNAME ROLE

Add a member with a role.

nh org user update USERNAME ROLE

Change a member's role.

nh org user remove USERNAME

Remove a member.

nh product: products & members

Command

What it does

nh product list

List products in the org.

nh product create

Create a product.

nh product delete PRODUCT_NAME

Delete a product.

nh product update PRODUCT_NAME KEY VALUE

Update a product setting.

nh product user list PRODUCT_NAME

List product members.

nh product user add PRODUCT_NAME USERNAME ROLE

Add a member.

nh product user update PRODUCT_NAME USERNAME ROLE

Change a member's role.

nh product user remove PRODUCT_NAME USERNAME

Remove a member.

nh device: devices

Command

What it does

nh device list

List devices.

nh device create

Create a device.

nh device bulk_create

Create many devices from a file.

nh device delete IDENTIFIER

Delete a device.

nh device update IDENTIFIER KEY VALUE...

Update a device (e.g. tags).

nh device cert list DEVICE

List a device's certificates.

nh device cert create DEVICE

Create a device certificate.

nh device cert import DEVICE CERT_PATH

Import an existing device certificate.

nh device script list

List support scripts.

nh device script send IDENTIFIER NAME_OR_ID

Run a support script on a device.

Common options: --org, --product, --identifier, --description, --tag (repeatable), --cert, --key, --path.

nh firmware: firmware

Command

What it does

nh firmware list

List published firmware.

nh firmware publish [FILE]

Sign (if needed) and upload a firmware image.

nh firmware sign [FILE]

Sign a firmware image locally.

nh firmware delete UUID

Delete a firmware.

nh key: firmware signing keys

Command

What it does

nh key list

List signing keys.

nh key create NAME

Create a key pair and register the public key.

nh key delete NAME

Delete a key.

nh key import NAME PUBLIC_KEY_FILE PRIVATE_KEY_FILE

Import an existing key pair.

nh key export NAME

Export a key.

nh deployment: deployment groups

The CLI uses deployment for what the web UI calls a deployment group.

Command

What it does

nh deployment list

List deployment groups.

nh deployment create

Create a deployment group.

nh deployment update DEPLOYMENT_NAME KEY VALUE

Update a deployment setting.

nh cacert: organization CA certificates

Manage the Signer CAs used to verify device certificates. See Production setup with NervesKey.

Command

What it does

nh cacert list

List registered CA certificates.

nh cacert register CERT_PATH

Register a CA certificate with the org.

nh cacert unregister CERT_SERIAL

Remove a CA certificate.

Environment variables

Set these to run nh non-interactively (for example, in CI). Both NERVES_CLOUD_* and NERVES_HUB_* prefixes work.

Variable

Purpose

NERVES_CLOUD_TOKEN / NERVES_HUB_TOKEN

API token for authentication.

NERVES_CLOUD_ORG / NERVES_HUB_ORG

Default organization.

NERVES_CLOUD_PRODUCT / NERVES_HUB_PRODUCT

Default product.

NERVES_CLOUD_FW_PRIVATE_KEY / NERVES_HUB_FW_PRIVATE_KEY

Firmware signing private key.

NERVES_CLOUD_FW_PUBLIC_KEY / NERVES_HUB_FW_PUBLIC_KEY

Firmware verification public key.

NERVES_CLOUD_DATA_DIR / NERVES_HUB_DATA_DIR

Config/keys directory (default ~/.nerves-cloud / ~/.nerves-hub).

NERVES_CLOUD_URI / NERVES_HUB_URI

Platform URI (default https://manage.nervescloud.com).

NERVES_CLOUD_NON_INTERACTIVE / NERVES_HUB_NON_INTERACTIVE

Answer yes to all prompts.

Related