One-click SSH terminals, in WEB-browser, on a Home Assistant dashboard with ttyd

I wanted a few buttons on my Home Assistant (HA) dashboard that open an SSH session to my servers, so I could jump straight to the password prompt without opening a terminal, typing "ssh user@server.local" and so on. It turned out to be a bit harder than expected, but the solution is simple, lightweight and works with any browser on the LAN.

The standard "Terminal & SSH" add-on can't be used for this. It only opens as an interactive window and doesn't accept any command or parameters from a button. My first idea, the Proxmox web console, had another catch described below. The solution is ttyd, a tiny program that shares a terminal over the web, with one button per target in HA.

Intro
Why not the Terminal & SSH add-on?
The add-on opens a ttyd terminal inside HA, but there is no way to pass "
ssh user@server.local" from a button. You can make the terminal start ssh automatically with init_commands, but then every button opens the same server. With several servers you need one terminal per target.

Why not the Proxmox console?
The Proxmox console can be opened with a direct link in a new tab, for example:
https://192.nn.nn.nn:8006/?console=shell&xtermjs=1&vmid=0&vmname=&node=proxmox&cmd=
It works nicely if you have just logged in to the Proxmox GUI. If not, you get "Connection failed (Error 401: No ticket)". The console needs the login cookie (ticket) from the GUI, which is valid for about two hours, and as far as I can find there is no way around it. So the Proxmox console is great for a quick look, but not for a reliable button.

Install ttyd
I run ttyd in a small LXC on my Proxmox host. It could be any Linux machine that can reach your targets over SSH.

On my Debian 13 (trixie) LXC, apt install ttyd gave "
Unable to locate package", so I used the binary from the releases page. It is a static build without dependencies. The latest version, when writing, is 1.7.7. Check your architecture with "uname -m". My Mac mini (2018) is Intel, so I need ttyd.x86_64 (use ttyd.aarch64 for a Raspberry Pi 4/5).

sudo wget https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 -O /usr/local/bin/ttyd
sudo chmod +x /usr/local/bin/ttyd
ttyd --version

Start a terminal by hand first
ttyd -W -p 7681 -c admin:mypassword ssh user@server.local
  • -W makes the terminal writable. From version 1.7.4 it is read-only by default, which is a classic "why can't I type?" moment.
  • -p 7681 is the port. Every instance needs its own port.
  • -c admin:mypassword is basic authentication for the web page. If you skip it anyone on your LAN who finds the port gets a terminal.
  • ssh user@server.local is the command ttyd runs in the terminal.
Open"http://your-ttyd-host:7681" in a browser. After the web login, if you choose that, you land directly on the SSH password prompt.

Run it as a service
Create "sudo nano /etc/systemd/system/ttyd-server1.service" and add 

[Unit]
Description=ttyd ssh server1
After=network-online.target

[Service]
ExecStart=/usr/local/bin/ttyd -W -p 7681 -c admin:mypassword ssh user@server.local Restart=always

[Install]
WantedBy=multi-user.target

and then 

sudo systemctl daemon-reload
sudo systemctl enable --now ttyd-server1
sudo systemctl status ttyd-server1

Make a copy per target with a new port (7682, 7683, ...).

The HA button
Add a manual card to the dashboard: 

type: button
name: SSH server1
icon: mdi:console
tap_action:
    action: url 
    url_path: http://your-ttyd-host:7681

The button opens a new tab. Use "action: url" and don't try to embed the terminal in the dashboard. If HA runs over https and ttyd over http the browser blocks it.

Many targets, one ttyd (optional)
With many servers, VMs and LXCs, one service per target gets tedious. The flag -a lets the URL pass an argument to the command, so a single ttyd can serve all targets. Don't pass raw ssh arguments from the URL, since ssh options like ProxyCommand can run arbitrary commands on the ttyd machine. Let a small script translate a short name to a fixed target instead. Create "sudo nano /usr/local/bin/sshgo" and add 

#!/bin/bash
case "$1" in
    server1) exec ssh user@192.nn.nn.10 ;;
    server2) exec ssh user@192.nn.nn.11 ;;
    proxmox) exec ssh root@192.nn.nn.202 ;;
    lxc101) exec ssh -t root@192.nn.nn.202 pct enter 101 ;;
    *) echo "Unknown target: $1"; sleep 5 ;;
esac

and 

sudo chmod +x /usr/local/bin/sshgo

Create a new servis file as above but change the "ExecStart....." line to "ExecStart=/usr/local/bin/ttyd -W -a -p 7690 -c admin:mypassword /usr/local/bin/sshgo"

And the button

type: button
name: LXC 101
icon: mdi:cube-outline
tap_action:
    action: url 
    url_path: http://your-ttyd-host:7690/?arg=lxc101

"pct enter 101" logs you in as root in the container directly from the Proxmox host, so the LXC doesn't need an SSH server. A VM needs its own SSH server and you connect to the VM's IP.

Check the Magic !
Press the button in HA. A new tab opens, you log in to the web terminal once per browser session, and you are at the SSH password prompt.

Good to know
  • status=203/EXEC: If systemd says this, the path in ExecStart is wrong. I had /usr/bin/ttyd in the service file but the binary was in /usr/local/bin. After fixing it, run systemctl daemon-reload and systemctl reset-failed ttyd-server1, otherwise systemd may refuse to start it again ("Start request repeated too quickly"). 
  • Can't reach it from HA or another machine? The 1.7.4 release notes say the port is no longer exposed publicly by default. Try -i with the machine's LAN IP, for example -i 192.nn.nn.50. 
  • Two passwords: The -c password protects the web page. The SSH password is typed in the terminal as usual. For a quicker login you can use SSH keys instead, but then the web password is the only protection, so keep it strong. 
  • Keep it on the LAN: Don't forward these ports in your router. ttyd gives a terminal to your servers, so use it only on a trusted network, or put it behind a VPN or reverse proxy with proper authentication.
  • The picture above shows the ssh buttons together with server info, this blogpost, and internet speed data from this blogpost.

Created together with Claude !!

Comments

Popular posts, last 30 days

IKEA Bäve dimmer hack II

Clone the Raspberry boot disk

IVT, Bosch heat pump easy integration, Home Assistant

Installing Ubuntu 24.04 or 26.04 on an old MacBook Air(2011)

Raspberry Pi OS Lite with GUI, RDP, VNC, Chromium

OpenPlotter V2, install guide

SeaTalk1 to NMEA 0183 converter, DIY

iCloud drive sync, or mount, with a Linux, Ubuntu, device

Raspberry Pi watchdog made simple