Ssh command to enter Karaf console inside docker container

  • Platform information:
    • openHAB Host OS: Ubuntu 24.04 LTS
    • Remote Host OS: macos
  • Issue of the topic:
    I want to ssh directly into a Karaf console of my openHAB inside a docker container with a single command. On my mac I’m using a tool to open ssh consoles to different machines. I would be happy to integrate openhab. It requires a single command/line to open the ssh connection and to enter the docker container.

I can ssh onto my openhab host:
ssh username@openhabIP -i ~/path/to/key

On my openhab system I can successfully enter the openhab console by following command:

username@openhab:~$ docker exec -it openhab /openhab/runtime/bin/client
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J(W): Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J(W): Ignoring binding found at [jar:file:/openhab/runtime/system/org/apache/karaf/org.apache.karaf.client/4.4.6/org.apache.karaf.client-4.4.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J(W): See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Logging in as openhab
Password:  

                           _   _     _     ____  
   ___   ___   ___   ___  | | | |   / \   | __ ) 
  / _ \ / _ \ / _ \ / _ \ | |_| |  / _ \  |  _ \ 
 | (_) | (_) |  __/| | | ||  _  | / ___ \ | |_) )
  \___/|  __/ \___/|_| |_||_| |_|/_/   \_\|____/ 
       |_|       4.2.0 - Release Build

Use '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
To exit, use '<ctrl-d>' or 'logout'.

The combination does not work:

ssh username@openhabIP -i ~/path/to/key "docker exec -it openhab /openhab/runtime/bin/client"
the input device is not a TTY

neither does:

ssh username@openhabIP -i ~/path/to/key "docker exec -i openhab /openhab/runtime/bin/client" 
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J(W): Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J(W): Ignoring binding found at [jar:file:/openhab/runtime/system/org/apache/karaf/org.apache.karaf.client/4.4.6/org.apache.karaf.client-4.4.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J(W): See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
No more authentication methods available

Is there a way to combine it?
Thank you!

Found the solution by myself.
Maybe it is helpful also for others.

ssh -t username@openhabIP -i ~/path/to/key "docker exec -it openhab /openhab/runtime/bin/client" 
1 Like

Karaf is actually an SSH server, so you could SSH directly from mac to Karaf without bunny hopping through your linux host’s ssh server first.

You just need to specify the correct port (default is 8101 I think) and make sure Karaf is not just listening on the localhost. Also make sure you understand the security repercussions on this.

Another way is instead of using docker exec, you could invoke the ssh client on the openhab host to go into karaf. This lets Karaf still listen on localhost only.

But if you’re happy with what you’re doing now, then that’s fine too.

1 Like

Thank you JimT for clarification. Indeed, depending on which ports were opened, multiple access option arise.
I did not mention another use case for me so far: /openhab/runtime/bin/backup
With the same mechanism I can trigger a backup remotely.

I use docker too. I just backup my conf and userdata volumes / directories using rsync + snapshot volume rather than using the backup script.

As always there are many options.
I have “duplicati” running in another container to backup my whole set of docker compose files and mounted volumes to a NAS.

1 Like