40

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?

5 Answers5

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'
Johan
  • 309
17

On 2021-06-04, "allow ssh_config SetEnv to override $TERM" was committed to openssh-portable, which sounds like it will let you set SetEnv TERM in ~/.ssh/config, such as in a Host directive. (Or it will let you as soon as a release is cut with this patch, presumably.)

dsedivec
  • 416
10
TERM=vt100 ssh some.host.name

On remote, execute echo $TERM.

O G
  • 944
10

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).

Edit:

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

SendEnv
             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".

Paweł Brodacki
  • 6,591
  • 1
  • 22
  • 23
6

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 "$@"
   else
     ssh "$@"
   fi
}

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

docwhat
  • 232