Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Firefox running, and from the command line I can open a new tab by just typing:


What I'm trying to accomplish is similar, but remotely. I have Firefox running on machine B. From machine A I want to be able to run (after setting whatever ssh tunneling or similar is needed) something like:


However the tab should open not on machine A, but rather on machine B. I don't want X11 forwarding, I just want to be able to instruct Firefox on a remote machine to open a given URL.

Any ideas?

share|improve this question

migrated from Jul 18 '11 at 12:07

This question came from our site for professional and enthusiast programmers.

On the machine where Firefox will run and display (machine A), you need to:

  • Specify which X server to connect to, e.g. set DISPLAY=:0.0 .
  • Authenticate somehow to the X server. An easy way is to read the value of $XAUTHORITY in the X session and use the same one.

For example, in a terminal in the X session do:


Then from the SSH terminal, do, as the same user as the X session (otherwise use su):

DISPLAY=:0.0 XAUTHORITY=/var/run/gdm/auth-for-ambro-j3bu8Q/database firefox

You can have the value of $XAUTHORITY automatically written somewhere when you login. For example, create the following script ~/write-xauth (don't forget to chmod +x):

touch "$HOME"/.saved-xauthority
chmod u=rw,g=,o= "$HOME"/.saved-xauthority
echo "$XAUTHORITY" > "$HOME"/.saved-xauthority

Then create an autostart file that will run the above script, ~/.config/autostart/save-xauthority.desktop :

[Desktop Entry]
Name=Save XAUTHORITY to .saved-xauthority

Once you have a shell on machine B (the machine on which firefox will not display), you just have to SSH to machine A (where firefox will run and will display) and run the firefox command I posted. It is possible to automate this into a script on machine B. You'll have use keys (rather than password) for SSH authentication to machine A. For example, see . This will allow you to ssh non-interactively without entering a password. Now you can run commands on machine A from machine B by typing:

ssh machineA command argument ...

In your case, you'd probably want to make a script on machineA for opening the Firefox window:

ssh machineA ./open_local_firefox http://whatever

And this script would look something like:

export DISPLAY=:0.0
export XAUTHORITY=$(cat "$HOME"/.saved-xauthority)
firefox "$1" &>/dev/null 2>&1 &

It's worth noting that this setup will allow machine B to run anything on machine A as the user you're SSHing as. It's possible to limit this, but it's not easy. If you want to do this with SSH, sshd's ForceCommand option would probably help.

There are other ways of doing this of course, but it all boils down to running the 'firefox' command on machine A with the right environment vars (as shown above) as the right user. For example, you can set up an HTTP server and a script on machine A, such that a certain POST request will open that Firefox window. This is probably easier to secure than the SSH approach.

share|improve this answer
Hi,thanks for the reply, but as I said in my question, I'm not looking for X11 forwarding, which in my use case would be too slow. I'm trying to find a way to instruct a firefox running in a remote computer to open a given URL. – Angel de Vicente Jul 18 '11 at 23:16
This is not X11 forwarding; it is about starting Firefox remotely (via an SSH session) to display itself on the remote system (not the one where the client is running). – Ambroz Bizjak Jul 19 '11 at 0:20
Ah, OK, I misunderstood it, but I'm not sure this will work, anyway. Let me clarify: I'm at machine A, where I am running Firefox. I connect via ssh to machine B. From machine B I want to tell (via a scirpt) the Firefox in machine A to open another tab with another URL. I'll try again, and I will report back. – Angel de Vicente Jul 19 '11 at 8:21
It will work, you just have to SSH back to machine A and start firefox the way I told you to. I've added more info now that you've explained your problem more completely. – Ambroz Bizjak Jul 19 '11 at 9:05
OK, thanks. I will try (hopefully today) it. Firefox has been quite stubborn in the past when I was trying to run it remotely... – Angel de Vicente Jul 19 '11 at 9:30

Your question is not very clear. If you mean, that you are sitting in front of your local machine L and want to run firefox on a running X session on remote machine R, you can do the following:

From your machine L login to the remote machine R with ssh:

ssh wife@remotemachine

Search for the running X displays on the remote machine (displays correspond to a socket in /tmp/.X11-unix):

ls -l /tmp/.X11-unix/

The following was the result in my case:

srwxrwxrwx. 1 erik         erik         0 13. Jun 14:44 X0
srwxrwxrwx. 1 concubine    concubine    0 13. Jun 11:40 X1
srwxr-xr-x. 1 gdm          gdm          0 13. Jun 11:13 X1024
srwxrwxrwx. 1 gdm          gdm          0 13. Jun 16:17 X2
srwxrwxrwx. 1 wife         wife         0 13. Jun 16:25 X3

I want to show my wife something on her display, therefore I do:

export DISPLAY=:3

This corresponds to the socket X3.

After that I just run:

firefox ''

to show her this interesting answer.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .