Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[Ubuntu] How to install VNC for access to the server with Ubuntu 16.04

WilliamWilliam Moderator
edited September 2018 in Linux Applications
VNC is a graphical desktop sharing system to access another computer remotely. When installed on server with Ubuntu 16.04 it provides desktop access to the server.

Virtualization server with Ubuntu 16.04 installed.
Root access via SSH.

1. When connected to the server, update current packages list and upgrade them:
apt-get update
apt-get upgrade
2. Install the required packages for the VNC connection (choose one):

If you want to install all possible packages:
apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
If you want to install only the essential packages:
apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
3. Essential step is to stop and then disable the NetworkManager service. With this service active the server would not be accessible:
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
4. Install vncserver packets:
apt-get install vnc4server
5. After the vncserver packets are installed, start the vncserver service. After initiation, the console will require you to provide a password for VNC connection and repeat it (up to 8 characters):
vncserver :1
You will receive the following message:
xauth:  file /root/.Xauthority does not exist

New 'localhost:1 (root)' desktop is localhost:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost:1.log

6. Afterwards stop the vncserver service, since configuration files have been created, but we have to adjust few more things:
vncserver -kill :1
7. Edit the ~/.vnc/xstartup file (for this we use nano, however you can use alternate text editor).
nano ~/.vnc/xstartup
The mentioned file contents should be edited into following:
    # Uncomment the following two lines for normal desktop:
    # exec /etc/X11/xinit/xinitrc
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    x-window-manager &
    gnome-panel &
    gnome-settings-daemon &
    metacity &
    nautilus &
8. After saving changes to ~/.vnc/xstartup, start the vncserver service once more:
vncserver :1
9. Now the VNC access to the server is possible. In addition we recommend to set up your crontab, so that after server reboot the vncservice would start automatically:
crontab -e
9.1. In the bottom of opened cron task file add the following line:
@reboot /usr/bin/vncserver :1

After saving the changes to file everything is complete. For accessing VNC via various VNC clients use the following address:

server_ip:5901 (123.456.789.0:5901) and the password that you have set during 5th step.


  • Got error " No Contab for root"
  • ValentineValentine Administrator
    mytipi said:
    Got error " No Contab for root"
    That means Crontab is not existed for root user. You can create it with:
    crontab -e -u root

  • After install VNC then reboot the server, I can connect  vnc and putty, please help.
  • ReginaRegina Moderator

    The issue is related to the last Ubuntu update, when after reboot SSH connection is refused. The recommendation is to avoid server reboot until it will be solved.

    Just create a support ticket if your SSH connection is not available.

Sign In or Register to comment.

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2019 Time4VPS. All rights reserved.

Get In Touch