Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 currently using Fedora 18 gnome-terminal, then started tmux multiplexer in it. After I connected to a CentOS 5 server via ssh command, I find:

  • ls result has no color
  • tmux, screen, hexedit, htop all failed to start with error message like:
    open terminal failed: missing or unsuitable terminal: screen-256color

It seems that ssh passes the $TERM environment variable to the server, but I can't find it in /etc/ssh/ssh_config file of Fedora 18.

Although I can manually change the $TERM variable on the server, each time I connect, it happens again. So how to prevent it?

share|improve this question
up vote 10 down vote accepted

$TERM is to tell applications what terminal they're talking to so they know how to talk to it.

Change it to a value supported by the remote host and that matches as closely as possible your terminal (screen).

Most Linux systems should at least have a screen terminfo entry. If not, screen implements a superset of vt100 and vt100 is universal. So:

TERM=screen ssh host


TERM=vt100 ssh host

If you do need the 256 color support, you could try xterm-256color which should be close enough (screen supports 256 colors the same way xterm does) and tell applications your terminal application supports 256 colors and tell them how to use them.

Or you can install the terminfo entry on the remote host.

infocmp | ssh -t root@remote-host 'cat > "$TERM.info" && tic "$TERM.info"'
share|improve this answer
good to know infocmp and tic, once compiled, no need to temporarily change $TERM again. by the way, i just copied (rsync) /usr/share/terminfo/s/screen-256color from Fedora 18 to CentOS, it seems works ok (rsync -tv /usr/share/terminfo/s/screen-256color root@the_host:/usr/share/terminfo/s). – LiuYan 刘研 Mar 11 '13 at 11:14
forgot to mentioned, i ran tmux in gnome-terminal of Fedora 18, tmux changed $TERM value to screen-256color from xterm-256color. – LiuYan 刘研 Mar 11 '13 at 11:18
btw, can ssh works in this way: get the terminfo which host/server supported (not pushed into), then pickup one the client terminal can support? – LiuYan 刘研 Mar 11 '13 at 11:37
I found it amusing that this infocmp piped through ssh thing left a file called dumb.info in my home dir. – Dmitri DB May 18 '14 at 5:45

Related to the answer given by Stephane Chazelas, in my case I simply added an alias to my .zshrc (.bashrc if using bash) on my local desktop: alias ssh='TERM=xterm ssh'

If you already use an alias, adjust it to include the Environment assignment.

share|improve this answer
alias is a nice trick, thanks! – LiuYan 刘研 Apr 25 '14 at 16:57

See man ssh_config:

         Specifies what variables from the local environ(7) should be sent
         to the server.  Note that environment passing is only supported
         for protocol 2.  The server must also support it, and the server
         must be configured to accept these environment variables.  Refer
         to AcceptEnv in sshd_config(5) for how to configure the server.
         Variables are specified by name, which may contain wildcard char‐
         acters.  Multiple environment variables may be separated by
         whitespace or spread across multiple SendEnv directives. The
         default is not to send any environment variables.

and man sshd_config:

         Specifies what environment variables sent by the client will be
         copied into the session's environ(7).  See SendEnv in
         ssh_config(5) for how to configure the client.  Note that envi-
         ronment passing is only supported for protocol 2.  Variables are
         specified by name, which may contain the wildcard characters `*'
         and `?'.  Multiple environment variables may be separated by
         whitespace or spread across multiple AcceptEnv directives.  Be
         warned that some environment variables could be used to bypass
         restricted user environments.  For this reason, care should be
         taken in the use of this directive.  The default is not to accept
         any environment variables.

According to that, the default should be not to send any variables, but TERM seems to be special. It is send anyway.

Therefore you can either change TERM when calling ssh (like TERM=xterm ssh ...), change it after login (like in .bash_profile), or define the unknown TERM type on server side (assuming you have root access there). See other answer for details.

share|improve this answer
Not setting $TERM will not really be any better than setting it to an unsupported value though. – Stéphane Chazelas Mar 11 '13 at 7:47
The literal question was, how to prevent sending TERM. - Answer: You cannot. - What he should do is setting it to a suitable value, yes. – michas Mar 11 '13 at 7:56
change $TERM temporarily may be a workaround, but i need to do it each time. by the way, it seems that both CentOS 5 and Fedora 18 AcceptEnv all locale environment variables (LANG, LC_*, ...) – LiuYan 刘研 Mar 11 '13 at 10:27

I put this in my .bashrc on the remote host:

# 256-color mode not supported on this host
if echo $TERM | grep -q -- '-256color'; then
    echo -e '\n\n256-color mode not supported on this host.  Reverting TERM...\n'
    export TERM=`echo -n $TERM | sed 's/-256color//'`

That way, both xterm-256color and screen-265color are handled properly. Also, I have it output the note so that if the server gets upgraded later and supports 256 colors, I won't end up banging my head against the wall wondering why my TERM variable gets changed when SSHing.

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.