In some scenarios, you might want to have a GUI on your GPU accelrated accelerated 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
The following steps are tested on Ubuntu Server 2022.04
Info |
---|
This steps in this guide should also work for VMs without a GPU. Just skip the nvidia-xconfig steps. |
Configure the server
Install a basic GUI, a VNC server and some necessary utilities
Code Block |
---|
$ sudo$ sudo apt install gnome-sessionxfce4 x11vnc xinit |
Disable gdm3 and set Set default target
Code Block |
---|
$ sudo systemctl disable gdm3.service $ sudo systemctl set-default multi-user.target |
...
Configure x11vnc to autostart with the gnome-sessionxfce4
Code Block |
---|
$ mkdir -p ~/.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
Code Block |
---|
$ sudo mkdir /etc/systemd/system/getty@tty1.service.d/ $ sudo cat << EOF >| sudo tee /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 |
...
Code Block |
---|
$ 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:
...