You must setup Lighttpd and Cloudflared first.

Steps

  1. create ttyd directory in $HOME
    mkdir -p ~/ttyd && cd ~/ttyd
    
  2. download latest version of ttyd and trzsz
    curl -LO "https://download.freaks.dev/compiled/ttyd"
    latest=$(basename $(curl -fs -o/dev/null -w %{redirect_url} https://github.com/trzsz/trzsz-go/releases/latest))
    curl -LO "https://github.com/trzsz/trzsz-go/releases/download/${latest}/trzsz_${latest#v}_linux_x86_64.tar.gz"
    tar -xzf trzsz_${latest#v}_linux_x86_64.tar.gz
    mv trzsz_${latest#v}_linux_x86_64/* ~/.local/bin/
    rm -r trzsz*
    
  3. copy from ttyd.service
    nano ttyd.service
    
  4. start ttyd service
    cp ~/ttyd/ttyd.service ~/.config/systemd/user/
    systemctl --user daemon-reload
    systemctl --user enable --now ttyd
    
  5. copy from ttyd.conf
    nano ~/lighttpd/conf.d/ttyd.conf
    
  6. create auth for ttyd
    printf "<username>:$(openssl passwd -6 <password>)" > ~/lighttpd/passwd/.ttyd
    
  7. restart lighttpd
    systemctl --user restart lighttpd
    

ttyd.service

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

[Service]
Restart=always
ExecStart=%h/ttyd/ttyd -p 1341 -i lo -o -t enableTrzsz=true -t fontSize=16 bash

[Install]
WantedBy=default.target

ttyd.conf

$HTTP["host"] == "ttyd.example.com" {
    auth.backend = "htpasswd"
    auth.backend.htpasswd.userfile= env.HOME + "/lighttpd/passwd/.ttyd"
    auth.require = ( "" =>
    (
    "method"  => "basic",
    "realm"   => "Restricted!",
    "require" => "valid-user"
    ),
)
    proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "1341" ) ) )
    proxy.header = ( "upgrade" => "enable" )
}