A GPU server is notoriously difficult to set up mainly due to two things: installing the OS itself, and the Nvidia driver installation.
However, there's actually a very easy way to do it - that is to use a Ubuntu Server as opposed to Ubuntu Desktop. This forgoes the GUI, which is unnecessary for a server anyway, and in doing so simplifies the Nvidia driver installation.
In fact, this can all be done quickly and easily and I've set up GPU servers numerous times, so here's the guide:
Go to BIOS, disable secure boot. Then boot UEFI. Install Ubuntu, overwrite full partition, add SSH Server and docker. Finish installation and reboot.
You can now ssh in with password auth (default port is 22). For GPU, login and install nvidia driver with docker toolkit. Since secure boot is disable, nvidia installation should go smoothly.
# if you install ubuntu server no GUI, oksudoadd-apt-repositoryppa:graphics-driverssudoapt-getupdatesudoaptinstallubuntu-drivers-commonubuntu-driversdevices# this will show a list of driverssudoapt-getinstallnvidia-driver-440# reboot required later# install Dockersudoaptinstallapt-transport-httpsca-certificatescurlsoftware-properties-commoncurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudoapt-keyadd-sudoadd-apt-repository"deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"sudoaptupdateapt-cachepolicydocker-cesudoaptinstalldocker-cesudousermod-aGdocker ${USER}# install nvidia-container-toolkit to run Docker with GPUdistribution=$(./etc/os-release;echo $ID$VERSION_ID)curl-s-Lhttps://nvidia.github.io/nvidia-docker/gpgkey|sudoapt-keyadd-curl-s-Lhttps://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list|sudotee/etc/apt/sources.list.d/nvidia-docker.listsudoapt-getupdate&&sudoapt-getinstall-ynvidia-container-toolkitsudosystemctlrestartdocker
# if you have wifisudoapt-getinstallnetwork-managersudo/etc/init.d/network-managerrestartnmclidnmclirwifionnmclidwifilistnmclidwificonnectmy_wifipassword<password>
6. Enable passwordless sudo (optional):
sudonano/etc/sudoers# add below the line includedir /etc/sudoers.d (replace <username>)<username> ALL=(ALL) NOPASSWD: ALL