Run application on local machine and show GUI on remote display
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
Solution 1:
Variant A - Shooting X Windows to another DISPLAY:
-
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). -
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. Runxauth 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. 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.
- SSH to your laptop from your desktop computer (you don't need to use -X yet).
- 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). - 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.
-
echo $DISPLAY
shows you the designation, your laptops X display has now on your desktop computer. I.e. :10 or :11. -
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.
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.
-
Start a X-Server on your Laptop, which requests the display manager from your desktop. Either a nested X:
Xephyr :1 -query desktop
orXephyr :1 -broadcast
Or by shutting down your Notebooks X-Server and enter on a System Terminalsudo 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.
Solution 2:
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.
Solution 3:
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
Solution 4:
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.
Solution 5:
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.