Set Up Remote Desktop On a Linux Virtual Machine

I set up my laptop to run Gentoo as a host and use virtual machines daily. It's important to connect to the virtual machine's desktop. I also have two external monitors. I can use Spice and remote viewer to use the virtual machine without any problems. But I want to be able to connect to it from multiple different machines. I've tried a few ways and would like to write them down.

Requirements

There are different technologies and each of them has their own pros and cons. It's important to know the goal and make the trade off. For me, I would like to be able to pick up the same applications and their states whenever I connect to the virtual machine, no matter where I connect from. I also have two external monitors so it's preferred to use all the monitors.

So I list what my requirements are:

  1. It uses the same desktop session and same applications.
  2. It supports two 4K monitors.
  3. I can connect to it from both Linux (the host) and Windows.
  4. The performance must be acceptable.

There is no a perfect solution. So trade off must be made.

Spice Viewer

Spice is the best option if I just need to connect from the host. I can enable 3d acceleration and multiple monitors. Spice doesn't need to bind to any network interface and listen to any ports. I configure it to use a local socket. Presumably that'll be faster.

There is also a Spice viewer for Windows. So I have to change a little bit to the Spice settings. I have it to listen to a port on the network interface. That means I have to disable 3d acceleration.

With that settings, I can connect to it from the host and from Windows. They share the same desktop. I can use multiple monitors. But the only drawback is the performance. It's slow and not acceptable. It's obvious that it's refreshing the desktop whenever I open a window or move a window. I can tell that it's updating the desktop line by line.

Xrdp + xorgxrdp

This is also a good option. Xrdp creates a virtual display though. I don't need to configure too much to make it work. I can use multiple monitors and I can connect from both the host and Windows.

There are two drawbacks. I cannot have both local display session and the virtual display session running on the same time. I used to enable auto login on the virtual machine. With that, the remote session won't start. This has to do with the settings in systemd and dbus. It may be able to make it work but I don't plan to spend too much time. So I have to disable auto login. And that also means I will never use Spice on the host if I want to connect to the virtual machine via xrdp.

The big problem is that it doesn't share the desktop session. Every connection is a new session. So I cannot use it.

XPRA

I also tried set up the xpra proxy on the VM. With this, I can still use Spice on the host. I can continue to auto login to the virtual machine. Then I start xpra on login.

With xpra proxy, it's actually proxy the whole desktop environment. I then can run xpra on Windows to connect to it. The desktop session is indeed shared and re-used.

But xpra on Windows doesn't support multiple monitors. It looks like it's possible with some settings but I don't continue on that.

I also try xpra on the host. The performance is acceptable. It's laggy when it's playing video.

NoMachine

NoMachine is also a promising one. It support multiple monitors too and it's easy to set up. It mirrors the same desktop session. I can continue to use Spice on the host. I can enable auto login in the virtual machine and start NoMachine. It's similar to xpra.

The real problem is that it's relatively slow. It's not as slow as Spice on Windows. But I still can feel it's laggy even if I just browse the web, not playing any video.

Xrdp + Vnc

It still comes back to use xrdp. The only drawback of xorgxrdp is that it creates a new session for each connection. To workaround that, I use vnc instead of xorgxrdp.

The performance at first when playing video is super slow. The whole remote desktop is almost paused. I then add use_h264=1 to /etc/xrdp/xrdp.ini. Playing video doesn't cause the system any problem. It's still laggy though.

I also need to update a few settings in /etc/xrdp/sesman.ini:

KillDisconnected=false
DisconnectedTimeLimit=0
IdleTimeLimit=0

This is to prevent the session from being terminated when it's idle or it's disconnected. I'm not in front of the desktop all the day.

Conclusion

I still use xrdp + vnc to connect. I need to make the trade off of not watching videos. I don't really watch too much videos. So that is ok. With xrdp + vnc, I can connect to the virtual machine from anywhere and pick up the application wherever it is.

Facebooktwitterredditlinkedintumblr

Leave a comment

Your email address will not be published. Required fields are marked *