# VS Code Terminal Window: How to automatically ssh to openhab server

**URL:** <https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515>\
**Category:** VS Code\
**Created:** [March 23, 2021, 10:54am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515 "2021-03-23T10:54:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter\_tau](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@peter\_tau](https://community.openhab.org/u/peter_tau)\
**Post date:** [March 23, 2021, 10:54am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/1 "2021-03-23T10:54:40Z")

</div>

Dear Community,

Is there a way to automatically establish an ssh connection to the openhab server when clicking on the terminal window in VS Code? At present, I only get shell access to the local computer where I can manually open an ssh connection.

Best regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Bruce\_Osborne](https://community.openhab.org/user_avatar/community.openhab.org/bruce_osborne/32/38531_2.png) [@Bruce\_Osborne](https://community.openhab.org/u/Bruce_Osborne)\
**Post date:** [March 23, 2021, 11:00am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/2 "2021-03-23T11:00:29Z")

</div>

Whenever I use VS Code with ssh and close the window when I am done it automatically reconnects when I reopen the window.

This is a VS Code usage question outside the topic of this forum.The fact you are accessing OH configuration files is incidental to your issue.

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 23, 2021, 5:11pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/3 "2021-03-23T17:11:22Z")

</div>

Sure, easy.

Prerequisites:

1. ssh installed (Windows10 (since ~ 19.10?) already has an installed ssh client).
2. a key pair without password to login (public key listed in .ssh/authorized\_keys)
3. a configuration in VSCode like this:

```auto
"openhab.karafCommand": "ssh.exe -i C:\\path\\to\\openhab.id_rsa user@server-ip"

```

Please be aware that the option is meant to directly open a connection to the karaf console. This would be port 8101 and another configuration in question of public key. But you can also use this command to connect to the GNU/Linux bash.

You can call the console via ctrl shift P → openhab: Open openHAB console (will be first command in list after using it or the first time)

---

<div class="post-metadata">

**Author:** ![peter\_tau](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@peter\_tau](https://community.openhab.org/u/peter_tau)\
**Post date:** [March 23, 2021, 5:42pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/4 "2021-03-23T17:42:53Z")

</div>

Dear Udo,

Thank you very much for your explanations. I had the openhab.karafCommand configured, but without any reference to a public key. Please note that I work on an iMac with macOS Catalina 10.15.7. having slightly different shell commands as compared to Windows, but the command is adapted to match the expected syntax.

I managed to successfully install a key pair so that ssh login from my desktop shell to the openhab server on port 22 is working fine, without being prompted for a password:

```auto
ssh openhab@<myOpenHabServerIP>

```

However, if I modify this to access the Karaf Console, like:

```auto
# without explicitly defining the key
ssh openhab@<myOpenHabServerIP> -p 8101

# with specifying the key
ssh -i ~/.ssh/id_rsa openhab@<myOpenHabServerIP> -p 8101

```

…then, in both cases, I need to enter my password, although ~/.ssh/id\_rsa on my local computer holds my key.

I can also login to the openhab server shell (i.e. **not** the Karaf Console) when I explicitly refer to the key:

```auto
ssh -i ~/.ssh/id_rsa openhab@<myOpenHabServerIP>

```

Therefore, I assumed that when entering exactly the aforementioned command into openhab.karafCommand, at least I should properly login at the openhab server when opening the terminal window in VS Code.

However, it appears that my VS Code does not consider this command at all. The only thing that happens when opening terminal is that the profile of my zsh is executed and I am prompted to enter a command. The openhab.karafCommand is not executed at all.

Best regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 23, 2021, 6:24pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/5 "2021-03-23T18:24:52Z")

</div>

Yes, that’s the point I referred to…

For direct access to karaf, the command needs additional parameter -p8101 (as you already know).  
But the point is, karaf is not the openssh server from GNU/Linux, but another ssh server, builtin in karaf.

So, you have to add the public key to another file, not `.ssh/authorized_keys`, but instead in the file `$OPENHAB_USERDATA/etc/keys.properties`. Be aware that the format is different to `authorized_keys`  
There is an example in the file:

```auto
#karaf=AAAAB3NzaC1kc3MAAACBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv8iIDGZ3RSAHHAAAAFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QAAAIEA9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoAAACBAKKSU2PFl/qOLxIwmBZPPIcJshVe7bVUpFvyl3BbJDow8rXfskl8wO63OzP/qLmcJM0+JbcRU/53JjTuyk31drV2qxhIOsLDC9dGCWj47Y7TyhPdXh/0dthTRBy6bqGtRPxGa7gJov1xm/UuYYXPIUR/3x9MAZvZ5xvE0kYXO+rx,_g_:admingroup

_g_\:admingroup = group,admin,manager,viewer,systembundles

```

