You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

In some scenarios, you might want to have a GUI on your GPU accelrated instance. VNC is typically the way to go, when you want a remote desktop connection to a Linux-based computer. Actullay getting a GPU accelrated VNC session is not very straightforward, but if you follow these instructions carefully; it can be done (smile)

The following steps are tested on Ubuntu Server 20.04

Configure the server

Install a basic GUI, a VNC server and some necessary utilities

$ sudo apt install gnome-session x11vnc xinit


Disable gdm3 and set default target

$ sudo systemctl disable gdm3.service
$ sudo systemctl set-default multi-user.target


Configure x11vnc to autostart with the gnome-session

$ mkdir ~/.config/autostart
$ cat << EOF > ~/.config/autostart/x11vnc.desktop
[Desktop Entry]
Name=X11VNC Server
Comment=Share this desktop by VNC
Exec=x11vnc -localhost -forever -shared -ncache
Icon=computer
Terminal=false
Type=Application
StartupNotify=false
Categories=Network;RemoteAccess;
Keywords=VNC;Server;Screencast
EOF


Tell getty to autologin the ubuntu-user

$ sudo /etc/systemd/system/getty@tty1.service.d/
$ sudo cat << EOF > /etc/systemd/system/getty@tty1.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin ubuntu --noclear %I $TERM
EOF

$ sudo systemctl enable getty@tty1.service


Generate config for X

$ sudo nvidia-xconfig --query-gpu-info # Take note of the value of "PCI BusID"
$ sudo nvidia-xconfig --busid="<busid from before>" --use-display-device=none

# This will generate a xorg.conf that almost works. In order to _actually_ make it work, open /etc/X11/xorg.conf in your favourite editor and do the following:
- Remove the entire Section "Monitor" block
- In the Section "Screen" block remove the following:
    Option         "UseDisplayDevice" "none"
    Monitor        "Monitor0"
    SubSection     "Display"
        Depth       24
    EndSubSection
- In the Section "Screen" block, add:
    Option         "AllowEmptyInitialConfiguration" "True"


Ensure that the X server starts on boot, and only when doing an interactive logon

$ cat << EOF >> ~/.bashrc
if [ -z "${DISPLAY}" ] && [[ "${XDG_VTNR}" -eq 1 ]]; then
  exec startx
fi
EOF

Congratulations. You are now done, and you should do a reboot.

Connect to the VNC server

When the steps above are completed, you are reday to connect. The configured VNC server is only listening to localhost. So, to be able to connect you need to setup a SSH tunnel on your client. This should work in Linux, MacOS and in PowerShell on windows:

$ ssh -f -L <some random high port>:127.0.0.1:5900 ubuntu@<ip to server> -N

Example:
$ ssh -f -L 15900:127.0.0.1:5900 ubuntu@10.212.136.100 -N

Now you can connect to localhost:15900 with your favourite VNC client.

  • No labels