Linux – Opening firefox in a centos linux terminal

centosfirefoxlinux

I am trying to run Firefox from the terminal on a server using a centos operating system. Whenever I type in the command:

  ssh - X hostname firefox 

I can get firefox to successfully open, but I can not ssh on to the server remotely and open firefox. I get the following error message after specifying export DISPLAY=:0 and typing in "firefox"

No protocol specified
No protocol specified
Error: cannot open display: :0

There are many forums for this problem online and the only useful suggestions I have tried:

export XAUTHORITY=/home/<user>/.Xauthority

Although I need firefox to open under a specific user it will also not open under root.

Best Answer

Normally, on a trusted network (i.e. home network, etc.) you could get away with

xhost +hostname

This enables X11 host control for your local display. It allows a X11 connection from the remote host hostname to connect to your local X11 server.

Please keep in mind that X11 host control is an old, old mechanism that is not inherently secure. It provides a rudimentary means of access control through IP addresses or host name resolution. This is why you would use ssh to connect to a remote host: it encrypts all of the data and secures the connection point to point.

In this case, it will not be needed, as your remote environment should be (sanely) set up to allow IP access through the loopback device. But it is listed here for reference.

ssh -x remotehostname "DISPLAY=localhost:10.0 firefox"

When ssh connects, and you specify X11 forwarding through the -x switch, a binding will be made on the loopback connector (address 127.0.0.1) for display number 10 (this is typically the default, although it can be changed). The DISPLAY environment variable is typically used to divert the connection of an X11 program to some other display or machine.

So, we are effectively setting the environment variable that tells firefox to connect to a fake display 10.0 residing on 127.0.0.1, which ssh will then tunnel backwards to your local X11 display.

Related Question