Start tmux automatically when connecting via SSH

tmux is a beautiful terminal application, which is able to survive disconnections.
But I ofte forget to start it, when I connect to a server via SSH.
I found this solution on the internet, unfortunately I cannot remember where, so I cannot give kredit to the originator.
However: put this at the end of your bashrc, ant it will start a tmux session, if one doesn’t exists, and connect to a session that already exists.

if [[ -n “${SSH_TTY}” ]] && [[ “${TERM}” != “tmux-256color” ]]; then tmux attach || tmux && exit
fi

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *