Windows – Use ~.ssh/config to always set TERM=cygwin for certain hosts

environment-variablessshwindows server 2008

I use WinSSHd on several Windows servers. To access them from my Mac (and presumably, just about any Unix-based terminal), I need to set the TERM environment variable to cygwin, e.g.:

TERM=cygwin ssh

I can also use the .ssh/config to set certain defaults for that server, such as a different user and non-default port:

    User SomeDifferentDude
    Port 22222

However, I apparently can't set environment variables that way. I haven't found anything in man ssh_config, anyway. Is there a way to set the default terminal emulation (and/or any environment variable) per host?

Best Answer

  • You would typically set the environment variable on the server side.

    If WinSSHd is sufficiently like openssh (the usual unix implementation of ssh), you can define an environment file (~/.ssh/environment on unix) and put TERM=cygwin there.

    You can also set the environment variable in your shell initialization file. Since you mention cygwin, this is presumably ~/.bash_profile where ~ is your cygwin home directory. You should set it conditionally, in case you also use cygwin on other terminal types; for example, to set it only if you are logging in over ssh (again, assuming WinSSHd is sufficiently like openssh):

    if [ -n "$SSH_CLIENT" ]; then
      export TERM=cygwin