Last active
July 4, 2025 16:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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