50

Is it possible to run an application on my local desktop but display the GUI on my laptop (remote X)?

I'm wondering if it is possible to emulate a dual-monitor setup using 2 distinct lan connected machines.

I have installed synergy and I can easily control my laptop with the desktop keyboard/mouse, but I would also like to just run something on the desktop and display the GUI on the laptop screen.

From my limited experience with X, I know that I can run a program on a remote machine and use the display of the first to show the output, but not the other way around.

Any pointers would be of great help. Thank you

P.S. Running XFCE 4.10 on Ubuntu 12.10

7 Answers 7

55

Variant A - Shooting X Windows to another DISPLAY:

  1. See to it, that the Xserver on your Laptop starts up listening to tcp connections. Sadly X11-Networking is disabled by default in most distributions. Since the Xserver is started by your display manager (gdm, lightdm) this has to be configured there:

    Whatever display manager you use, some configuration file in /etc/ will probably contain the responsible XServer parameter. Run grep -r 'nolisten tcp' /etc/ on your Laptop to find out which config file is responsible and remove the part where it says -nolisten tcp (not the entire line, just this parameter). Restart X on your Laptop.

    Your Laptop should now have a display running on tcp port 6000 (try running nmap -p6000 Laptop on your Desktop PC, if the port reported as "open", you came this far).

  2. Make your X-display available to the desktop computer. X11 uses an authentication mechanism to grant access to a display. You have to allow the desktop PC to shoot Windows onto the Laptop. Normally by exchanging a display cookie.

    For starters perform this step with hands on your notebook. Once you have gotten the concept with the DISPLAY variable and everything, you can do this via ssh.

    Quick and dirty: You can run xhost +desktops.computers.ip.address on your laptop to grant X access to the desktop computer. Note that every user on your laptops computer can use your laptops X display this way. Note that this is sufficient i.e. for installing a keylogger on your laptops display. Use this method only for testing.

    Correct and secure: run xauth extract cookie-file :0 on your laptop to export your display access secret to "cookie-file". Transfer the cookie to your Desktop machine. Run xauth merge cookie-file. Or in one short step (from your desktop) ssh Laptop xauth extract - :0 |xauth merge - Note: if your laptop and desktop are sharing a home directory i.e. via nfs you don't need to exchange any credentials. The credential database is the .Xauthority file in your home dir, and can be shared among different machines.

  3. Run the program: In a terminal on your desktop PC run export DISPLAY=Your.Laptops.IP.Address:0, run any X program in the same terminal. It should appear on the notebooks display.

Variant B - Using SSH with a twist.

SSH accomplishes X11 forwarding by forwardin a local X11 socket (normally a Unix Domain Socket) to a local TCP socket on the remote machine, then negotiating the display cookie, then setting the DISPLAY-Environment on the remote machine. This way all X11 traffic is encrypted over the ssh tunnel. The normal use case is to forward the local display to the remote machine (meaning allow remote applications to display x windows locally).

