Ssh – Running Firefox in an Ubuntu VM over SSH opens host machine’s Firefox

firefoxssh

I'm using Slackware. Firefox is running. I also have a virtual machine running Ubuntu 16.04 using VirtualBox.

I've installed Firefox on the virtual machine, and Firefox is installed on the host computer.

I opened an SSH session in the virtual machine and ran Firefox. It opened a new window of my host computer's Firefox.

Why did it do this? I was expecting two running instances of Firefox: one on my host computer and one on the virtual machine.

Best Answer

When Firefox starts, it looks for a Firefox window running on the same display, and if it finds one, it focuses this window (and if you pass a URL on the command line, it opens a new tab to load the URL in the existing window).

You must have run SSH with X11 display forwarding. Since X11 forwarding is active, all GUI programs that you start in the SSH session will be displayed on the local machine.

If you X11 forwarding was not active in the SSH connection, then GUI applications run from the SSH session would have nowhere to display. They'd just complain “Error: no display specified” or some similar error message.

X11 is inherently network-transparent, so it doesn't have a notion of “the local display”. The display is whatever you tell the application is the display. There can be multiple local displays, e.g. in the case of a multiseat configuration. There isn't one “true” display like there is with Windows. If you're running a program remotely and you want it to display on the monitor of the remote machine, you need to run an X server on the remote machine and you need to explicitly tell the program to connect to that display. By default, if you do nothing, programs will be displayed on the machine that you're in front of.

Related Question