PDA

View Full Version : [TUT] Install VNC server on Ubuntu



Chillivanilli
10-13-2014, 05:39 PM
Because of an exploit ( btw.: to be a VIP on a2s rocks! :) ) some people asked me how to setup a linux VPS for desktop connection like RDP on Windows.

Here is a simple step by step guide for absolute beginners how to connect to your Ubuntu VPS (the commands on other linux OS are a bit different).
You can't really make mistakes by using this guide.

Requirements for your home PC:
- Tight VNC(DOWNLOAD) (http://www.tightvnc.com/download.php)
- PuTTY (DOWNLOAD) (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)


1. Open a connection from PuTTY
Type in the IP from your server and the port (default is 22, so if you don't know the port, dont edit it) and click on "open"
http://i.imgur.com/LmYzdxX.png

Then you'll see a console window asking you "login as".
Type in: root and click enter, then type in your password and click enter.

Note
When you type there are no characters or *** shown, so you have to take a look at your keyboard to avoid making mistakes. After that your console will look like this:
http://i.imgur.com/qZQzB8I.png

You find this easy? Great, because that was the hardest part, after that you will only do copy and paste work!
Copy / paste in PuTTY is not like on windows "CTRL + C ; CTRL +V".
If you want to copy something from Windows, just use CTRL + C, but if you want to paste it in the console, just do a right click it gets pasted.

2. Update and upgrade Ubuntu

apt-get update; apt-get dist-upgrade -y --force-yes
Depending on the internet connection of your VPS this will normally take about 10-20 seconds

3.Install GUI on Ubuntu 14.04 Server

apt-get install xubuntu-desktop xfce4 firefox nano -y --force-yes
This will take a little bit more time, so just wait until its finished.

4. Install VNC Server on Ubuntu 14.04

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

5. Add a user + password
Now you'll need to add a user and a password with which you want to login to vnc. In this case it's the user "vncuser"

adduser vncuser

6. Switch to the created user

su - vncuser

7. Start VNC server
This is needed because VNC server needs to create some files first, which we can edit after this step

vncserver

8. Kill VNC server

vncserver -kill :1

9. Edit xstartup file
This will be a little bit more complicated now, but don't worry, it's also very easy if you follow my steps:

nano .vnc/xstartup

You will see something like this now:
http://i.imgur.com/dDpNHV0.png

Now press the DEL key on your keyboard and delete everything!
When you are done, just copy this code and paste it:


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

Now press CTRL + X to save it.
Now press Y to confirm it and press enter to finally save the file.

10. Get root access and edit vncserver file

su -
Enter your root password now and hit enter.


nano /etc/init.d/vncserver

This creates a new file. Now paste this code into the file again:


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

Press CTRL + X, then press Y and finally ENTER to save the file.

11. Make the VNC startup script executable

chmod +x /etc/init.d/vncserver

12. Create the VNC server config file
Create the directory

mkdir -p /etc/vncserver

Create the file

nano /etc/vncserver/vncservers.conf

Copy and paste this code again now:


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

Press CTRL + X, then Y, then ENTER to finally save the file.

12. Make VNC server start on boot

update-rc.d vncserver defaults 99

13. Reboot your VPS
Finally you need to reboot your VPS

reboot


14. Connect with TightVNC
Now you'll need to connect to your VPS with TightVNC.
Open TightVNC Viewer and put in your IP address. After the IP address, write :1
That means that you are connecting to the IP on port 1.
http://i.imgur.com/XTBzP0a.png

Finally click on "connect".
You will be asked for a password. Enter your password which you've chosen to you vncuser.

Now you are connected via desktop connection with your VPS!
It will look like this:
http://i.imgur.com/x4uV45U.png

Click on "Use default config".
Congratulations, that's it! You have created a desktop connection to Ubuntu 14.04!


NOTE:
If you want to run my java bots which i posted in the subscriber section, you'll need to download java first and after you've done that you'll need to mark the .jar file as executable.
If you don't mark it as executable, the following error will occur:
http://i.imgur.com/vuwlny1.png


To install java, click here:
http://i.imgur.com/LgP0Dxk.png

Then search for OpenJDK Java 7 and click on install.
http://i.imgur.com/ezyWbO9.png

Now open the Terminal.
Type in this code:

chmod +x pathtothefile

In my case to mark my iRazoo bot as executable i have to type in this code:
chmod +x /home/vncuser/Desktop/iRazooBot_v1.4_by_Chillivanilli/irazoo_bot_v_1_4.jar


Thats it!
I hope you enjoyed my step by step tutorial and could create a VNC connection to your Ubuntu VPS.
If you have any questions, feel free to ask!

Pikachu
10-13-2014, 10:06 PM
Wish i could give you 10000 thanks. Full detailed and explained, well done Chilli!

medsamy
10-13-2014, 10:35 PM
in my case i just need to enter these commands to enable xrdp on ubuntu with Bitvise SSH Client

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ubuntu-desktop
sudo apt-get install --no-install-recommends ubuntu-desktop
sudo apt-get install xrdp
echo "gnome-session --session=ubuntu-2d" > ~/.xsession
sudo apt-get install gnome-session-fallback

big thanks to you Chilli for this tuto

Kunkka
10-13-2014, 10:39 PM
Thanks for the detailed guide Chilli! :D

This will not make me confuse again :D

funaddaa
10-14-2014, 02:42 AM
Thank you very much Chillivanilli for the details guide
i don't know anything about Ubuntu...but this guide will help me a lot:prettiness:

BeyondZero
10-14-2014, 05:31 PM
For installing java faster:

1) Check if there is java already installed "java -version" in console
2) If it returns "The program java can be found in the following packages" then just copy and paste this: "apt-get install default-jre"

If it gives you a java version that you have, you clearly have java already :D

Co0oL
10-15-2014, 08:55 PM
Just to explain this a bit.
This isn't just VNC, VNC is like teamviewer, It only allows you to see what's happening on desktop and doesn't give you any kind of desktop, What you are using is called Ubuntu desktop which I don't recommend because It uses much RAM.
I suggest using LXDE desktop, Uses 60 MB ram only, I've it running on 128 MB vps like charm (haphost vps[free])
Thanks for this anyway :)

Chillivanilli
10-15-2014, 10:28 PM
Just to explain this a bit.
This isn't just VNC, VNC is like teamviewer, It only allows you to see what's happening on desktop and doesn't give you any kind of desktop, What you are using is called Ubuntu desktop which I don't recommend because It uses much RAM.
I suggest using LXDE desktop, Uses 60 MB ram only, I've it running on 128 MB vps like charm (haphost vps[free])
Thanks for this anyway :)

Thanks for the explanation.
I'm not really into linux and also made this tutorial based on another one (copied the commands).

I'll try to install LXDE dekstop on one of my vps and see if it saves that much performance :)

tutudragon3
10-16-2014, 03:18 AM
that's a lot of unnecessary steps. Here's what I do that ends up doing the same thing
install ubuntu desktop, vnc4server, xfce4

then you run the following commands
vncserver
vncserver -kill :1
nano /root/.vnc/xstartup
add this "startxfce4 &" at the end of the file and save
vncserver

all done

bluelight
10-18-2014, 02:32 AM
Chillivanilla, this guide was on point. The only thing is that it would not connect to the internet.

I contacted support and it was fixed. I've been trying to do this for some time. Thanks.

Can I find the irazoo bot listed in the Subscriber Section?

Chillivanilli
10-18-2014, 12:32 PM
Chillivanilla, this guide was on point. The only thing is that it would not connect to the internet.

I contacted support and it was fixed. I've been trying to do this for some time. Thanks.

Can I find the irazoo bot listed in the Subscriber Section?

If you can't connect to the internet it's a problem of the provider.
Yes the bot is listed in the subscriber section.

medsamy
10-18-2014, 01:03 PM
Just to explain this a bit.
This isn't just VNC, VNC is like teamviewer, It only allows you to see what's happening on desktop and doesn't give you any kind of desktop, What you are using is called Ubuntu desktop which I don't recommend because It uses much RAM.
I suggest using LXDE desktop, Uses 60 MB ram only, I've it running on 128 MB vps like charm (haphost vps[free])
Thanks for this anyway :)

can you share console commands for LXDE, iam using haphost free also

kid1490
10-19-2014, 11:57 PM
how much space this require? if is more than 3 gb then i need to look for other method lulz, ths a lot Chillivanilli you are my idol :P

Chillivanilli
10-20-2014, 12:51 PM
how much space this require? if is more than 3 gb then i need to look for other method lulz, ths a lot Chillivanilli you are my idol :P

Ubuntu Desktop is about 1gb
Thanks for the nice words :)

Chillivanilli
10-25-2014, 11:18 AM
Just to explain this a bit.
This isn't just VNC, VNC is like teamviewer, It only allows you to see what's happening on desktop and doesn't give you any kind of desktop, What you are using is called Ubuntu desktop which I don't recommend because It uses much RAM.
I suggest using LXDE desktop, Uses 60 MB ram only, I've it running on 128 MB vps like charm (haphost vps[free])
Thanks for this anyway :)

I tried installing lxde light + only the programs i need, but for some reason when i start my bots it is slow like hell. I open firefox and it takes about 5-10 seconds to load a new site. When i click an item it also takes much more time. When i looked into my ressources with free -m there was much more free ram.

I reinstalled ubuntu desktop again and it was running smooth again but i had a higher ram usage.

Any idea?

Co0oL
10-28-2014, 08:03 AM
Well, In the end, It's a light desktop interface, You can't expect it to work functional as well as Ubuntu Desktop (which is originally made for ubuntu lol)
I use LXDE desktop to run Hitleap on Ubuntu 14.04 (Could install it for anyone, Just hit me with a PM)

avenger
11-02-2014, 06:38 PM
thank you chili, this is very detailed guide

fedi96
03-12-2015, 08:36 PM
thanks bro :)

fedi96
03-14-2015, 11:26 AM
Because of an exploit ( btw.: to be a VIP on a2s rocks! :) ) some people asked me how to setup a linux VPS for desktop connection like RDP on Windows.

Here is a simple step by step guide for absolute beginners how to connect to your Ubuntu VPS (the commands on other linux OS are a bit different).
You can't really make mistakes by using this guide.

