When checking whether the iTerm protocol is available, check the LC_TERMINAL environment variable in addition to TERM_PROGRAM. LC_TERMINAL is passed to many remote hosts; read on for details.
iTerm2 sets the environment variable LC_TERMINAL to iTerm2. This is useful because on Debian and Ubuntu systems*, the default /etc/ssh/sshd_config contains the line:
AcceptEnv LANG LC_*
That is, if the ssh client sends the LC_TERMINAL variable, it will be added to the login environment. macOS has this configuration in /etc/ssh/sshd_config.d/100-macos.conf as well. macOS's default /etc/ssh/ssh_config contains
Host *
SendEnv LANG LC_*
so macOS ssh clients all pass LC_TERMINAL. Debian and Ubuntu do this too.
When checking whether the iTerm protocol is available, check the
LC_TERMINAL
environment variable in addition toTERM_PROGRAM
.LC_TERMINAL
is passed to many remote hosts; read on for details.iTerm2 sets the environment variable
LC_TERMINAL
toiTerm2
. This is useful because on Debian and Ubuntu systems*, the default/etc/ssh/sshd_config
contains the line:That is, if the ssh client sends the
LC_TERMINAL
variable, it will be added to the login environment. macOS has this configuration in/etc/ssh/sshd_config.d/100-macos.conf
as well. macOS's default/etc/ssh/ssh_config
containsso macOS ssh clients all pass LC_TERMINAL. Debian and Ubuntu do this too.
*: Checked Ubuntu 16.04, 18.04, 20.04, 22.04; Debian 9.9, 10.12, 11.3, current sid.