# Tmux interactive session app

**URL:** <https://discourse.openondemand.org/t/tmux-interactive-session-app/1409>\
**Category:** Feature Requests and Roadmap Discussion\
**Created:** [April 2, 2021, 2:03pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409 "2021-04-02T14:03:37Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![kevinlee](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@kevinlee](https://discourse.openondemand.org/u/kevinlee)\
**Post date:** [April 6, 2021, 5:05pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/21 "2021-04-06T17:05:07Z")

</div>

I followed an analog very close to what is done for the authentication helper that was done for the RStudio bc app

Basically swap the plaintext user:password call with

`-a /path/to/bin/auth`

And then write the auth to verify against a cached shell `TTYD_PASSWORD` password

One other notable bit is that I needed to stash the full `tmux <with all the opts>` command in another file, and let the `/bin/auth` call this file.

I’m still not quite finalized as I’m thinking this through, but I can reach out to you offline to discuss this potential solution.

-Kevin

---

<div class="post-metadata">

**Author:** ![kevinlee](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@kevinlee](https://discourse.openondemand.org/u/kevinlee)\
**Post date:** [April 22, 2021, 1:46pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/22 "2021-04-22T13:46:18Z")

</div>

I did end up reaching out to @nvonwolf (thanks) and ultimately the solution at our site was to modify ttyd to support a simple file credential option, which still uses http basic authentication. Then I still use [https://gitlab.com/nmsu\_hpc/ood\_bc\_shell](https://gitlab.com/nmsu_hpc/ood_bc_shell) the repo here but with minimal changes.

My fork currently has the changes that were done, and I plan on submitting a PR upstream to ttyd in the future.

> **[tsl0922/ttyd](https://github.com/tsl0922/ttyd/compare/main...kmanalo:main)**
>
> re/main...kmanalo:main

---

<div class="post-metadata">

**Author:** ![carnoldvt](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/carnoldvt/32/663_2.png) [@carnoldvt](https://discourse.openondemand.org/u/carnoldvt)\
**Post date:** [April 22, 2021, 2:26pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/23 "2021-04-22T14:26:44Z")

</div>

@kevinlee very cool, that is a great alternative.

Here is what I ended up doing, which is similar to what others. I created a simple shell script that replaces the tmux command that checks the password from an environment variable. The password is sent as arg in the URL. For our case we don’t mind having the session password in the URL: /node/%host%/%port%/?arg=%password%

```auto
#before.sh.erb
# Find available port to run server on
export port=$(find_port ${host})
# Export compute node the script is running on
export host="${host}"
# Generate SHA1 encrypted password (requires OpenSSL installed)
export password="$(create_passwd 20)"
# Define tmux socket name
export tsock="<%= session.id %>.sock"
# Define tmux session name
export tses="<%= session.id %>"

```

```auto
#!/usr/bin/env bash
#script.sh.erb
# Launch ttyd
/usr/local/bin/ttyd -a -p "${port}" -b "/node/${host}/${port}" <%= session.staged_root.join("tmux.sh") %>
# kill tmux session
tmux kill-session -t "$tses"

```

```auto
#!/usr/bin/env bash
#tmux.sh
# Set Working Directory To Home
cd "${HOME}"
# set the TERM
export TERM="xterm-256color"
# Launch tmux
if ["$1" == "$password"];then
    tmux -L "$tsock" new -A -s "$tses" '/bin/bash'
else
    echo Access Denied
    sleep 5
fi
exit

```

---

<div class="post-metadata">

**Author:** ![nvonwolf](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/nvonwolf/32/574_2.png) [@nvonwolf](https://discourse.openondemand.org/u/nvonwolf)\
**Post date:** [June 4, 2021, 7:47pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/24 "2021-06-04T19:47:32Z")

</div>

Kevin, did you ever submit that pull request to the ttyd project?

---

<div class="post-metadata">

**Author:** ![baverhey](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/baverhey/32/605_2.png) [@baverhey](https://discourse.openondemand.org/u/baverhey)\
**Post date:** [June 7, 2021, 9:50am UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/25 "2021-06-07T09:50:33Z")

</div>

> [@carnoldvt](#):
>
> ux command that checks the password from an environment variable. The password is sent as arg in the URL. For our case we don’t mind having the session password in the URL:

What are your minimal changes to [https://gitlab.com/nmsu\_hpc/ood\_bc\_shel](https://gitlab.com/nmsu_hpc/ood_bc_shell) app?

---

<div class="post-metadata">

**Author:** ![kevinlee](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@kevinlee](https://discourse.openondemand.org/u/kevinlee)\
**Post date:** [June 10, 2021, 12:14pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/26 "2021-06-10T12:14:46Z")

</div>

Hi @baverhey

I think the relevant changes are here, key point being that a password file is stored in the user’s session directory.

```auto
# Create password file
echo "ttyd:${password}" > "${sdir}/passfile.txt"

# Benchmark info
echo "TIMING - Starting ttyd at: $(date)"

<%- if context.tmux_config.to_s == "1" -%>
    $TTYD -p "${port}" -b "/node/${host}/${port}" -t fontSize=$fsize -t cursorStyle=underline -t cursorBlink=true -t 'theme={"background": "#282a36", "foreground": "#f8f8f2"}' -f "${sdir}/passfile.txt" $TMUX -f "$tconf" -L "$tsock" new -A -s "$tses"
<%- else -%>
    $TTYD -p "${port}" -b "/node/${host}/${port}" -t fontSize=$fsize -t cursorStyle=underline -t cursorBlink=true -t 'theme={"background": "#282a36", "foreground": "#f8f8f2"}' -f "{sdir}/passfile.txt" $TMUX -L "$tsock" new -A -s "$tses"
<%- end -%>

```

---

<div class="post-metadata">

**Author:** ![kevinlee](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@kevinlee](https://discourse.openondemand.org/u/kevinlee)\
**Post date:** [June 10, 2021, 12:17pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/27 "2021-06-10T12:17:56Z")

</div>

@nvonwolf I finally submitted it. I forgot since I recompiled against my fork and deployed at our site and got sidetracked…

> <https://github.com/tsl0922/ttyd/pull/700>
>
> This is a simple extension of the credential option, but in file form. Essentia…lly, it's a passthrough to credential.
> 
> This was important to use for a related project where the credential option is mandated but at the same time we did not want to share the plain text password on the CLI because of multi-tenant sharing on the same server.

We finally have this app in a pre-production setup 🎊 with an OOD deployment to all users later this summer.

---

<div class="post-metadata">

**Author:** ![westburg.2](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@westburg.2](https://discourse.openondemand.org/u/westburg.2)\
**Post date:** [May 26, 2022, 4:11pm UTC](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409/28 "2022-05-26T16:11:34Z")

</div>



[Previous page](https://discourse.openondemand.org/t/tmux-interactive-session-app/1409.md?page=1)