Requirements for your home PC:
- Tight VNC(DOWNLOAD) (http://www.tightvnc.com/download.php)
- PuTTY (DOWNLOAD) (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)


1. Open a connection from PuTTY
Type in the IP from your server and the port (default is 22, so if you don't know the port, dont edit it) and click on "open"
http://i.imgur.com/LmYzdxX.png

Then you'll see a console window asking you "login as".
Type in: root and click enter, then type in your password and click enter.

Note
When you type there are no characters or *** shown, so you have to take a look at your keyboard to avoid making mistakes. After that your console will look like this:
http://i.imgur.com/qZQzB8I.png

You find this easy? Great, because that was the hardest part, after that you will only do copy and paste work!
Copy / paste in PuTTY is not like on windows "CTRL + C ; CTRL +V".
If you want to copy something from Windows, just use CTRL + C, but if you want to paste it in the console, just do a right click it gets pasted.

2. Update and upgrade Ubuntu

apt-get update; apt-get dist-upgrade -y --force-yes
Depending on the internet connection of your VPS this will normally take about 10-20 seconds

3.Install GUI on Ubuntu 14.04 Server

apt-get install xubuntu-desktop xfce4 firefox nano -y --force-yes
This will take a little bit more time, so just wait until its finished.

4. Install VNC Server on Ubuntu 14.04

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

5. Add a user + password
Now you'll need to add a user and a password with which you want to login to vnc. In this case it's the user "vncuser"

adduser vncuser

6. Switch to the created user

su - vncuser

7. Start VNC server
This is needed because VNC server needs to create some files first, which we can edit after this step

vncserver

8. Kill VNC server

vncserver -kill :1

9. Edit xstartup file
This will be a little bit more complicated now, but don't worry, it's also very easy if you follow my steps:

nano .vnc/xstartup

You will see something like this now:
http://i.imgur.com/dDpNHV0.png

Now press the DEL key on your keyboard and delete everything!
When you are done, just copy this code and paste it:


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

Now press CTRL + X to save it.
Now press Y to confirm it and press enter to finally save the file.

10. Get root access and edit vncserver file

su -
Enter your root password now and hit enter.


nano /etc/init.d/vncserver

This creates a new file. Now paste this code into the file again:


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

Press CTRL + X, then press Y and finally ENTER to save the file.

11. Make the VNC startup script executable

chmod +x /etc/init.d/vncserver

12. Create the VNC server config file
Create the directory

mkdir -p /etc/vncserver

Create the file

nano /etc/vncserver/vncservers.conf

Copy and paste this code again now:


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

Press CTRL + X, then Y, then ENTER to finally save the file.

12. Make VNC server start on boot

update-rc.d vncserver defaults 99

13. Reboot your VPS
Finally you need to reboot your VPS

reboot


14. Connect with TightVNC
Now you'll need to connect to your VPS with TightVNC.
Open TightVNC Viewer and put in your IP address. After the IP address, write :1
That means that you are connecting to the IP on port 1.
http://i.imgur.com/XTBzP0a.png

Finally click on "connect".
You will be asked for a password. Enter your password which you've chosen to you vncuser.

Now you are connected via desktop connection with your VPS!
It will look like this:
http://i.imgur.com/x4uV45U.png

Click on "Use default config".
Congratulations, that's it! You have created a desktop connection to Ubuntu 14.04!


NOTE:
If you want to run my java bots which i posted in the subscriber section, you'll need to download java first and after you've done that you'll need to mark the .jar file as executable.
If you don't mark it as executable, the following error will occur:
http://i.imgur.com/vuwlny1.png


To install java, click here:
http://i.imgur.com/LgP0Dxk.png

Then search for OpenJDK Java 7 and click on install.
http://i.imgur.com/ezyWbO9.png

Now open the Terminal.
Type in this code:

chmod +x pathtothefile

In my case to mark my iRazoo bot as executable i have to type in this code:
chmod +x /home/vncuser/Desktop/iRazooBot_v1.4_by_Chillivanilli/irazoo_bot_v_1_4.jar


Thats it!
I hope you enjoyed my step by step tutorial and could create a VNC connection to your Ubuntu VPS.
If you have any questions, feel free to ask!

chilli what's this problem ?
http://i.imgur.com/9iAfSb5.png

Chillivanilli
03-14-2015, 11:37 AM
chilli what's this problem ?
http://i.imgur.com/9iAfSb5.png

I dont know.. I'd say that this vps got some restrictions and you cannot install software? Can you install other things? From which provider is this vps?

fedi96
03-14-2015, 11:39 AM
I dont know.. I'd say that this vps got some restrictions and you cannot install software? Can you install other things? From which provider is this vps?

i've rented it from my friend ( idon't know which provider )... i can't install any software

Chillivanilli
03-14-2015, 11:40 AM
i've rented it from my friend ... i can't install any software

Then ask your friend... ;)

fedi96
03-14-2015, 11:48 AM
Then ask your friend... ;)

ok thanks for support :burn:

Boner Assault
03-20-2015, 06:37 AM
xRDP is a lot better IMO. These VNC viewers are buggy as hell.