My Setup

Mac OS runs terminal with $TERM = xterm-256color; tmux with $TERM = xterm-256color

When I ssh into an AWS EC2 inside that tmux session on my MacOS, $TERM is also xterm-256color

Weird Behavior

When I use tmux on my MacOS and then ssh into an EC2, I experience this behavior: sometimes when I hit space, the previous character is duplicated.


Does anybody know how to fix this? I'd rather change up the TERM on my Mac rather than my EC2's.


This is why I set TERM environment the way I'm having it now. I'm not sure about the reason behind it.

  • Curious: why do you think that the TERM setting is relevant?
    – roaima
    Jun 17, 2020 at 0:23
  • 1
    I ran into another problem with tmux that messed up terminal's rendering. The fix for that was setting the TERM variable. The guy who helped me pointed out that issues like these are likely related to the TERM variable so I included that info in here.
    – Tran Triet
    Jun 17, 2020 at 0:36
  • Is the duplication just a visible artefact or does it get included in the text the shell receives and processes?
    – roaima
    Jun 17, 2020 at 7:32
  • 1
    The duplication gets included in the text that the shell receives. (e.g. If I visibly see that duplication and then press enter, the duplicated is sent to shell which will most commonly trigger an unknown command error).
    – Tran Triet
    Jun 17, 2020 at 14:17

1 Answer 1


The TERM variable (set within the tmux session) is going to produce problems. tmux doesn't support the full set of xterm features that are used in that terminal description. Which one you're tripping over is hard to determine because of the lack of information in the question.

The tmux manual is the place to start:

The TERM environment variable must be set to ‘screen’ or ‘tmux’ for all programs running inside tmux. New windows will automatically have TERM=screen added to their environment, but care must be taken not to reset this in shell start-up files or by the -e option.

although the manual page could use some attention in discussing how to properly configure tmux if the outer terminal has TERM=xterm-256color.

  • The realized upon terminal most likely properly corresponds to TERM=iTerm.app or similar anyway.
    – JdeBP
    Jun 17, 2020 at 9:16
  • @Thomas I don't specifically set the TERM for shells inside my tmux session. In this case, my EC2 just have that TERM setup that way, I didn't. If I understand your answer correctly, then I'll have to make sure the TERM variable in my EC2 is set to 'screen' or 'tmux'. Is there anyway to avoid this? I don't want to have to do this for all the machines I connect to and potentially mess up for other people who access these machines.
    – Tran Triet
    Jun 17, 2020 at 17:29
  • Ideally your TERM is set on the local machine and passed through to the remote machines. The only reason you should be setting TERM in a shell's initialization is for the (rare) case that you' re connecting via something that is unable to provide this information. Jun 17, 2020 at 18:33
  • Right now, I don't specifically set TERM for my EC2 instances. From your answer, I understand that I should set the TERM on my laptop shell inside TMUX to be 'screen' or 'tmux'. And that's it. Is that correct?
    – Tran Triet
    Jun 19, 2020 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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