Server Fault is a question and answer site for system and network administrators. 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

On my local terminal, I have TERM=konsole-256color, but not all remote machine I connect to have this definition.

Is it possible to make ssh change the TERM on remote machine? Without changing .bash* scripts on remote machine, just by changing configuration on my local desktop?

share|improve this question
TERM=vt100 ssh

On remote, execute echo $TERM.

share|improve this answer
I though about it, but I want it set only for a subset of hosts I ssh to, so issuing TERM=... ssh all the time will not work. and remembering which hosts have old termcap info, and then changing command on the fly is not nice either. – user13185 Aug 17 '11 at 16:48
Per-host configuration is supported only in /etc/ssh/ssh_config, however I know of no configuration value to support terminal schema mapping per host. – O G Aug 17 '11 at 16:53
It can also be done in ~/.ssh/config, which I know, but I also can't find any option to modify environment sent to remote server. Was hoping that I missed something. – user13185 Aug 17 '11 at 17:03

man ssh:

     ssh reads ~/.ssh/environment, and adds lines of the format
     “VARNAME=value” to the environment if the file exists and users are
     allowed to change their environment.  For more information, see the
     PermitUserEnvironment option in sshd_config(5).


Rats, I hoped it could be on the local side, still, if there's a will, there's a way. man ssh_conf:

             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.

Depending on the configuration of sshd on the receiving end this may or may not fulfil the requirement of "no remote file modification".

share|improve this answer
Yes, but this is configuration on remote side, and I need/want something that changes only on local end. – user13185 Aug 17 '11 at 16:47
SendEnv is not related. It can possibly send additional env variables, but: 1. it cannot modify them, and 2. TERM is sent anyway, even if it's not listed in SendEnv. – user13185 Aug 17 '11 at 19:52

Here's my quick and dirty solution I just threw together. I'd prefer something better. I guess I could use a shell script instead. Adjusting TERM values is left as an exercise to the reader.

# To move into a separate plugin...
function ssh {
   if [[ "${TERM}" = screen* || konsole* ]]; then
     env TERM=screen ssh "$@"
     ssh "$@"

Ideally, it would do something like check the TERMs on the other side, using the ControlPersist stuff to prevent long delays for multiple connections.

share|improve this answer
Thanks! I did something like this, but instead of checking for specific values of $TERM with an if/else construct, I'm using $(echo -n "$TERM" | sed -e s/tmux/screen/) to unconditionally replace the problematic "tmux" in my local term with the more universally accepted "screen" type (source here). – wincent Dec 1 '15 at 20:20

I have added the following alias to my .bashrc file. It uses O G's answer but wraps it in an alias. Works like a charm ;)

# Force xterm-color on ssh sessions
alias ssh='TERM=xterm-color ssh'
share|improve this answer

Your Answer


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