Skip to content

Instantly share code, notes, and snippets.

@eamonburns
Last active July 4, 2025 16:49
Show Gist options
  • Select an option

  • Save eamonburns/ef5e8d68d5d2b831b536c226a5f1eeff to your computer and use it in GitHub Desktop.

Select an option

Save eamonburns/ef5e8d68d5d2b831b536c226a5f1eeff to your computer and use it in GitHub Desktop.
A simple bash snippet to add to the end of your `.bashrc` to automatically enter tmux when you login through SSH
# Automatically start tmux for ssh connections
# This will _unconditionally_ run tmux. If tmux may not be available (e.g. you use the same .bashrc
# for multiple systems), you can wrap it in an if statement:
#
# if command -v tmux >/dev/null 2>&1; then
# ...
# fi
# is interactive, is not in tmux, is in ssh
if [[ "$-" == *i* ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_TTY" ]]; then
# Start a tmux session (`-A`: attach if it already exists)
tmux new-session -A -s tmux-ssh
# Uncomment the following line to automatically exit bash after exiting/detaching from tmux
#exit
fi # MUST BE END OF FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment