Você está na página 1de 21

How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.

04

English | Deutsch Log in or Sign up

Tutorial search

Tutorials How To Install VNC Serv…

How To Install VNC


Server On Ubuntu 14.04

Author: howtoforge
This tutorial exists for these OS Tags: desktop, linux, ubuntu
versions

On this page
Tweet
1 Preliminary Note
2 VNC Server Installation Recommend 13
3 Adding VNC user
4 VNC Client

This guide explains the installation and


configuration of a VNC server on Ubuntu
14.04 server. I use a server here to show you
a ay to have a remote desktop on a root
server in a data center. The same steps will
work for Ubuntu desktops as well.VNC is a
very convenient way of administrating the
Ubuntu 14.04 desktops remotely. The GUI can
be accessed from anywhere over the internet
or local network with a VNC client on any OS.
The only requirement is that the connecting
OS has a VNC-client installed on it.

1 Preliminary Note

In my case, I have a fresh installed

1 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

Ubuntu14.04 server in a datacenter (root


server) where I will install the VNC server so
that I can access the Ubuntu Gnome GUI
remotely. If you do. In case that you havent a
Ubuntu minimal installation yet, follow this
guide for the basic installation of the Ubuntu
server till Chapter 11. All of the cases are
same as per the guide. My network details are
as follows:

IP address 192.168.0.100
Gateway 192.168.0.1
DNS 8.8.8.8 8.8.4.4
Hostname server1.example.com

VNC-server benefits

Remote GUI administration makes work easy


& convenient.
Clipboard sharing between host Ubuntu
server & VNC-client machine.

2 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

GUI tools can be installed on the host Ubuntu


server to make the administration more
powerful
Host Ubuntu server can be administered
through any OS having the VNC-client
installed.
More reliable and faster then running a
X-Server over SSH.
More reliable then RDP connections.

2 VNC Server Installation

I am logged in my system as root user on


the shell (e.g. by ssh). Now I will install the
VNC-server.

apt-get install gnome-core xfce4


firefox

apt-get install vnc4server

Please make sure that you are using only


vnc-server & no other VNC-server are
installed as this could give errors in future
mostly that clipboard sharing between the
host Ubuntu Server & vnc-client machine. You
can check it as follows:

root@vboxtest ~ # dpkg -l | grep vnc


ii
vnc4server

4.1.1+xorg4.3.0-37ubuntu5
amd64 Virtual network
computing server software
root@vboxtest ~ #

3 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

Please uninstall if TightVNC or anything


similar installed.

3 Adding VNC user

In my case, I am using user=srijan it will


differ in your case. You can use any username
for the same.

adduser srijan

root@server1:~# adduser srijan


