I use this setting in ~/.ssh/config:

Host server
  Hostname 192.168.x.x
  SetEnv TERM=xterm

But when logging in to the server and doing echo $TERM, I get xterm-256color.

How to set TERM from ssh client config file?

What is curious: when connecting as TERM=xterm ssh server, echo $TERM on server gives xterm. Although this shows that the setting can be transmitted, it does not solve the problem, because I need to set it in config file. Also, putting TERM=xterm in .ssh/environment on server sets it, but it does not solve the problem either, because I cannot edit anything on server.

  • 1
    I'm wondering this as well, but ended up just creating an alias like so: alias ssh='env TERM=xterm ssh' in my .bashrc. I know it's a hack, but it's good enough for my purpose (i.e. st-256color not being recognized by older hosts). Aug 28, 2019 at 11:55

3 Answers 3


Since OpenSSH 8.7 (2021-08-20), SetEnv TERM is now supported:

allow ssh_config SetEnv to override $TERM, which is otherwise handled specially by the protocol. Useful in ~/.ssh/config to set TERM to something generic (e.g. "xterm" instead of "xterm-256color") for destinations that lack terminfo entries.


Adjusting the configuration to this can be used as a workaround:

Host server
  Hostname 192.168.x.x
  RemoteCommand TERM=xterm $SHELL
  RequestTTY yes

Probably worthwhile mentioning it comes with a caveat; the section will no longer work when explicitly giving a command as an argument to ssh, or with sftp, sshfs etc.

  • Add -l at the end of the remote command to get a login shell like by default. Jun 16, 2021 at 10:25

Only TERM must decide here - one is not supposed to configure that in ssh in any way. One way to deal with this is to use proper terminal (one that uses TERM=xterm). Another way is to create ssh wrapper and check name of desired host in it and in case of match check if TERM is xterm-compatible, and if yes, do export TERM=xterm before exec ssh "$@". One may also use the hack to set TERM=xterm in .ssh/environment on server (assuming that only xterm-compatible terminal will be used to connect to the server).

Use this command:

TERM=xterm ssh host

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.