Opening firefox in a centos linux terminal

9,528

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.

Share:
9,528

Related videos on Youtube

pulsarjune
Author by

pulsarjune

Updated on September 18, 2022

Comments

  • pulsarjune
    pulsarjune over 1 year

    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.

    • Keith
      Keith over 11 years
      Try it with the -Y switch also.
    • Admin
      Admin over 11 years
      yep, that also opens a Firefox browser.
    • Keith
      Keith over 11 years
      Oh, SSH doesn't use display 0. Try DISPLAY=:10.0
    • Admin
      Admin over 11 years
      thanks for your suggestions, but I'm now getting Error: cannot open display: :10.0.
    • Joni
      Joni over 11 years
      Use the -X option also when you log in. ssh -X user@hostname
    • Admin
      Admin over 11 years
      I need the server to be able to run firefox as part of automated tests using a script run locally on the server, therefore I will not be using SSH.
    • terdon
      terdon over 11 years
      In that case why do you need it opening on your local machine? The problems you are experiencing are related to opening a GUI program from a remote server and asking it to display on your local machine. If you want to run the tests on the server, none of what you describe sjould be a problem. Perhaps you need to clarify your question?
  • gronostaj
    gronostaj over 9 years
    What does it do? How do I know it won't damage my system? This answer needs some explanation.
  • Avery Payne
    Avery Payne over 9 years
    Answer is briefly amended. I don't have enough time to really spell everything out at the moment, as I have more pressing things to tend to.