Close Menu
    Facebook X (Twitter) Instagram
    • Download Cisco Packet Tracer
    Facebook X (Twitter) Instagram Pinterest Vimeo
    IT Beginner
    • Home
    • Server
    • WordPress
    IT Beginner
    Home»Server»How to install VNC Server on Ubuntu 14.04
    Server

    How to install VNC Server on Ubuntu 14.04

    25/07/2017No Comments6 Mins Read

    I have shown you How to install VNC Server on CentOS 6, today I’m going to show you How to install VNC Server on Ubuntu 14.04 since many people like and use Ubuntu these days. I mostly spend time with Centos but not with Ubuntu. I spent quite sometimes to make VNC Server to work on Ubuntu 14.04 because gnome doesn’t play nice with VNC Server.

    Update and Upgrade Ubuntu 14.04

    To make sure the installation of VNC Server go smoothly, check your Ubuntu 14.04 is up to date.

    $ su -
    
     
    
    <h1>apt-get update; apt-get dist-upgrade -y --force-yes</h1>

    Install GUI on Ubuntu 14.04 Server

    If you have Ubuntu 14.04 LTS (Trusty Tahr) Desktop version, you can skip gnome-core and xubuntu-desktop packages, you will only need xfce4. Well we don’t need a GUI on Ubuntu 14.04 over ssh, but for VNC purpose we are going to install a GUI to work with Ubuntu comfortably. There are two options here for you to choose, either gnome-core with xfce4, or xubuntu-desktop with xfce4. I have tried to make gnome to work over VNC but no luck so far. So make your pick.

    # apt-get install gnome-core xfce4 firefox nano -y --force-yes

    Or

    # apt-get install xubuntu-desktop xfce4 firefox nano -y --force-yes

    Install VNC Server on Ubuntu 14.04

    It’s quite simple to install VNC server on Ubuntu 14.04, but it’s not that simple to configure VNC server 🙂

    # apt-get install vnc4server -y --force-yes

    Configure VNC Server to work on Ubuntu 14.04

    You can remotely control your Ubuntu 14.04 system via VNC with any user that you want. Some people would recommend you to install and run login to VNC server as root user to avoid sudo escalation privileges which is not a good security practice at all. In this tutorial I will add new user called vncuser you can use any user as you want.

    # adduser vncuser

    set vncuser password

    # passwd vncuser

    Now switch to the user you want to login to VNC server with. We are going to modify xstartup file to start xfce4 session whenever VNC server is started.

    # su - vncuser

    Start VNC server with that user for VNC server to create some necessary files first time.

    $ vncserver

    VNC server will ask you for a password you want to use to login to VNC server, this password does not necessary to be the same as regular user password. This is the sample output

    vncuser@namhuy:~$ vncserver
    
    You will require a password to access your desktops.
    
    Password:
    
    Verify:
    
    xauth:  file /home/vncuser/.Xauthority does not exist
    
     
    
    New 'namhuy:1 (vncuser)' desktop is namhuy:1
    
     
    
    Creating default startup script /home/vncuser/.vnc/xstartup
    
    Starting applications specified in /home/vncuser/.vnc/xstartup
    
    Log file is /home/vncuser/.vnc/namhuy:1.log

    After VNC Server started and created some of it’s files. We are now can turn it off to modify the xstartup file (startup script) to make it start with xfce4 instead of gnome which doesn’t work right with VNC Server on Ubuntu 14.04.

    To kill VNC Server session

    $ vncserver -kill :1

    To modify xstartup file (these commands will empty xstartup file, if you installed wine before vnc server and you want to keep the old content of xstartup file, skip this line $ > .vnc/xstartup ) thanks Hamid

    $ cd ~
    
    $ > .vnc/xstartup
    
    $ nano .vnc/xstartup
    With the content
    #!/bin/sh
    
    unset SESSION_MANAGER
    
    unset DBUS_SESSION_BUS_ADDRESS
    
    startxfce4 &
    
     
    
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    
    xsetroot -solid grey
    
    vncconfig -iconic &
    Save xstartup when you are done. The next step is to create VNC Server statup script. You must do this with root user
    $ su -
    
     
    
    <h1>nano /etc/init.d/vncserver</h1>

    With the content

    #!/bin/bash
    
    ### BEGIN INIT INFO
    
    # Provides:          tightvncserver
    
    # Required-Start:    $syslog
    
    # Required-Stop:     $syslog
    
    # Default-Start:     2 3 4 5
    
    # Default-Stop:      0 1 6
    
    # Short-Description: vnc server
    
    # Description: http://www.namhuy.net
    
    #
    
    ### END INIT INFO
    
     
    
    unset VNCSERVERARGS
    
    VNCSERVERS=""
    
    [ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
    
    prog=$"VNC server"
    
    start() {
    
    . /lib/lsb/init-functions
    
    REQ_USER=$2
    
    echo -n $"Starting $prog: "
    
    ulimit -S -c 0 >/dev/null 2>&1
    
    RETVAL=0
    
    for display in ${VNCSERVERS}
    
    do
    
    export USER="${display##*:}"
    
    if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
    
    echo -n "${display} "
    
    unset BASH_ENV ENV
    
    DISP="${display%%:*}"
    
    export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
    
    su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
    
    fi
    
    done
    
    }
    
    stop() {
    
    . /lib/lsb/init-functions
    
    REQ_USER=$2
    
    echo -n $"Shutting down VNCServer: "
    
    for display in ${VNCSERVERS}
    
    do
    
    export USER="${display##*:}"
    
    if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
    
    echo -n "${display} "
    
    unset BASH_ENV ENV
    
    export USER="${display##*:}"
    
    su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
    
    fi
    
    done
    
    echo -e "\n"
    
    echo "VNCServer Stopped"
    
    }
    
    case "$1" in
    
    start)
    
    start $@
    
    ;;
    
    stop)
    
    stop $@
    
    ;;
    
    restart|reload)
    
    stop $@
    
    sleep 3
    
    start $@
    
    ;;
    
    condrestart)
    
    if [ -f /var/lock/subsys/vncserver ]; then
    
    stop $@
    
    sleep 3
    
    start $@
    
    fi
    
    ;;
    
    status)
    
    status Xvnc
    
    ;;
    
    *)
    
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    
    exit 1
    
    esac
    You must make vncserver startup script executable
    # chmod +x /etc/init.d/vncserver
    Save the file. We are almost there, now we are going to create VNC Server configuration file in /etc/ directory
    # mkdir -p /etc/vncserver
    
     
    
    <h1>nano /etc/vncserver/vncservers.conf</h1>
    Copy the content to vncservers.conf file. The first line is for VNC ports and VNC users. number “1″ is the VNC port, it’s port “1″ or “5901″, you can add or change the port to “2″ or “5902″ and so on. If you want more users to connect to your VNC Server, you must include those users here. The second line VNCSERVERARGS is to set VNC screen size.
    VNCSERVERS="1:vncuser"
    
    VNCSERVERARGS[1]="-geometry 1024x768"
    The final step is to make VNC Server starts on boot
    # update-rc.d vncserver defaults 99
    and the output, you can ignore missing LSB information warning.
    update-rc.d: warning: /etc/init.d/vncserver missing LSB information
    
    update-rc.d: see 
    
    Adding system startup for /etc/init.d/vncserver ...
    
       /etc/rc0.d/K99vncserver -> ../init.d/vncserver
    
       /etc/rc1.d/K99vncserver -> ../init.d/vncserver
    
       /etc/rc6.d/K99vncserver -> ../init.d/vncserver
    
       /etc/rc2.d/S99vncserver -> ../init.d/vncserver
    
       /etc/rc3.d/S99vncserver -> ../init.d/vncserver
    
       /etc/rc4.d/S99vncserver -> ../init.d/vncserver
    
       /etc/rc5.d/S99vncserver -> ../init.d/vncserver
    Reboot your Ubutnu 14.04 system and test out your new VNC Server on Ubuntu 14.04
    # reboot
    You can login to your VNC Server with IP address or hostname/domain name by using RealVCN viewer or TightVNC viewer. You will be asked for your user VNC’s password.
    When your VNC session starts the first time, Xfce4′s panel will ask you to choose “Use default config” or “One empty panel”. Choose/click on “Use default config”
    Now you should have a working VNC Server on Ubuntu 14.04.
    VNC Server with xubuntu_desktop
    xubuntu-desktop with xfce4
    VNC Server with xfce4 and gnome_core
    gnome-core with xfce4
    gnome-core VNC Server xubuntu-desktop
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleGet ready for Ubuntu 14.04 LTS (Trusty Tahr)
    Next Article How to install VNC Server on Debian 7

    Related Posts

    Security

    How to secure Nginx web server

    02/08/2017
    Security

    How to secure Apache HTTP Web Server

    29/07/2017
    CentOS

    How to install LEMP web server with Nginx, PHP-FPM 5.6, MySQL 5.5 on Centos 7

    28/07/2017
    Subscribe
    Notify of
    guest

    guest

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

    0 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    Tags
    apache centos Centos 6 cuda Desktop Environment dual boot environment featured gnome GUI hostname hosts intel kernel kill lamp server lemp server life MariaDB netflix nginx nvidia password php-fpm phpmyadmin pids processes s.m.a.r.t Security session solid state drive ssd ssh ssh server tag 1 tag 2 Ubuntu upgrade varnish VirtualBox VNC Server web server window manager wordpress xfce
    Facebook X (Twitter) Instagram Pinterest

    Type above and press Enter to search. Press Esc to cancel.

    wpDiscuz