We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install and Configure VNC Server on Ubuntu 22.04|20.04|18.04

Learn how to – Install and Configure VNC Server on Ubuntu 22.04|20.04|18.04.

Virtual Network Computing (VNC) is a technology which allows remote control of another computer using the  Remote Frame Buffer protocol (RFB). In this guide, we’ll cover how to Install and Configure VNC Server on Ubuntu 22.04|20.04|18.04.

VNC works in a client/server model. The VNC client is installed on the local computer while the VNC server is installed on the remote system to be managed. The server transmits a duplicate of the remote computer’s display screen to the viewer(client).

Install and Configure VNC Server on Ubuntu 22.04|20.04|18.04

Install VNC server on Ubuntu by running the commands below in your terminal.

sudo apt update
sudo apt -y install tightvncserver

Install Desktop Environment

Ensure you have a Desktop Environment installed on your Ubuntu. For this guide, we’ll install  Xfce desktop environment.

sudo apt install xfce4 xfce4-goodies

You can choose to use other Desktop environments.

Configure VNC Server

Once you’ve finished the installation of Desktop environment and VNC server. Configure VNC server on Ubuntu 18.04 LTS as follows.

1. Set a secure access password

Run the vncpasswd command to set password for your VNC server.

$ vncpasswd
Password:
Verify:

When prompted, enter and verify your password to set.

2. Start VNC server

Start VNC Server on Ubuntu 18.04 using the command:

$ vncserver :1
New 'ubuntu-01:1 (learnhowto)' desktop is ubuntu-01:1
Creating default startup script /home/learnhowto/.vnc/xstartup
Starting applications specified in /home/learnhowto/.vnc/xstartup
Log file is /home/learnhowto/.vnc/ubuntu-01:1.log

3. Kill VNC Server

Kill VNC Server using the command:

$ vncserver -kill :1
Killing Xvnc4 process ID 20842

4. Set VNC Server Desktop Environment

VNC configuration file is located on ~/.vnc/xstartup. Edit it with your favorite text editor.

sudo vim ~/.vnc/xstartup

Add the following line at the end of the file.

exec /usr/bin/startxfce4 &

Finally start VNC Server with ;

  • Display number [1]
  • Screen resolution [800×600]
  • Color depth [24]
$ vncserver :1 -geometry 800x600 -depth 24 
New 'ubuntu-01:1 (learnhowto)' desktop is ubuntu-01:1
Starting applications specified in /home/learnhowto/.vnc/xstartup
Log file is /home/learnhowto/.vnc/ubuntu-01:1.log

Step 4:  Connect to the VNC Desktop

You can connect to remote desktop using a VNC client and SSH tunneling. Create an ssh tunnel to VNC server using the following command

ssh <username>@<vnsserverip>  -C  -L 5901:127.0.0.1:5901

Then install vncviewer client

sudo apt install tigervnc-viewer

On Arch Linux, install it with:

sudo pacman -S tigervnc

Once your SSH tunnel is running, connect to localhost:5901 using  VNC client. When prompted for password, enter the password created during the VNC server configuration.

Once connected, you’ll see the default Xfce Desktop environment

Step 5:  Configure Systemd

Stop the current VNC server instance:

vncserver -kill :1

Create a systemd service unit file for managing VNC Server.

sudo vim /etc/systemd/system/vncserver@.service

Add:

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

[Service]
Type=forking
User=learnhowto
Group=learnhowto
WorkingDirectory=/home/learnhowto

PIDFile=/home/learnhowto/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Don’t forget to replace learnhowto with your actual remote user username. Save the file and exit when done.

Reload systemd and start VNC

sudo systemctl daemon-reload
sudo systemctl enable --now vncserver@1

Check status:

$ systemctl status vncserver@1
* vncserver@1.service - Start TightVNC server at startup
   Loaded: loaded (/etc/systemd/system/vncserver@.service; indirect; vendor preset: enabled)
   Active: active (running) since Wed 2018-12-05 11:32:50 PST; 7s ago
  Process: 24161 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=0/SUCCESS)
  Process: 24154 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)
 Main PID: 24168 (Xvnc4)
    Tasks: 63 (limit: 1110)
   CGroup: /system.slice/system-vncserver.slice/vncserver@1.service
           |-24168 Xvnc4 :1 -desktop ubuntu-01:1 (learnhowto) -auth /home/learnhowto/.Xauthority -geometry 1280x800 -depth 24 -rfbwait 30000 -rfbauth /home/v
           |-24174 vncconfig -iconic
           |-24176 /bin/sh /etc/xdg/xfce4/xinitrc -- /etc/X11/xinit/xserverrc
           |-24186 xfce4-session
           |-24189 /usr/bin/dbus-launch --sh-syntax --exit-with-session xfce4-session
           |-24190 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
           |-24194 /usr/lib/x86_64-linux-gnu/xfce4/xfconf/xfconfd
           |-24198 /usr/bin/ssh-agent -s
           |-24202 xfwm4
.....

How to secure a VNC Server on Ubuntu?

If you have followed the steps mentioned above, you will have a perfectly working VNC server on your Ubuntu device. However, keep in mind that VNC sends passwords without any security – meaning, someone can easily listen to your conversation by logging themselves in! Therefore, to secure your VNC server, you can use a VPN for encryption which will mask your remote VNC server location, making it impossible to track. There are plenty of free VPNs for Ubuntu that you can use to set up a secure VNC server. 

You have successfully installed and configured VNC server on Ubuntu server.

Check other Ubuntu guides available in our website.

Cart

Your Cart is Empty

Back To Shop