This is the username (would be openhab in openHAB2, or the username you chose when first starting openHAB3), followed by `=`, the key (between **=** and **,** ) and the correct group (should be `_g_:admingroup`)

The user is commented out as it’s an example 🙂 so don’t write the # in front of the username…

---

<div class="post-metadata">

**Author:** ![peter\_tau](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@peter\_tau](https://community.openhab.org/u/peter_tau)\
**Post date:** [March 23, 2021, 7:43pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/6 "2021-03-23T19:43:23Z")

</div>

Dear Udo,

Your comments helped me to access the Karaf Console without entering a password from the zsh shell of my desktop computer. Thank you very much. But the behavior inside VS Code remains unchanged, even after restarting both OpenHAB and VS Code.

I have entered the following configuration settings (of course with the real IP of the openhab server) in VS Code:

```auto
"openhab.karafCommand": "ssh -i ~/.ssh/id_rsa openhab@<OpenHabServerIP>",

```

Besides, I have also tried:

```auto
"openhab.karafCommand": "ssh -i ~/.ssh/id_rsa openhab@<OpenHabServerIP> -p 8101",

```

However, when switching to the terminal window in VS Code, I still receive a new line in the shell of my local desktop. There is no ssh command executed. Maybe I invoke the terminal functionality in a wrong way. I simply click on “Terminal” in the menu line where “Problems”, Output", “Debug Console” are listed right besides “Terminal”.

Best regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 24, 2021, 10:50am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/7 "2021-03-24T10:50:35Z")

</div>

Ah. No, you have to use the command:

ctrlshiftP, then type `openHAB: Open openHAB console` (you only have to type few letters and then click at the command)

Additionally, you can link a Shortcut to the command (I’m using ctrlshiftaltK)

---

<div class="post-metadata">

