Skip to content

Instantly share code, notes, and snippets.

@madars
Created April 30, 2020 01:46
Show Gist options
  • Save madars/e6b957ea508be1dcd9044fd2c70969ac to your computer and use it in GitHub Desktop.
Save madars/e6b957ea508be1dcd9044fd2c70969ac 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