Problem :
I’m in a Linux environment and have the ability to ssh to another host and start an X Windows based application (like chromium-browser
) and it will open on my host box. This is done using an ssh tunnel for X Windows apps (see below).
Depending on what I’m doing, some Chrome windows will open locally and some will open remotely. At some point I’m trying to do something via the browser and the local file system only to find that the browser I’m using was launched on the wrong host.
So my question is this: Does Chrome (or chromium-browser
) have some setting that allows it to look at the localhost and see something that would identify the host? Something like the local IP address(es), a MAC address, a hostname or maybe something else that I don’t yet know of.
Searching for an answer
-
In Google Chrome Browser, how can I set the theme for one system to be different from another system? – I tried to configure the browser theme to look different depending on the host that I was on but this isn’t possible (as of 2021-March-16).
-
https://stackoverflow.com/questions/18572365/get-local-ip-of-a-device-in-chrome-extension – This is what I want but not from a chrome extension.
If I keeps searching I’ll probably find it!
How I configure ssh tunnel to support X Windows (GUI apps)
I use a $HOME/.ssh/config file set up as follows:
Host my-dev
HostName p245ud.example.com
ForwardX11 yes
ForwardX11Trusted yes
ForwardAgent yes
Solution :
I have to give credit to user1686 who’s comment gave me the idea and answer to this question. The solution was to use xprop
as shown below.
xprop | grep WM_CLIENT_MACHINE
By default, when xprop runs it opens a cross-hair cursor. Next, you move the cursor to the browser you want to examine and then click on the window; xprop runs and queries the underlying window for it’s properties. The grep
command simply filters out all of the other noise so only the hostname is printed.
The output was as follows:
xprop | grep WM_CLIENT_MACHINE
WM_CLIENT_MACHINE(STRING) = "myhost.example.com"
# Run it again selecting the 2nd browser
xprop | grep WM_CLIENT_MACHINE
WM_CLIENT_MACHINE(STRING) = "another-host.example.com"
The output myhost.example.com
in the examples I performed matched the output of hostname
on the particular machine in which the browser was running.
Needed to install xprop
The Linux host (an EC2 instance) that I was using did not have xprop installed, so I installed it using
sudo yum install xprop
which installed xorg-x11-utils
(which includes xprop as well as other commands).