Adding user `srijan' ...
Adding new group `srijan' (1001)
...
Adding new group `srijan' (1001)
...
Adding new user `srijan' (1001)
with group `srijan' ...
Creating home directory `/home
/srijan' ...
Copying files from `/etc/skel' ...

Enter new UNIX password:


<--yourpassword
Retype new UNIX password:
<--yourpassword
passwd: password updated
successfully
Changing the user information for
srijan
Enter the new value, or press
ENTER for the default
Full Name []: <--ENTER
Room Number []:<--ENTER
Work Phone []:<--ENTER
Home Phone []:<--ENTER
Other []:<--ENTER
Is the information correct?
[Y/n]<--ENTER

Further, we need to start the vncserver with


the user, for this use:

4 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

su - srijan

vncserver

It will show this on the prompt:

srijan@server1:~$ vncserver

You will require a password to acce


ss your desktops.

Password:<--Put your VNC password


Verify:<--Put your VNC password
Password too long - only the first
8 characters will be used
xauth: file /home/srijan/.Xauthori
ty does not exist

New 'server1:1 (srijan)' desktop is


server1:1

Creating default startup script /ho


me/srijan/.vnc/xstartup
Starting applications specified in
/home/srijan/.vnc/xstartup
Log file is /home/srijan/.vnc/serve
r1:1.log

srijan@server1:~$

Now I am going to make backup of the


original file & then make the configuration as
follows:

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
> ~/.vnc/xstartup
vi ~/.vnc/xstartup

#!/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

5 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

x
s
e
t
r
o
o
t

-
s
o
l
i
d

g
r
e
y
v
n
c
c
o
n
f
i
g

-
i
c
o
n
i
c

&

It will have some issues with the gnome-vnc


session so please kill the present vnc session
as follows:

vncserver -kill :1

Further, I will make the startup script for the


vncserver like this:

6 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

su
vi /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_US
ER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
DISP="${display%%:*}"
export VNCUSERARGS="${VNCSERVERARGS[$
{DISP}]}"
su ${USER} -c "cd ~${USER} && [ -f .v
nc/passwd ] && vncserver :${DISP} ${VN
CUSERARGS}"
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_US
ER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
export USER="${display##*:}"
su ${USER} -c "vncserver -kill :${dis
play%%:*}" >/dev/null 2>&1
fi
done
echo -e "\n"
echo "VNCServer Stopped"
}

7 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

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|c
ondrestart|status}"
exit 1
esac

Now make it executable:

chmod +x /etc/init.d/vncserver

Next I will make the configuration file for the


vncserver by creating file as follows:

mkdir -p /etc/vncserver
vi /etc/vncserver/vncservers.conf

Give the entries like this.

VNCSERVERS="1:srijan"
VNCSERVERARGS[1]="-geometry 1024x768"

Here your port comes to be 5901 & 1024x768


resolution for the VNC client, you can choose
a resolution of your own choice.

8 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

Now I will add it into boot startups:

update-rc.d vncserver defaults 99

root@server1:~# update-rc.d vncserv


er defaults 99
Adding system startup for /etc/ini
t.d/vncserver ...
/etc/rc0.d/K99vncserver -> ../in
it.d/vncserver
/etc/rc1.d/K99vncserver -> ../in
it.d/vncserver
/etc/rc6.d/K99vncserver -> ../in
it.d/vncserver
/etc/rc2.d/S99vncserver -> ../in
it.d/vncserver
/etc/rc3.d/S99vncserver -> ../in
it.d/vncserver
/etc/rc4.d/S99vncserver -> ../in
it.d/vncserver
/etc/rc5.d/S99vncserver -> ../in
it.d/vncserver
root@server1:~#

And fFinally reboot the machine.

reboot

4 VNC Client

On the client side, my OS is Ubuntu 14.04


Desktop with the "vino" VNC Client software
installed. But you may use any other VNC
client as well. In case, other OS like
windows-7 you can e.g. install Realvnc-client
or TightVNC.

Now I am going to connect with the VNC


server through my VNC-client

9 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

It will prompt for the password as follows:

Enter the password as VNC password that you


had set for the user "srijan" on the server.

Now you are logged into the GUI of your


server.

Choose Use default config:

10 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

To setup the graphical user session. In case


you want to add more users to access the
vnc-console you need to add the user as
mentioned above & append the entry in the
file as:

vi /etc/vncserver/vncservers.conf

For instance I am using user kishore,


entries will be like this

[..]
VNCSERVERS="2:kishore"
VNCSERVERARGS[2]="-geometry 1024x768"

This will enable user kishore to get the access


to the VNC-server with the port 5902. In the
same way, you can add the root user also.
Congrats you have configured the VNC-server
successfully :)

view as pdf | print

Share this page:


Tweet

Follow @howtoforgecom 26.2K followers

Recommend 13

38 Comment(s)
Add comment
Name * Email *

11 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

Comments

From: Not a loser linux nerd like you Reply

This "tutorial" was clearly written by a linux


nerd who has never had to deal with another
human being in his life. While it does a good
job of explaining absolutely nothing, it misses
out on crucial details, like how to actually enter
data into vi. Note: vi was not written by a
human being. Therefore, human beings are
incapable of understanding its utterly byzantine
interface and backwards approach to data
entry.
Next time you have the urge to write more
tutorials, please kill yourself instead.

From: A nerd Reply

The tutorial was written assuming you have


Linux running on a machine that doesn't
have a GUI. If you're already using a
headless Linux box via ssh, it's not
unreasonable to assume that the reader
knows how to use vi.
Having said that, I'm not going to disagree
that if you don't know anything about vi and
you launch it, you're now in a world of
pain.

From: Jonti Reply

I've just followed the tutorial to set up a


VNC server, and I'm glad the author will
live to write other helpful guides
I was surprised to see vi being used for
editing. The occasional script editor like
myself is better served by nano, because

12 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

the vital keystroke commands are always


displayed on screen.

From: Anonymous Reply

I am commenting merely to say, you, sir


(Not a loser lin...) need to go dance through
a field of flowers and enjoy life. As others
said, clearly, if you have a headless *nix
install, you know what to do, or at least
how to recognize an editor command and
know how to use it, or an alternate (nano),
like I did.
As far as the guide, it was perfect, exactly
what I needed. A few simple commands just
to get VNC installed, and a great refresher
guide for those, like me, who dont always
work with Linux so tend to forget the simple
stuffs.

From: me Reply

I have to agree, I hate vi more than


anything, I can't understand why we are
here in 2015, and old dogs are still up to
their old tricks. Learn some new tricks!
I haven't used vi for years, and avoid it like
the plague.
When following these, simply replace "vi"
with "nano" and you will be much happier.
I suggest to these authors to do the same,
and it will improve their user feedback, and
limit frustration. It sucks if you take the
time to help people, then lose all of your
effort because of an antiquated and
frustrating line editor.

From: Ivan Reply

No one is born knowing this kind of stuff.


Vi, like many other unix technologies has to
be learned. I had a similar reaction many
years ago with my first introduction to vi but
like everything else I don't know, I studied
it and learned it. As the saying goes, better
to light a candle than to curse the darkness.

13 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

From: UbuntuUser Reply

Wonderful in explaining all the steps. It was


easy to follow and I am going to try.

From: Arash Reply

...
...
...
Wow... Speechless. Im absolutely speechless.
** starting up windows 7 **

From: Anonymous Reply

This /.vnc/xstartup configuration worked for


me:
# Uncomment the following two lines
for normal desktop:
unset SESSION_MANAGER
#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" &
xfce4-session &
startxfce4 &

From: Nathan R. Reply

I wanted to say thanks for this tutorial! I've


been messing with several today, and this is
the only one that worked. Great job and
thanks for putting this up!

My headless Ubuntu server is running happily


up on EC2, and I'm able to connect to it
graphically with no problems.

Nathan

From: Anonymous Reply

I'm setting up Ubuntu Studio to run as a


headless software synthesizer. This helped a
lot. Thanks very much!

14 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

From: votuduc Reply

Hello, Thank you so much for this great post.


I do follow all your steps, but I can not access
to my Ubuntu (EC2 Amazon) via VNC viewer. I
use Mac OS (10.9.5) + RealVNC (version 5.2.2)
and I have already created a security group on
Instance EC2 in order to enable port 5901.
I got error every time I try to connect to my
Ubuntu.
If I input DNS public like ec2-aa-bbb-ccc-
ddd.ap-southeast-
1.compute.amazonaws.com into VNC viewer,
then I always got error as "The connection was
refused by the host computer".
If I input Private IPs:port like
aa.bb.cc.dd:5901, then I get error as "Timed
out waiting for a response from the host
computer".
The VNCServer has installed successfully as I
get some message as below:

--command:
myuser@myserver:~$ service vncserver start
-- result:
Starting VNC server: 1:myuser Password:
A VNC server is already running as :1
-- command: myuser@myserver:~$ service
vncserver stop

Shutting down VNCServer: 1:myuser.


//// Could you please give me an advise? I
spend a lot of time to read a lot of tutorial, but
I still can not access to Ubuntu via VNC.
Best and Regards,
DUC

From: ubuntino88 Reply

hi,
why if I add a second user following the
instructions in this guide TightVNC and
VNCviewer give me this error: Error in
TightVNC Viewer: Unable to establish
connection . Persistent refusal of the target
computer. ?????
This error is given to me also in the first user,
that work correctly before I've put the second

15 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

user!!!!
If I delete the second user, the first user return
to work correctly!!!
any advice???
thanks!
ubuntino88

From: Evelyne Lachance Reply

The server won't start when attempting to


use sudo service vncserver start.
The error I get is the following: /etc/init.d
/vncserver: 2: /etc/vncserver/vncservers.conf:
VNCSERVERARGS[1]=-geometry 1024x768:
not found
I tried to put 800x600 and get the same error
(with different geometry).
My google-fu fails me on this one, anyone have
any ideas?

From: herp Reply

did you put -geometry 1024x768 in quotes?


like so:
VNCSERVERARGS[1]="-geometry
1024x768"
? that could be a problem if you didn't...

From: Denis Reply

Oh, vnc4server, tightvncserver it's old


development and not actual. Good practice is
TigerVNC (http://tigervnc.org/)

From: TitinoBambino Reply

Interesting and funny but useless comment...


:-)
The set of instructions provided by the autor
are 100% correct, the use of one or another
editor is an unimportant subject, it doesn't
actually matter what editor you use, instead of
VI, I used one of my choice to get the same
things done. and everything works as
explained.
Now, if happens to you (as happened to me),
that vncserver was not what I was actually
looking for, here are the set of instructions to

16 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

undo everything:
vncserver -kill :# (where # is the
current vncserver running)
rm ~/.vnc/xstartup
rm /etc/vncserver/vncservers.conf
rm /etc/init.d/vncserver
update-rc.d -f vncserver remove
apt-get remove --purge vnc4server
apt-get autoremove
(just in case)
mv ~/.vnc/xstartup.bak ~/.vnc/xstartup
Still gnome-core, xfce4 and firefox installed
initially will remain, it is up to you if you want
to remove them as well, those won't harm
anyway.
Is not my intention to explain the above
commands, just list the set of steps required to
undo the install procedure proposed here.
It is supposed that users come here knowing a
little bit of Linux

From: mstreet Reply

What ARE all those packages installed by


the first command. Once I saw everything
the first command planned to install, I
backed out. The second command worked
fine, and the server seems to be installed
correctly (though not tested).
So is all that core\xfce4\firefox stuff
neccessary?

From: herp Reply

Have you tried using your VNCclient to login to


your VNCserver at port :1? That's what i
needed to do.
So, at VNCclient prompt: xxx.xxx.xxx.xxx:#
where xxx.xxx.xxx.xxx is your server's ip (on
ec2, this will be your public ip or instead just
your public dns hostname), and # is your
vncServer session you want to connect to - in
this tutorial they set up 1:youruser, and so you
would want # to be 1 for that user. Hope that
helps...

17 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

From: Roger Crawford Reply

Much appreciated. Your startup script works! I


needed that.

From: Lucas Reply

THis works splendidly, however, i cannot logout


from the session?The GUI just hangs.

From: ivan Reply

Even though some people disliked, I just have


to congrat the writer of this tutorial because,
after 48 hours of desesperated searching and
failed tries, I finally understood and finnished in
the first time this installation totally usable.
Thanks a lot Mister, and to be more precise,
I've only been using Linux for one mounth.

From: PCITGUYS Reply

This is a excellant how to instructions.. I am


only haveing one issue. The VNC does not start
when the system is rebooted. anyway to
correct that?

From: linux basic Reply

Hi,
I followed these steps, But for me, getting a
gray screen only. How can fix this ?

From: Douglas Reply

Getting these errors:insserv: warning: script


'K01vncserver' missing LSB tags and
overridesinsserv: warning: script 'vncserver'
missing LSB tags and overrides

From: till Reply

Thats ok, it just means that the start script


has no LSB tags. You can ignore that
warning.

From: Linux, not windows Reply

18 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

If you do not know how to use linux, then don't


read a guide on how to install "VNC Server On
Ubuntu 14.04". vi saves you so much time
when dealing with Linux on a day to day basis,
something which you clearly don't do. Go back
to your OS for people that don't know how a
computer really works. You're just interested in
the sausage, not how it's made. Oh looks, it's a
pretty desktop shortcut - when you click on it,
nice things happen...

From: Ivan S Kirkpatrick Reply

This was the first time I setup vnc successfully.


Your tutorial worked very well and I had no
trouble with it at all. I use vim instead of vi but
effectively it is a good tutorial. I really
appreciate your work.

From: yousef alhajeri Reply

Thanx a lot, its not easy to find a simple


tutorial that does work on linux for alsmot
anything.

keep on with the good work

From: jbsquared Reply

Very useful tutorial - thanks.


I agree with 'Linux, not windows' if you don't
know how to use linux - then don't read it, and
if you don't like vi - use something else!

From: kid Reply

Did not work for me at all. I went through this


tutorial twice on brand new VMs. The first time,
nothing worked at all. The second time it kinda
works if I startup the vncserver myself, but if I
do it under the second account you had me
create then all I got was a gray screen. If I
ignored the user you had me create, still not
sure why you did that, and startup VNC as the
user I originally logged in as. Then I get a UI in
VNC but there is nothing there. Nothing shows.
I get a mouse and a console window that is

19 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

blank. The server is pretty much unusable in its


current state. I don't think this is a very good
tutorial and it seems strange to me to have to
go through this much pain simply to install
VNC. A whole day wasted. Pretty silly.

From: till Reply

Not sure what you did wrong. I just tested


the guide and it works out of the box on
Ubuntu 14.04, everything shows up on the
desktop and mouse and keyboard are
working.

From: ColumG Reply

Good tutorial! Many thanks for your fine work


here.

From: Malibu Reply

Thank you 1 million times, bless u :D


It works! Problem solved, it's so easy, thanks
thanks thanks :D :D :D

From: Dave Reply

My tightvnc seems to only be listening to port


5901 from localhost, how can I get to to listen
to connections from other hosts on the local
network to avoid requiring an SSH tunnel?

From: Alfonso Castellanos Reply

Wow! It worked as a charm. Many Thanks!!!!

From: Andrew Reply

hi..i installed vnc as guided by your tutorial..but


when i try to restart..ubuntu is unable to
reboot..any suggestions?

From: andertavares Reply

Awesome tutorial. Be sure that you helped


many many people!

20 of 21 2/10/2017 3:27 PM
How To Install VNC Server On Ubuntu 14.04 https://www.howtoforge.com/how-to-install-vnc-server-on-ubuntu-14.04

Tutorials How To Install VNC Serv…

Xenforo skin by Xenfocus Contact Help Imprint Tutorials Top


RSS-Feed
Howtoforge © projektfarm GmbH. Terms

21 of 21 2/10/2017 3:27 PM

Você também pode gostar