The advantage of using ssh is, that you don't need to put your X-Server into tcp listen mode (since the unix socket is used). And ssh handles the credential exchange.

  1. SSH to your laptop from your desktop computer (you don't need to use -X yet).
  2. In the remote shell enter export DISPLAY=:0 this makes the already running display on your notebook available to the shell you got via ssh. If you run any X command now, it will already appear on your notebook screen, but still run on your laptop (try it out to be safe).
  3. From this shell ssh back to your desktop computer, use -X this time. You now have a shell on the machine on which the ssh session originated but this time with working X. Run xeyes or xcalc to test it.
  4. echo $DISPLAY shows you the designation, your laptops X display has now on your desktop computer. I.e. :10 or :11.
  5. You can minimize the terminal now. Anytime you enter export DISPLAY=:10 (see what display number you got) on your desktop computer now, each program you run afterwards in the same shell will appear on you notebooks screen.

    This Variant is easy but slow, since all X11 traffic is forwarded via SSH.

Variant C - The original thinclient concept:

You can use your laptop to Open a desktop session running entirely on your desktop computer.

  1. Configure the display manager on your Desktop to answer to XDMCP Broadcasts. How to do this depends on your display manager. Some display managers don't support this at all, i.e. slim. XDM, KDM, WDM, GDM do support it.

  2. Start a X-Server on your Laptop, which requests the display manager from your desktop. Either a nested X: Xephyr :1 -query desktop or Xephyr :1 -broadcast Or by shutting down your Notebooks X-Server and enter on a System Terminal sudo Xorg :0 -broadcast

    The display manager will see to it, that credentials are generated and exchanged and everything. Congrats, you should now see a login window provided by your desktop computer.

5
  • 3
    BTW. All this wonderful X11-Functionality will just stop working once Ubuntu switches to Wayland. NAtive wayland applications cannot even be forwarded via ssh anymore. Oct 27, 2012 at 14:57
  • 9
    Isn't it quite ironical that there is no graphical toolchain to control your X-Server? If you truly want to work with GUIs you have to dominate the command line first. Oct 27, 2012 at 14:59
  • General Hint: The first program you may want to start on your remote display is an application starter. I.e. lxpanel or something. This savel a lot of command line work. Oct 27, 2012 at 21:07
  • Does this still work for Ubuntu 17's + ... or has the Wayland prediction come to pass?
    – Xen2050
    Dec 27, 2017 at 3:09
  • Can anyboy mention the pros and cons of each way?
    – SouvikMaji
    Sep 1, 2020 at 19:32
24
+50

You can use ssh X forwarding to achieve your goal. If you are in the same subnet than it is quit fast.

Install the ssh server and client on your laptop and desktop PC

sudo apt-get install ssh

To connect to the desktop PC, open a terminal on the laptop and type the following

ssh -X username@desktop_pc_ip

And you can start any software using the terminal, for example starting Firefox, just type firefox in the terminal.

5
  • 2
    Don't forget to verify that the sshd config files (usually /etc/ssh/sshd_config) have X11Forwarding set to yes as well. Oct 22, 2012 at 6:25
  • Here's my use case: I'm on my desktop and i open Firefox, for example, but i want the browser window to open on my laptop display and still run on my desktop. I'm looking for a functionality similar to workspaces, but instead of a local workspace (4 screens on the same pc) to use a remote workspace (the laptop) Oct 22, 2012 at 8:59
  • 2
    Also you can try the x2x package, you can use one keyboard and mouse in different machine. ex: ssh -X user@host x2x -west -to :0
    – Mokus
    Oct 22, 2012 at 12:35
  • @iUngi i'm already using synergy for that, thanks anyway Oct 22, 2012 at 17:00
  • Be aware that by opening up access to your desktop's X server, you're giving quite wide ranging access to the remote machine. If your server was compromised, this could be used to get into your desktop as well. X11 forwarding is useful, but think about what you are doing, and don't turn it on by default.
    – mc0e
    Nov 21, 2014 at 14:51
8

Preparation

(you do this only once)

In your desktop install SSH server

sudo apt-get install openssh-server


From your laptop:

ssh -X username@desktop_pc_ip

In the terminal you get whatever you run will be on your desktop but displayed on your laptop. If you want to do the same while seated on your desktop (and send windows on your laptop) then go on.

On your terminal you run

echo $DISPLAY

This will show you something like:

localhost:10.0

From your desktop:

Open a terminal and run

DISPLAY=:10.0 firefox

This should send a firefox window on your laptop but running on your desktop. Make sure the number you put (e.g. 10.0) is the same as in the echo result

3

You are looking at using a combination of SSH and screen then to get the situation you want.

On your desktop, install screen:

sudo apt-get install screen

From there, start up a new screen session:

screen

and open firefox in it:

firefox

Use firefox all you want on your desktop, then ssh into your computer from your laptop:

ssh -X username@hostname

Type the following command to see which screen sessions you have running:

screen -ls

Log in to your screen session (1234 would be the number screen -ls gave you)

screen -x 1234

Then you can use firefox on your laptop and close the terminal on your desktop.

2
  • tried that. opened up screen from terminal, started firefox on the desktop, then sshed from the laptop into the desktop, attached the screen session, but i don't get any window on the laptop, just the output from the running program in screen. Oct 23, 2012 at 20:38
  • You were mixing it up. Wait... at least one of you did. Install screen on your desktop computer, use your notebook to ssh -X to your desktop, start screen in the ssh session, detach it and leave the session running. Then reattach the screen session with hands on your desktop computer and run something. This is similiar to my "SSH with a twist" answer. Using screen makes it a bit more conveniant. Oct 27, 2012 at 21:11
3

Virtualgl will create an extra(background) desktop (TightVNC Style) that you can access via a turbo VNC client. It will function as a remote desktop type deal -> But it will play smooth video over a network.

If you looking for a way to offload CPU overhead for a remote connection, so you can run apps from your computer on your laptop, then that would be what I would do.

http://www.virtualgl.org/

You can also export the desktop environment through SSH as /dude above mentioned.

2
  • Thank you. Looks promising. I'll take a look and keep you posted. Oct 24, 2012 at 10:21
  • Yeah, "TurboVNC" (moreso its component VirtualGL) IS the result of my searching for a remote desktop program that would let me play Video Games and Movies. It would function easily as an extra monitor.
    – TardisGuy
    Oct 25, 2012 at 8:45
2

Yes, it is possible. I am taking both linux computer with xclock installed on local computer. I am trying to run xclock locally and show the clock on remote linux computer.

reboot the remote machine
Disable firewall
Disable SELINUX
Check $DISPLAY variable value by command
echo $DISPLAY
Let say its value is :1
run command
xhost +

Now on local computer
xclock -display remote_machine_IP_address:1
1

After some more digging online i came accross DMX

From the home page

Xdmx is proxy X server that provides multi-head support for multiple displays attached to different machines (each of which is running a typical X server). When Xinerama is used with Xdmx, the multiple displays on multiple machines are presented to the user as a single unified screen.

2
  • 2
    this would be a better answer if you can give instructions how to install and how to use.
    – fossfreedom
    Oct 24, 2012 at 12:26
  • XmetaX provides similar functionalities. Is there any alternative to Xdmx and XmetaX?
    – Mariusz
    Oct 24, 2014 at 12:12

You must log in to answer this question.

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