Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

TERM=vt100 ssh some.host.name

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

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

share|improve this answer
1  
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
1  
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 "$@"
   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.

share|improve this answer

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

 
discard

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