Skip to content

Instantly share code, notes, and snippets.

@mahasak
Last active January 4, 2024 09:04
Show Gist options
  • Save mahasak/60d89128d65f9e57eabdd4847a63cae9 to your computer and use it in GitHub Desktop.
Save mahasak/60d89128d65f9e57eabdd4847a63cae9 to your computer and use it in GitHub Desktop.
Reattach to tmux over ssh connection
# inside your .bashrc or .zshrc (on the server side) add:
# start tmux if we ssh into the box
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
tmux attach-session -t $USER || tmux new-session -s $USER
fi
# this will attach to an ongoing tmux session or start a new one
# the session name will be the name of the user ($USER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment