Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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'm trying to run tmux sessions inside and outside of a remote ssh session, so I want to use c-b prefix for the outer (local) session and c-a prefix inner (remote) session.

My question is how can it be done with a single tmux.conf. It's easy to check with bash if the session is remote using something like [ -n "$SSH_CLIENT" ], but I don't know how to reliably incorporate this into tmux.conf, given that if appears to be asynchronous and subject to race conditions.

share|improve this question

I made a workaround via .bash_profile:

if [[ -n "$SSH_CLIENT" && -n "$TMUX" ]] ; then
  tmux unbind c-b
  tmux set -g prefix c-a
  tmux bind c-a send-prefix

It makes sure the c-a prefix is only set if the shell is running in a remote tmux window. Seems to work okay, but it would still be cleaner if it could be expressed in tmux.conf.

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.