Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do want to use tmux by default when I am establshing ssh connection and this works well with a command like:

ssh -t 'tmux a || tmux || /bin/bash'

I can even put this as part of the ProxyCommand inside the ~/.ssh/config but the problem is that I am also doing SSH connections as part of scripts that are just running different commands on the remote machines and I do not want tmux in this case.

How can I achieve this behaviour so tmux invocation would be transparent and happen only when ssh is colled without any paramerts / commands.

share|improve this question

You're re-inventing the wheel.

  • Install Byobo.
  • byobu-enable
share|improve this answer

Solved by adding this to ~/.bashrc:

function ssh() {
  if [ "$#" == "1" ]; then
    if [ "${1:0:1}" != "-" ]; then
      /usr/bin/ssh "$@" -t 'tmux a || tmux || /bin/bash'
    /usr/bin/ssh "$@";
    /usr/bin/ssh "$@";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.