HostOnNet Blog

Install VNC Server on Ubuntu Server

Looking for Linux Server Admin or WordPress Expert? We can help.

We will be installing xfce4 desktop on remote Ubuntu server to run it as a Virtual Desktop. This instruction will work on Ubuntu and Debian servers.

Lets install xfce, chromium browser and vncserver.

apt update && apt upgrade
apt install xfce4 xfce4-goodies chromium-browser tightvncserver

Now we need to create a user for desktop to run

useradd -m -s /bin/bash desktop
usermod -G sudo desktop

Lets set password for vnc server, for this change to user desktop

su - desktop

Run vncserver, this will ask you to enter password.

vncserver

At this point, you will be able to connect to VNC server using your server-ip:1

Lets kill the running VNC Server

vncserver -kill :1

Starting VNC Server on Boot

Create a file

vi /etc/systemd/system/vncserver.service

Add following content

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=desktop
PAMName=login
PIDFile=/home/desktop/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target

Run

systemctl daemon-reload

To auto start enable the service with command

systemctl enable vncserver

You can start/stop vncserver with command

systemctl enable vncserver
systemctl start vncserver

Change VNC Password

You can change vnc password by running command

vncpasswd

This need to be done as user “desktop”.

Posted in Linux

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.