From a Linux box, how can I detect if I'm ssh'ing in via MacOS iTerm2 vs something else?


Hi
I have a number of Ubuntu linux boxes that I ssh into, but sometimes I do it from iTerm2 on a mac, and sometimes from MobaXterm on windows.

From the Ubuntu box, is there something I can check for that will tell me that I'm coming from this or that OS or terminal program?

(The x/y problem here is that on my Linux boxes I have .zshrc code that will tell iTerm to use a particular profile for each box so I can easily tell them apart via different backgrounds, but I don't want that to run unless I'm ssh'ing in from iTerm2. Other ideas welcome.)
When I ssh into a box, I get a couple of environment variables set.
SSH_CONNECTION
SSH_CLIENT
These tell you where you're coming from.
You would have to list IP address of the macs and search that list with address parsed from SSH_CLIENT.

There is "SendEnv" in ssh. See https://superuser.com/questions/48783/how-can-i-pass-an-environment-variable-through-an-ssh-command

Does iTerm2 set some unique environment variable(s)? Sending that variable over connection and testing it in script would really narrow it down to "from iTerm2".
I have a number of Ubuntu linux boxes that I ssh into, but sometimes I do it from iTerm2 on a mac. ...
(The x/y problem here is that on my Linux boxes I have .zshrc code that will tell iTerm to use

I don't understand the problem. You want ssh client iTerm on your mac to look different depending on the OS of the server (when they're all Linux)?

As @keskiverto mentioned above, if want to build some intelligence into the server, I think SendEnv/AcceptEnv is the way to go.
tell iTerm to use a particular profile for each box so I can easily tell them apart via different backgrounds

This could have a client-side solution too. Have command aliases on the mac.
Use those aliases when in iTerm.

An alias could be:
1. Set pink 2. ssh huey
and another:
1. Set blue 2. ssh dewey

I.e. set the colour in the client before connecting to host of that colour.
in windows, you can name a console session (its title bar). I don't recall if unix can do this, but if it can, that may help too .. a script as part of the launch for the connection and its set.
Topic archived. No new replies allowed.