Skip to content

Instantly share code, notes, and snippets.

@hardeepnarang10
Last active October 31, 2020 05:16
Show Gist options
  • Save hardeepnarang10/75bc3e2cdc7234401445d8ba589ab7e0 to your computer and use it in GitHub Desktop.
Save hardeepnarang10/75bc3e2cdc7234401445d8ba589ab7e0 to your computer and use it in GitHub Desktop.
My minimal VNC server (host) setup script running gnome environment on cloud VM instance.
  • Create swap space. If RAM ~ 1G, 4G would be an overkill in most cases and should be replaced with 2G.
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
  • Update official repo & packages. Install modules for gnome-desktop. Install VNCServer.
sudo apt update && sudo apt upgrade
sudo apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal gnome-core tightvncserver -y
  • Run VNC server. First run would trigger VNC config. Configure VNC startup script to initialize desktop env on VNC startup and restart daemon.
vncserver
sudo echo "gnome-panel & gnome-settings-daemon & metacity & nautilus &" >> .vnc/xstartup
vncserver -kill :1
vncserver

VNC ports are usually in the 5900 range. So our server should be accessible at :5901. Check startup logs if this doesn't work.

In one line (Over SSH):

(sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile && sudo echo "/swapfile swap swap defaults 0 0" >> /etc/fstab); sudo apt-get update; sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal gnome-core tightvncserver -y && vncserver && sudo echo "gnome-panel & gnome-settings-daemon & metacity & nautilus &" >> .vnc/xstartup && vncserver -kill :1 && vncserver

This script vs Snapshots: Depends on your provider. Snaps are cheap but still incur a monthly bill. This script can replace a VNC setup snapshot given your cloud account has enough bandwidth sitting around to cover installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment