|
| 1 | +--- |
| 2 | +title: Register and connect an IoT device |
| 3 | +titleSuffix: Azure IoT Hub |
| 4 | +description: How to create, manage, and delete Azure IoT devices and how to retrieve their connection information. |
| 5 | +author: kgremban |
| 6 | + |
| 7 | +ms.author: kgremban |
| 8 | +ms.service: iot-hub |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 06/10/2024 |
| 11 | +--- |
| 12 | + |
| 13 | +# Create and manage device identities |
| 14 | + |
| 15 | +Create a device identity for your device to connect to Azure IoT Hub. This article introduces key tasks for managing a device identity including registering the device, collecting its connection information, and then deleting or disabling a device at the end of its lifecycle. |
| 16 | + |
| 17 | +## Register a new device in the IoT hub |
| 18 | + |
| 19 | +In this section, you create a device identity in the [identity registry in your IoT hub](./iot-hub-devguide-identity-registry.md). A device can't connect to a hub unless it has a device identity. |
| 20 | + |
| 21 | +The IoT Hub identity registry only stores device identities to enable secure access to the IoT hub. It stores device IDs and keys to use as security credentials, and an enabled/disabled flag that you can use to disable access for an individual device. |
| 22 | + |
| 23 | +IoT Hub supports three methods for device authentication: |
| 24 | + |
| 25 | +* **Symmetric key** - When you register a new device, you can provide keys or IoT Hub will generate keys for you. Both the device and the IoT hub have a copy of the symmetric key that can be compared when the device connects. |
| 26 | +* **X.509 self-signed** - Also called thumbprint authentication, you upload a portion of the device's X.509 certificate to the IoT hub. When the device connects, it presents its certificate and the IoT hub can validate it against the portion it knows. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md). |
| 27 | +* **X.509 CA signed** - You upload and verify an X.509 certificate authority (CA) certificate to the IoT hub. The device has an X.509 certificate with the verified X.509 CA in its certificate chain of trust. When the device connects, it presents its full certificate chain and the IoT hub can validate it because it knows the X.509 CA. Multiple devices can authenticate against the same verified X.509 CA. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md). |
| 28 | + |
| 29 | +### [Azure portal](#tab/portal) |
| 30 | + |
| 31 | +1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub. |
| 32 | +1. Select **Device management** > **Devices**, then select **Add Device** to add a device in your IoT hub. |
| 33 | + |
| 34 | + :::image type="content" source="./media/iot-hub-include-create-device/create-identity-portal.png" alt-text="Screen capture that shows how to create a device identity in the portal." border="true"::: |
| 35 | + |
| 36 | +1. In **Create a device**, provide the information for your new device identity: |
| 37 | + |
| 38 | + | Parameter | Dependent parameter | Value | |
| 39 | + | -- | -- | -- | |
| 40 | + | **Device ID** | | Provide a name for your new device. | |
| 41 | + | **Authentication type** | | Select either **Symmetric key**, **X.509 self-signed**, or **X.509 CA signed**. | |
| 42 | + | | **Auto-generate keys** | For **Symmetric key** authentication, check this box to have IoT Hub generate keys for your device. Or, uncheck this box and provide primary and secondary keys for your device. | |
| 43 | + |
| 44 | + 1. a name for your new device. |
| 45 | + |
| 46 | + [!INCLUDE [iot-hub-pii-note-naming-device](iot-hub-pii-note-naming-device.md)] |
| 47 | + |
| 48 | +1. Select **Save**. |
| 49 | + |
| 50 | + |
| 51 | +### [Azure CLI](#tab/cli) |
| 52 | + |
| 53 | +### [PowerShell](#tab/powershell) |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Retrieve device connection information |
| 58 | + |
| 59 | +### [Azure portal](#tab/portal) |
| 60 | + |
| 61 | +1. After the device is created, open the device from the list in the **Devices** pane. Copy the value of **Primary connection string**. This connection string is used by device code to communicate with the IoT hub. |
| 62 | + |
| 63 | + By default, the keys and connection strings are masked because they're sensitive information. If you click the eye icon, they're revealed. It's not necessary to reveal them to copy them with the copy button. |
| 64 | + |
| 65 | + :::image type="content" source="./media/iot-hub-include-create-device/device-details.png" alt-text="Screen capture that shows the device connection string." border="true" lightbox="./media/iot-hub-include-create-device/device-details.png"::: |
| 66 | + |
| 67 | +### [Azure CLI](#tab/cli) |
| 68 | + |
| 69 | +### [PowerShell](#tab/powershell) |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Disable or delete a device in an IoT hub |
| 74 | + |
| 75 | +If you want to keep a device in your IoT hub's identity registry, but want to prevent it from connecting then you can change its status to *disabled.* |
| 76 | + |
| 77 | +### [Azure portal](#tab/portal) |
| 78 | + |
| 79 | +1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub. |
| 80 | + |
| 81 | +1. Select **Devices** from the navigation menu. |
| 82 | + |
| 83 | +1. Select the name of the device that you want to disable to view its device details page. |
| 84 | + |
| 85 | +1. On the device details page, set the **Enable connection to IoT Hub** parameter to **Disable**. |
| 86 | + |
| 87 | + :::image type="content" source="./media/iot-hub-create-through-portal/disable-device.png" alt-text="Screenshot that shows disabling a device connection."::: |
| 88 | + |
| 89 | +If you want to remove a device from your IoT hub's identity registry, you can delete its registration. |
| 90 | + |
| 91 | +1. From the **Devices** page of your IoT hub, select the checkbox next to the device that you want to delete. |
| 92 | + |
| 93 | +1. Select **Delete** to remove the device registration. |
| 94 | + |
| 95 | + :::image type="content" source="./media/iot-hub-create-through-portal/delete-device.png" alt-text="Screenshot that shows deleting a device."::: |
| 96 | + |
| 97 | +### [Azure CLI](#tab/cli) |
| 98 | + |
| 99 | +### [PowerShell](#tab/powershell) |
| 100 | + |
| 101 | +--- |
0 commit comments