Skip to content

Instantly share code, notes, and snippets.

@mikalv
Forked from madars/public-tmux
Created January 29, 2022 15:51
Show Gist options
  • Save mikalv/a3f8f415b477e5590521b86f1239dc31 to your computer and use it in GitHub Desktop.
Save mikalv/a3f8f415b477e5590521b86f1239dc31 to your computer and use it in GitHub Desktop.
A read-only tmux session for demos and remote debugging
#!/bin/sh
# To be used with something like this in sshd_config:
#
# Match User public-tmux
# X11Forwarding no
# AllowTcpForwarding no
# PasswordAuthentication yes
# ForceCommand /usr/bin/tmux -S /tmp/public-tmux-socket attach -r -t public
#
SOCKET=/tmp/public-tmux-socket
if tmux -S $SOCKET list-sessions 2>/dev/null | grep -q ""; then
echo "The socket at $SOCKET already has sessions, attaching..."
exec tmux -S $SOCKET attach -t public
else
echo "Creating a new tmux session with socket at $SOCKET and changing it to be world-writeable..."
exec tmux -S $SOCKET new-session -s public "chmod o=w $SOCKET; $SHELL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment