How to Install VNC Server on Ubuntu
In this tutorial you will learn how to install VNC on Ubuntu and access the graphical desktop from a remote computer.
VNC (Virtual Network Computing) is a cross platform remote control utility that uses the Remote Frame Buffer (RFB) protocol, Is a way to share graphical desktop over the network, Similar to Remote Desktop on Microsoft Windows.
To Install and Configure VNC Server on Ubuntu, perform the following steps:
Open the Ubuntu terminal and use the following commands to install Xfce desktop session:
sudo apt-get update sudo apt-get install xfce4 xfce4-session
We are going to use Xfce desktop for the VNC session (Works Perfectly).
Once Xfce is installed, Install the vnc4server package on Ubuntu:
sudo apt-get install vnc4server -y
When installation completes, start the VNC server for the first time:
When you run vncserver command for the first time, You will prompt to create a password for the VNC connection. The command will also create necessary configuration files for the Ubuntu VNC server.
Next, we need to edit the startup configuration file, First stop the VNC Server with the kill command:
vncserver -kill :1
Open the ~/.vnc/xstartup file:
And make sure that "xstartup" file is similar to the following configuration:
#!/bin/sh unset SESSION_MANAGER [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources startxfce4 &
Save the configuration file and Start the VNC Server:
vncserver :1 -geometry 1366x768 -depth 24
The remote session will use the 1366x768 resolution and the desktop ID is 1.
The user also needs a VNC Viewer to connect from their local computer. Ubuntu users can use the Vinagre remote desktop viewer. For Microsoft windows you can use RealVNC Viewer.
Enter your Ubuntu server IP address and the VNC desktop number to be connected.
Multiple users can connect the Ubuntu system and work simultaneously, But you have to start multiple VNC sessions with different desktop IDs. For example, following command will start a VNC session with desktop ID 2:
vncserver :2 -geometry 1366x768 -depth 24
To manually stop the VNC Server on Ubuntu, run the kill command followed by the desktop ID:
vncserver -kill :1
To change the password run the following command:
Automatically start the VNC server on startup
We need to create a systemd unit file to start the VNC server Automatically when Ubuntu system reboot. Following example will create a new systemd unit with desktop ID 1.
To create a systemd unit, create a file named email@example.com inside the /etc/systemd/system directory and add the following configuration (Change User=your_username to your Linux username).
[Unit] Description=Start VNC Server at startup With Desktop ID 1. After=multi-user.target network.target [Service] Type=forking User=your_username ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :' ExecStart=/usr/bin/vncserver :%i -geometry 1366x768 -depth 24 ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Then Reload the systemd manager and enable the "firstname.lastname@example.org":
sudo systemctl daemon-reload sudo systemctl enable email@example.com
In this tutorial we learned how to install VNC on Ubuntu Linux. VNC is a cross-platform Remote Desktop Server implementation that uses the Remote Frame Buffer (RFB) protocol.
The way it works, The VNC Server runs on your Ubuntu Server/Desktop, and the VNC client application runs on the computer from which you want to access the remote desktop.