Skip to content

Instantly share code, notes, and snippets.

@alloydwhitlock
Created March 10, 2015 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloydwhitlock/758fc8badfec04dc51e9 to your computer and use it in GitHub Desktop.
Save alloydwhitlock/758fc8badfec04dc51e9 to your computer and use it in GitHub Desktop.
Start & attach tmux session on SSH login
# Add this line to a user's ~/.bashrc to automatically attach a tmux session upon login.
# Credit goes to William Shallum for writing this gist (http://william.shallum.net/random-notes/automatically-start-tmux-on-ssh-login)
if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
STARTED_TMUX=1; export STARTED_TMUX
sleep 1
( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0
echo "tmux failed to start"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment