Vous êtes sur la page 1sur 18

How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

VNC is a protocol that is used to share the desktop with other users/computers over the network/Internet.In order to share a desktop, VNC server must be install and configure
on the computer and VNC client must be run on the computer that will access the shared desktop.

When we install the fresh copy of Ubuntu Server, it only gives us the Command Line interface.

But some people prefer GUI instead and for this they install Full version of Gnome on Ubuntu Server. Actually there is a better way and that is to install VNC. VNC provides a
lightweight virtual desktop than full blown version of Gnome.

To install the core components of gnome, use this command:

sudo apt-get install gnome-core

To install a virtual desktop, use this command:

sudo apt-get install vnc4server

In order to use VNC, we need to setup a password using the following command:

vncserver

1 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

To make a tweak in startup script, we need to kill the session that we just created:

vncserver -kill :1

Now open up the file that we need to edit:

cd ~
nano .vnc/xstartup

And Modify the file so it looks like this:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup


[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

Next, create the VNC Session once more:

vncserver -geometry 1024x600

2 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Now, download VNCViewer onto our desktop computer from which we want to access the shared desktop. Connect using ServerIP/Name:1 (:1 is for the VNC server window), In
my case it is tendo:1.

Enter the password that we created using the vncserver command:

We now have GUI access to our server.

After reboot the server, we will not be able to connect to the server with VNC, this is because the vncserver -geometry 1024600 command that we typed above is not
persistent. To solve this problem, we will use an excellent script of Justin Buser.

As sudo user create the file (and directory if it doesnt exist):

sudo mkdir -p /etc/vncserver


sudo touch /etc/vncserver/vncservers.conf
sudo nano /etc/vncserver/vncservers.conf

3 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Add servers as needed for each user by adding something like the following to the vncservers.conf file we just created:

VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24"

Next, create an empty init script and make it executable:

sudo touch /etc/init.d/vncserver


sudo chmod +x /etc/init.d/vncserver
sudo nano /etc/init.d/vncserver

Add the following to /etc/init.d/vncserver:

#!/bin/bash
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)

4 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

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

Well need to run vncserver command AT LEAST ONCE AS EACH USER that want to login as. I put that in caps because if you skip that step none of it will work.

Finally, do the following:

sudo update-rc.d vncserver defaults 99

Now, restart the service by typing:

sudo service vncserver restart

5 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Ability to connect for multiple users:

Create a local user, using the following command:

sudo adduser hussain

Switch to the newly created user and run vncserver command for it:

su hussain
vncserver

Move to the home directory and edit the xstartup file:

cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup


[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

6 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Now open up the /etc/vncserver/vncservers.conf file as sudo user:

sudo nano /etc/vncserver/vncservers.conf

Add servers for newly created user by adding something like this:

VNCSERVERS="1:arbab 2:hussain"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24"
VNCSERVERARGS[2]="-geometry 1024x600 -depth 24"

Restart the service:

sudo service vncserver restart

Connect with newly created user using tendo:2, Where tendo is my server name:

7 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Enter the password that we created using the vncserver command:

We now have GUI access to our server for newly created user.

Preventing Gnome to start on boot on the server:

Gnome is automatically started on boot in Ubuntu 12.04 LTS, if we connect a monitor to our server we will see that GUI sitting there waiting for us to log in.

To prevent it, edit the gdm.conf file:

8 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

sudo nano /etc/init/gdm.conf

Comment these six lines:

#start on ((filesystem
# and runlevel [!06]
# and started dbus
# and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
# or stopped udev-fallback-graphics))
# or runlevel PREVLEVEL=S)

Reboot the server and that GUI log-in screen will no longer appear:

VNC encrypted through the ssh tunnel:

By default, VNC is not secure protocol.VNC uses encryption during initial connection and login (passwords are not sent in plain-text). Once, we connected then all the VNC data is
unencrypted and hacker could sniff our VNC session. It is better (safer) to start VNC server only on 127.0.0.1(localhost) and tunnel it over secure SSH tunnel (For this,there are
options in Putty).

On Ubuntu, edit /etc/vncserver/vncservers.conf:

sudo nano /etc/vncserver/vncservers.conf

9 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Add the option -localhost:

VNCSERVERS="1:arbab 2:hussain"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24 -localhost"
VNCSERVERARGS[2]="-geometry 1024x600 -depth 24 -localhost"

Restart the service:

sudo service vncserver restart

Here is visual, how to connect to VNC Server through PuTTY(SSH) from Windows Machine.

Run PuTTY,enter the IP address or hostname of the VNC Server:

10 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

On the left-hand panel, Go to Connection -> SSH -> Tunnels:

Source Port:590x(Where x is a value that we set in vncservers.conf,like 1 for arbab)


Destination:localhost:590x(Same x value that we used above in source port)

Click Open button in order to connect to the Server via SSH:

Login to the Ubuntu (VNC Server) with username and password:

11 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Upon successful connection to VNC Server, well find port 5901 is in listening mode on localhost:

netstat -a

Run VNC Viewer and enter the localhost:1(:1 is for arbab user, that we defined in vncservers file):

Enter the password, in order to connect to the VNC Server:

Now, we are connected to remote VNC Server through ssh tunnel:

12 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Hope this will help you!

Please Remember me in your prayers!

Enjoy

Name (required)

Email (required)

Website

Comment (required)

Rate this:

16 Votes

Share this:

4 bloggers like this.

Related

Installing the VNC server on Ubuntu using How to install VNC server on CentOS 6 How to Encrypt VNC Traffic with Putty
Ansible

Linux, Ubuntu, Windows Administer Ubuntu Server 12.04 using VNC, command line interface, encrypt the vnc traffic, Encrypting VNC Traffic with Putty, Gnome, gnome
classic, Gnome Classic on Ubuntu 12.04 LTS, gnome core, Gnome to start on boot, How to install VNC server on Ubuntu Server 12.04, How to run VNC on startup, Install VNC
server on Ubuntu Server, multiple users on vnc, putty ssh, secure the vnc, Secure VNC using SSH, ssh, ssh server, ssh tunnel, tunneling the traffic, ubuntu, ubuntu 12.04, ubuntu
desktop, ubuntu server, virtual desktop, vnc, vnc on startup, vnc over ssh, vnc server, vnc session, vnc through ssh, vncserver, xstartup

13 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

How to find the Linux Distribution Name and Version How to install VNC server on CentOS 6

47 responses to How to install VNC server on Ubuntu Server 12.04

CzBiX October 15, 2012 at 5:47 pm


Thx for your post! thats useful.

Reply

Motte October 22, 2012 at 9:27 pm


that is VERY VERY VERY VERY VERY USEFUL!!! thank you for this keep up the good work!

Reply

tay October 27, 2012 at 3:31 am


ty

Reply

bernds November 9, 2012 at 4:16 pm


thank you very much and God bless you

Reply

narp November 9, 2012 at 7:44 pm


very nice, thanks a lot!

+1

Reply

SB November 24, 2012 at 3:12 am


Excellent guide, just solved me my issue with server Thank you very much.

Reply

fred November 29, 2012 at 5:44 pm


You need to add a step apt-get install gnome after apt-get install gnome-core to get the entire package otherwise the desktop will be minimal and pretty
useless.

Reply

Arbab November 29, 2012 at 8:35 pm


Thanks fred for comment, but normally full desktop is not recommended on server

Reply

Amrish December 6, 2012 at 3:10 am


Sorry I was trying to set up and I was getting following error. Server is running fine.

Error > getaddrinfo: No such host is known. (11001)

I was following the same steps. Can you please let me know where I am going wrong.

Reply

Amrish December 6, 2012 at 3:13 am


I am using Ubuntu 12.04 with Unity.

Reply

i-acces December 21, 2012 at 10:10 am


Thanks very much for such a well written guide. Very smooth!

14 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

Reply

Pingback: Instalar VNC Server en Ubuntu 12.04 Server

Kareem Adams February 3, 2013 at 1:58 am


Nice and precise. But how do one do tunnelling on MacBook to the Ubuntu vncserver?

Reply

Chris March 8, 2013 at 8:45 pm


Nice, got everything working but the following issues I have found. When connecting via vnc then trying to run vi or gedit the normal function such as up arrow do
not work. Also when logging out if I select the normal logout the gui disappears and to get it back I have to ssh to the server and restart vncservice. Any ideas?

Reply

Harold March 12, 2013 at 5:17 pm


Thank you for the detailed instructions, well written. How do I change the default port 5901 to a different port number?

Reply

KC March 27, 2013 at 2:50 am


Thank you for this great tutorial. I have multiple users, I only want to allow each user to be able to log into their existing session. How can I achieve that? Right
now VNC just creates a new session every time. My system is Ubuntu 12.04 LTS, and uses vnc4server, and I followed your tutorial here to set it up in both user and
server sides. Your help is greatly appreciated. Is there a way to fix this in vnc4server?

Reply

Pingback: Setup wordpress | Tech Info

Leon April 6, 2013 at 12:25 pm


This helped me so much. After struggling several nights with instructions that did not do the complete setup (building a headless server with a gnome GUI in
vncserver) this guide did the trick for me! Thanks!

Reply

curtisbob April 7, 2013 at 11:39 pm


Love your info here.. very helpful. the only question I would have is how would one do that wit KDE or is that not recommended.. is there a core version for KDE
as well??

Reply

Celladria June 19, 2013 at 2:56 pm


Excellent! Thanks a lot

Reply

naveen July 7, 2013 at 7:04 pm


i think the website is doing a great job. thanks</a

Reply

Obamayourmama July 11, 2013 at 2:27 am


Ubuntu Server 12.04 types in commands exactly Unable to locate package gnome-core and Unable to locate package vnc4server thoughts?

Reply

Harmerex July 12, 2013 at 11:27 pm


Same problem as for Amrish (no such host), i realy hope its possible to resolve this

Reply

Osric Caton July 14, 2013 at 7:12 pm


Thanks for the tutorial Just what I was looking for!

Reply

Pingback: Install VNC server on Ubuntu server | Technology Librarian Does Stuff

15 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

LaudemGloriae August 24, 2013 at 4:51 am


I had problems querying the status in the vncserver run-level script. It didnt work. I replaced it with the following:
status)
#status Xvnc
pgrep Xvnc4 > /dev/null && echo vncserver is Running
pgrep Xvnc4 > /dev/null || echo vncserver is Not Running
;;
This was one of the options given for this problem at StackOverflow: http://stackoverflow.com/questions/2903354/bash-script-to-check-running-process

As well, I had to inert the following header inforamtion to satisfy some of the Debian requirements:
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 3 4 5
# Default-Stop: 0 6
# Short-Description: Start vncserver daemon at boot time
# Description: Enable vnc server service provided by daemon
### END INIT INFO
# Guides for rc init scripts at wiki.debian.org/LSBInitScripts
#
Yours was the clearest and most complete guide for doing a vncserver installation on ubuntu 12.04 that I found. I will indeed pray for you as you requested.

Reply

Pingback: VNCServer on Ubuntu Server | Minuk.Net

KKP September 10, 2013 at 11:36 am


excellent

Reply

vishwa h February 18, 2014 at 2:28 pm


Very well written, thank you very much.

Reply

remd1980 March 13, 2014 at 8:49 am


Hello, this is a nice step-by-step guide. I like it, I have only one doubt, in the parameter VNCSERVERS=1:arbab'. What is arbab? What does it means? I just
hope you can answer me. Thanks. Great Tutorial!!

Reply

Pingback: VPS - Konfigurcia VNC Servera | itnavody.sk

Pingback: nothingOS VNC guide for Ubuntu

Joe Mauri May 1, 2014 at 2:45 pm


This VNC over SSH tutorial is the most complete and accurate ive ever found in years on the net.

Now that i know how to do it i will post the procedure on my blog, i will surely cite you.

Thanks for sharing, bro..

Reply

Pingback: .vnc/xstartup files ubuntu 14.04 | Brett Broderick

Igor June 11, 2014 at 10:19 pm


Thanks for this tutorial. But i have the grey monitor and cant doing anything. Please, help. I have not any idea what is wrong.

Reply

Hildegarde September 5, 2014 at 12:13 am


Asking questions are in fact nice thing if you are not
understanding anything totally, but this paragraph provides pleasant understanding
yet.

Reply

Oliver S. October 10, 2014 at 2:34 pm


If you are using Ubuntu 14.04 please have a look at this updated instructions:

16 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

http://www.havetheknowhow.com/Configure-the-server/Install-VNC.html

Reply

robin September 16, 2015 at 2:33 pm


This is very helpful! thanks.

Reply

Pingback: Data Recovery Ubuntu 12.04

Pingback: How To Fix Install Server Not Responding Xp Errors - Windows Vista, Windows 7 & 8

Pingback: How To Fix Install Server Not Responding Errors - Windows Vista, Windows 7 & 8

Pingback: How To Install Servers | Kuplux's

Pingback: Fix Ubuntu 12.04 Error Prefix Not Set Windows XP, Vista, 7, 8 [Solved]

Pingback: Installing the VNC server on Ubuntu using Ansible | Lazy Geek -:)

Eknaprasath May 20, 2015 at 6:04 pm


Reblogged this on Eknaprasath.

Reply

Siddhartha May 28, 2015 at 12:49 pm


This works
~/.vnc/xstartup

1
2
3
4
5
6
7
8
9
10

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
#startxfce4 &
gnome-session session=gnome-session-fallback &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup


[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

Reply

17 sur 18 19/02/2016 15:43


How to install VNC server on Ubuntu Server 12.04 | Lazy Geek -:) https://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on...

gufran December 19, 2015 at 11:45 am


Use this if you are installing on ubuntu 14.04
#!/bin/sh

export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup


[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

Reply

Blog at WordPress.com. The zBench Theme. Top

18 sur 18 19/02/2016 15:43

Vous aimerez peut-être aussi