**Author:** ![pacive](https://community.openhab.org/user_avatar/community.openhab.org/pacive/32/36234_2.png) [@pacive](https://community.openhab.org/u/pacive)\
**Post date:** [March 24, 2021, 4:54pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/8 "2021-03-24T16:54:14Z")

</div>

Is there a reason you can’t/don’t want to use the remote ssh extension? That will give you the remote server’s console instead of the local.

---

<div class="post-metadata">

**Author:** ![peter\_tau](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/e99b99/32.png) [@peter\_tau](https://community.openhab.org/u/peter_tau)\
**Post date:** [March 24, 2021, 8:23pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/9 "2021-03-24T20:23:45Z")

</div>

Dear Udo and Anders,

Thank you both for your hints. I am now able to automatically open die Karaf Console via the OpenHAB extension (which does not work with Remote SSH because of the very specific SSH server of the Karaf Console) and Remote SSH allows me to get access to the OpenHAB server.

Best regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Confectrician](https://community.openhab.org/user_avatar/community.openhab.org/confectrician/32/105046_2.png) [@Confectrician](https://community.openhab.org/u/Confectrician)\
**Post date:** [March 27, 2021, 9:22am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/10 "2021-03-27T09:22:25Z")

</div>

Just for information:

You can also add keybindings to the conseole commands if you don’t want to use cmdshiftp all the time. 🙂

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 29, 2021, 5:23am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/11 "2021-03-29T05:23:30Z")

</div>

offtopic: how to create keys instead of text? (e.g. \<shift\> )?

---

<div class="post-metadata">

**Author:** ![Confectrician](https://community.openhab.org/user_avatar/community.openhab.org/confectrician/32/105046_2.png) [@Confectrician](https://community.openhab.org/u/Confectrician)\
**Post date:** [March 29, 2021, 6:47pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/12 "2021-03-29T18:47:49Z")

</div>

You can do that with the keyboard `<kbd>BLABLUB</kbd>` html tag. 🙂

```auto
<kbd>cmd</kbd><kbd>shift</kbd><kbd>p</kbd>

```

will result in cmdshiftp

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 29, 2021, 6:53pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/13 "2021-03-29T18:53:39Z")

</div>

Ah, cool! Thanks.

---

<div class="post-metadata">

**Author:** ![Jonas88](https://community.openhab.org/user_avatar/community.openhab.org/jonas88/32/92069_2.png) [@Jonas88](https://community.openhab.org/u/Jonas88)\
**Post date:** [December 23, 2022, 4:28pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/14 "2022-12-23T16:28:09Z")

</div>

Hello

is there a way to get this working with docker?  
it kinda bugs me that i have to ssh into my synology first and then use

```csv
docker exec -it openhab /openhab/runtime/bin/client

```

the rest api is working in vscode. the terminal would be great to use openhab:send  
or is there another way of making changes to items? i can see the current values when hovering over them.

regards

jonas

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [December 24, 2022, 12:40pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/15 "2022-12-24T12:40:02Z")

</div>

Well, there are some ways to do it…  
MY preferred method:

1. create a public/private key pair (`ssh-keygen ...`) You may or may not set a password for the key.
2. copy the content of the public key into the file `openhab_userdata/etc/keys.properties` and add a reasonable username and group (there is an example in the file)
3. deactivate the password login for Karaf user `openhab` (in `openhab_userdata/etc/users.properties` delete or comment out the user `openhab`)
4. open the karaf console for remote access via `openhab_userdata/etc/org.apache.karaf.shell.cfg` (set `sshHost` to `0.0.0.0`)
5. add port `8101` to open container ports.
6. use ssh `<username>@<docker-server> -i <path to private key> -p8101` to connect directly to the console.

---

<div class="post-metadata">

**Author:** ![Jonas88](https://community.openhab.org/user_avatar/community.openhab.org/jonas88/32/92069_2.png) [@Jonas88](https://community.openhab.org/u/Jonas88)\
**Post date:** [December 24, 2022, 1:00pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/16 "2022-12-24T13:00:45Z")

</div>

Udo, as always thanks for your great reply. I really appreciate it!  
I will try it tomorrow.  
I wish you happy holidays!

---

<div class="post-metadata">

**Author:** ![Jonas88](https://community.openhab.org/user_avatar/community.openhab.org/jonas88/32/92069_2.png) [@Jonas88](https://community.openhab.org/u/Jonas88)\
**Post date:** [December 24, 2022, 6:44pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/17 "2022-12-24T18:44:02Z")

</div>

Thank you so much it works!

Are the changes to the properties files persistent or do i have to change them again after an update?

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [December 25, 2022, 12:57am UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/18 "2022-12-25T00:57:27Z")

</div>

The files belong to userdata, so it should be persistent.  
But please always keep in mind, that _sometimes_ even userdata files can be changed via upgrade, apt should pause in that occasion and ask wether the file should be altered to the new one or stay as the old one.  
If the file is changed, the old version will be renamed to \*.dpkg-old.  
if the file is not changed, the new file will be stored as \*.dpkg-dist, so nothing is lost.

I’m not sure about docker, as the software won’t be “upgraded” but the image is changed to a newer one, in this case the configuration should stay as is, because openHAB will only check if a file does not exist, not, if it’s “too old”.

---

<div class="post-metadata">

**Author:** ![Jonas88](https://community.openhab.org/user_avatar/community.openhab.org/jonas88/32/92069_2.png) [@Jonas88](https://community.openhab.org/u/Jonas88)\
**Post date:** [February 17, 2023, 2:42pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/19 "2023-02-17T14:42:42Z")

</div>

Hello

it broke a while ago unfortunately and in addition to that i could not connect from my mac either.  
I checked the files and recognized the dns was wrong so i reset it to 0.0.0.0.  
The rest of the config was right and i can connect from my mac termianl using this: ssh [jonas@192.168.1.20](mailto:jonas@192.168.1.20) -i /Volumes/docker/openhab/id\_rsa -p8101 again.

set the same in the vscode but it just connects to my synology nas (where docker is installed) and not directly to the console - see images.

Do you have any idea what’s going wrong?

 ![Bildschirm­foto 2023-02-17 um 15.35.58](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/d/a/da91fe2da735dc287d8eabc9492638bb426f81f1.png)

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [February 17, 2023, 10:02pm UTC](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515/20 "2023-02-17T22:02:55Z")

</div>

> [@Jonas88](#):
>
> recognized the dns was wrong so i reset it to 0.0.0.0.

Nothing with DNS, I hope that only was a typo… `sshHost` has to be set to `0.0.0.0`, this is: Karaf will listen on every Ethernet Port, regardless which IP is set.

I don’t see your console issue (the picture is part of the settings.json.

[Next page](https://community.openhab.org/t/vs-code-terminal-window-how-to-automatically-ssh-to-openhab-server/119515.md?page=2)
