# Balena ssh tunnel to device container

**URL:** <https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365>\
**Category:** balenaOS\
**Created:** [October 31, 2020, 5:38am UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365 "2020-10-31T05:38:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpk](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jpk](https://forums.balena.io/u/jpk)\
**Post date:** [October 31, 2020, 5:38am UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365/1 "2020-10-31T05:38:21Z")

</div>

Can I setup an ssh tunnel directly to an application container running on the device?

---

<div class="post-metadata">

**Author:** ![crbn60](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/crbn60/32/3671_2.png) [@crbn60](https://forums.balena.io/u/crbn60)\
**Post date:** [October 31, 2020, 3:03pm UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365/4 "2020-10-31T15:03:10Z")

</div>

You can easily get an interactive session to a container:

```auto
$ balena ssh f49cefd my-service

```

I don’t see the option for an actual tunnel, though. Hopefully someone else chimes in.

---

<div class="post-metadata">

**Author:** ![jpk](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jpk](https://forums.balena.io/u/jpk)\
**Post date:** [October 31, 2020, 3:34pm UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365/5 "2020-10-31T15:34:34Z")

</div>

Thanks for your reply crbn60. I’m specifically looking for tunnelling as I want to run some other services over the tunnel.

---

<div class="post-metadata">

**Author:** ![alexgg](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@alexgg](https://forums.balena.io/u/alexgg)\
**Post date:** [November 2, 2020, 12:45pm UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365/6 "2020-11-02T12:45:43Z")

</div>

Hi, did you already try the `balena tunnel` CLI command? See [https://www.balena.io/docs/reference/balena-cli/#tunnel-deviceorapplication](https://www.balena.io/docs/reference/balena-cli/#tunnel-deviceorapplication)

---

<div class="post-metadata">

**Author:** ![crbn60](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/crbn60/32/3671_2.png) [@crbn60](https://forums.balena.io/u/crbn60)\
**Post date:** [November 2, 2020, 4:14pm UTC](https://forums.balena.io/t/balena-ssh-tunnel-to-device-container/204365/8 "2020-11-02T16:14:54Z")

</div>

I had never seen that command at all! Brilliant.

Quick ref:

```auto
Tunnel local ports to your balenaOS device.

USAGE
  $ balena tunnel <deviceOrApplication>

ARGUMENTS
  <deviceOrApplication> device uuid or application name/id

OPTIONS
  -h, --help show CLI help
  -p, --port <port> port mapping in the format <remotePort>[:[localIP:]localPort]

DESCRIPTION
  Use this command to open local ports which tunnel to listening ports on your balenaOS device.

  For example, you could open port 8080 on your local machine to connect to your managed balenaOS
  device running a web server listening on port 3000.

  Port mappings are specified in the format: <remotePort>[:[localIP:]localPort]
  localIP defaults to 'localhost', and localPort defaults to the specified remotePort value.

  You can tunnel multiple ports at any given time.

  Note: Port mappings must come after the deviceOrApplication parameter, as per examples.

EXAMPLES
  # map remote port 22222 to localhost:22222
  $ balena tunnel myApp -p 22222

  # map remote port 22222 to localhost:222
  $ balena tunnel 2ead211 -p 22222:222

  # map remote port 22222 to any address on your host machine, port 22222
  $ balena tunnel 1546690 -p 22222:0.0.0.0

  # map remote port 22222 to any address on your host machine, port 222
  $ balena tunnel myApp -p 22222:0.0.0.0:222

  # multiple port tunnels can be specified at any one time
  $ balena tunnel myApp -p 8080:3000 -p 8081:9000

```
