> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nerves-hub.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Local shell extension

> Open an interactive OS shell on a device from NervesHub with the optional Local shell extension, which is mostly for devices that are not Nerves devices.

The Local shell extension gives NervesHub users an interactive shell on the device's operating system. It is separate from the [remote console](https://docs.nerves-hub.org/management/remote-console.md), which is an IEx session.

The extension is optional. It is mostly recommended for devices that are not Nerves devices, such as ones running the [Linux agent](https://docs.nerves-hub.org/integrations/linux-agent.md).

> [!WARNING]
>
> A local shell lets a NervesHub user with the right permission run commands on the device as the user your application runs as. Turn it on only for products where you want that.

## Requirements

* `nerves_hub_link` 2.10.0 or later.
* NervesHub 2.3.0 or later.
* The [`expty`](https://hex.pm/packages/expty) library in your firmware.

## Enable it on a Nerves device

For the Linux agent, turn on `[extensions.local_shell]` in the agent's config instead. See [Linux agent](https://docs.nerves-hub.org/integrations/linux-agent.md). The product and device settings below apply to both.

**1. Add ExPTY to your dependencies**

```elixir theme={null}
# mix.exs
{:expty, "~> 0.3.0"}
```

`nerves_hub_link` lists `expty` as an optional dependency. Without it, the extension cannot start a shell.

**2. Check your extension list**

When `ExPTY` is available, `NervesHubLink.Extensions.LocalShell` is in the default `extension_modules` list and you have nothing to configure.

If you set `extension_modules` yourself, that list replaces the default, so name the module in it:

```elixir theme={null}
config :nerves_hub_link,
  extension_modules: [
    NervesHubLink.Extensions.Geo,
    NervesHubLink.Extensions.Health,
    NervesHubLink.Extensions.NetworkIdentity,
    NervesHubLink.Extensions.LocalShell
  ]
```

**3. Turn it on for the product**

In **Product settings**, on the **General** tab, switch on **Local shell** in the **Device extensions** card. A product created in the web UI starts with every extension on. A product created through the API or `nh` starts with every extension off.

**4. Check the device setting**

On the device's **Settings** tab, **Local Shell** in the **Extensions** card is on by default.

## Check that it works

Reconnect the device if it was connected before you turned the extension on. Open the device and select the **System Shell** tab. A terminal opens when the device is online and the extension is attached.

If the tab says the local shell isn't currently enabled, check the product and device settings. If it says the shell isn't currently available, the device has not attached the extension: check that the firmware includes `expty` and the module.

## How it behaves

* The device runs the program in the `SHELL` environment variable with `-i`. If `SHELL` is not set, it runs `sh -i`.
* `TERM` defaults to `xterm` when it is not set.
* The session is shared. Everyone with the **System Shell** tab open for a device sees the same shell.
* NervesHub keeps a bounded scrollback for the connection, so someone opening the tab sees recent output.

## Who can use it

Opening a local shell needs the `device:extensions:local_shell` permission. It is separate from the `device:console` permission for the remote console. See [Roles](https://docs.nerves-hub.org/access/roles.md).

## Related pages

* [Extensions overview](https://docs.nerves-hub.org/extensions/overview.md)
* [Remote console](https://docs.nerves-hub.org/management/remote-console.md)
* [Linux agent](https://docs.nerves-hub.org/integrations/linux-agent.md)
* [Roles and permissions](https://docs.nerves-hub.org/access/roles.md)
* [Extensions protocol](https://docs.nerves-hub.org/device-api/extensions.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.