Tag Archives: ubuntu

How to install VNC server on Ubuntu Server 12.04

   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

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

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 1024×600” 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 doesn’t exist):

sudo mkdir -p /etc/vncserver
sudo touch /etc/vncserver/vncservers.conf
sudo nano /etc/vncserver/vncservers.conf

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)
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

We’ll 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

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 &

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:

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:

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

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:

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:

Upon successful connection to VNC Server, we’ll 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:

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

Advertisements

How to backup data from crashed Windows system

Sometimes, our Windows systems crashed for no reason because it is windows and it doesn’t need a reason to crash 🙂

But sometimes in this situation, we want to access our important files on urgent basis. So, in this tutorial, I will try to show you, how we can do this.

First download the latest version of Ubuntu Desktop and burn the ISO image on a CD or make a bootable USB.Put the Ubuntu CD/USB in the System that has been crashed and wait for the desktop to load:

Click on “Try Ubuntu” and it will present you with the Live Desktop of Ubuntu:

In order to open the Terminal,press “Ctrl + Alt + T”  and type:

gksudo nautilus

By typing this command, it will start temporary windows in which you have full access to all the files like Root user, then within the nautilus windows, click on your hard disk and copy your desired files to an external USB/Media.

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

OSPF routing between Cisco,Ubuntu,CentOS and Mikrotik Router!

Scenario:

  • Routers: 1 Ubuntu Linux with 3 nics, 1 Centos Linux with 3 nics, 1 Cisco 3640 Router with 3 FastEthernet interfaces and 1 Mikrotik Router with 2 interfaces.
  • Clients: 3 Windows Xp with 1 nic.
IP Details

All the Routers in this scenario have a default password of “zebra“.

Cisco Router:

  • fe0/0: 10.10.10.1/24
  • fe1/0:10.10.50.1 /24
  • fe2/0: Getting through DHCP

UbuntuRouter:

  • eth0: 10.10.10.2/24
  • eth1: 172.16.10.1/24
  • eth2: 10.10.100.1/24

CentOSRouter:

  • eth0: 172.16.10.2/24
  • eth1: 192.168.10.1/24
  • eth2: 10.10.150.1/24

Mikrotik Router:

  • ether1: 192.168.10.2/24
  • ether2: 10.10.200.1/24

Clients:

  • Ubuntu-Desktop: 10.10.50.50/24
  • WinXP-1: 10.10.100.50/24
  • WinXP-2: 10.10.150.50/24
  • WinXP-3: 10.10.200.50/24

Cisco Router Configuration:

UbuntuRouter Configuration:

Restart the Router!!!

CentOSRouter Configuration:

Restart the Router!!!

Mikrotik Router Configuration:

Neighbor verification from Routers:

Route verification from Routers:

Test from Clients:

Make a simple test from Ubuntu-Desktop.

Make a simple test from WinXP-1.

Make a simple test from WinXP-2.

Make a simple test from WinXP-3.

Configure NAT on Cisco Router:

This is just a bonus section, in which we will configure the NAT on Cisco router and also propagate the default route in OSPF. I connect my Cisco Router to DSL Modem and configure it so that it will take IP address through DHCP, as well as configure the inside and outside interface for NAT.

Lazy man access -list for NAT (This is not the perfect access list):

NAT Overload:

Originate the default route in OSPF:

Verify the last resort information on Cisco Router:

Check default route information on all routers 🙂

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

OSPF routing between Ubuntu and CentOS using Quagga

Topology:

Scenario:

  • Routers: 1 Ubuntu Linux with 2 nics, 1 Centos Linux with 2 nics.
  • Clients: 2 Windows 7 with 1 nic.

IP Details:

All the Routers in this scenario have a default password of “zebra“.

UbuntuRouter:

  • eth0: 192.168.10.1/24
  • eth1: 10.10.10.1/24

CentOSRouter:

  • eth0: 192.168.10.2/24
  • eth1: 172.16.10.1/24

Clients:

  • Dektop: 172.16.10.50/24
  • Laptop: 10.10.10.50/24

Read more of this post

InterVLAN Routing using Ubuntu with 1 Interface

Scenario:
  • Router: Ubuntu Server with 1 network card.
  • Clients: 2 WindowsXP in VLAN10,1 Ubuntu and 1 CentOS in VLAN20.
  • Switch: Cisco 2960
Cisco 2960 Switch Configuration:
interface FastEthernet0/1
description CONNECTED TO UBUNTU ROUTER
switchport mode trunk
!
!
!
interface FastEthernet0/5
description WINXP-1
switchport access vlan 10
switchport mode access
!
interface FastEthernet0/6
description WINXP-2
switchport access vlan 10
switchport mode access
!
!
!
interface FastEthernet0/15
description UBUNTU CLIENT
switchport access vlan 20
switchport mode access
!
interface FastEthernet0/16
description CentOS CLIENT
switchport access vlan 20
switchport mode access
 Ubuntu Router Configuration:

To install the vlan support on ubuntu, use this command:

sudo apt-get install vlan

Now we shall configure the vlans on Ubuntu router by editing the /etc/network/interfaces:

sudo nano /etc/network/interfaces

To enable ip forwarding, edit /etc/sysctl.conf file:

sudo nano /etc/sysctl.conf

Change net.ipv4.ip_forward from 0 to 1:

Load “8021q” kernel module:

(Optional): If the Ubuntu router didn’t load the 8021q kernel module at boot time, then use this command to add  the module to the kernel on boot:

sudo su -c 'echo "8021q" >> /etc/modules'

Restart the Networking service:

sudo /etc/init.d/networking restart

Use the ifconfig command to check the newly created vlan interfaces:

ifconfig

Verify the vlan configuration:

sudo cat /proc/net/vlan/config

Test from WinXP-1:

Test from WinXP-2:

Test from Ubuntu Client:

Test from CentOS Client:

Hope this will help you!

Please Remember me in your prayers!

Mercurial Server on Ubuntu 12.04 LTS with Web Access

First we shall verify the version of the Ubuntu server that is running on our machine!

lsb_release -a

Install the Apache if you haven’t it already on your server!

sudo apt-get install apache2

Test the apache directly from the shell by doing a wget to the localhost. You will see the 200 OK response code.

Now install the Mercurial using the following command:

sudo apt-get install mercurial

Check the version of installed mercurial server:

hg --version

Let’s configure the master hgrc configuration file in order to remove the SSL restriction, allow to push the repository through web and trust the apache user (www-data).

sudo nano /etc/mercurial/hgrc

Add these lines to the hgrc file:

[web]
allow_push = *
push_ssl = false
allow_archive = gz, zip, bz2
[trusted]
users = www-data

Now configure the directory where Mercurial will keep all its repositories and serve them through Apache!

cd /
sudo mkdir mercurial
sudo mkdir mercurial/repositories
sudo chown -R www-data:www-data /mercurial

Let’s configure the hgweb.config!

cd /mercurial
sudo nano hgweb.config

Enter the following lines:

[web]
style = gitweb
[collections]
/mercurial/repositories = /mercurial/repositories

Let’s configure the hgweb.cgi script in order to serve the repositories via Apache:

sudo cp /usr/share/doc/mercurial/examples/hgweb.cgi /mercurial
cd /mercurial
sudo chmod a+x hgweb.cgi

Open hgweb.cgi with nano:

sudo nano hgweb.cgi

Find the line that reads config=”…..” and replace with the following line:

Now we shall configure the Apache so it runs the hgweb.cgi when the /mercurial virtual directory is requested.

cd /etc/apache2
sudo mkdir mercurial
cd mercurial
sudo nano mercurial.conf

Type the following in the mercurial.conf file:

Move to the apache sites directory and edit the default file:

cd /etc/apache2/sites-available
sudo nano default

Enter the command in order to link the mercurial.conf file to Apache:

Include /etc/apache2/mercurial/mercurial.conf

Restart the apache server:

sudo apache2ctl restart

Now create a first repository as test, inside the /mercurial/repositories:

cd /mercurial/repositories
sudo mkdir first_repo
cd first_repo
sudo hg init

Change the owner of the repository to the Apache user:

sudo chown -R www-data:www-data /mercurial

To configure the security, we have to tell the Apache that allow only those users who are registered in the password file.

cd /mercurial
sudo htpasswd -mc hgusers arbab 
sudo chown www-data:www-data hgusers

Note: repeat command for more users without adding c.

Time to Test, Launch your browser pointing to http://servername/mercurial:

In order to add the “Description” and “Contact” detail, do the following steps:

cd /mercurial/repositories/first_repo/
cd .hg
sudo nano hgrc

Add these lines to hgrc:

[web]
contact = Arbab Nazar
description = First Mercurial Repository!

Refresh your browser, now you will see the contact and the descriptio 🙂

To solve the push permission denied error:

cd /mercurial/repositories
cd first_repo
sudo chmod -R 777 .hg

Again do it!!!

sudo chown -R www-data:www-data /mercurial

Congrats! now we have a working Mercurial server on Ubuntu 12.04 :-)

Hope this will help you!

Please Remember me in your prayers!

RIP routing between Ubuntu and CentOS using Quagga

Topology:

Scenario:

  • Routers: 1 Ubuntu Linux with 2 nics, 1 Centos Linux with 2 nics.
  • Clients: 2 Windows 7 with 1 nic.
IP Details

All the Routers in this scenario have a default password of “zebra“.

UbuntuRouter:

  • eth0: 172.16.10.1/24
  • eth1: 10.10.10.1/24

CentOSRouter:

  • eth0: 172.16.10.2/24
  • eth1: 192.168.10.1/24

Clients:

  • Dektop: 192.168.10.50/24
  • Laptop: 10.10.10.50/24
UbuntuRouter Configuration:

Restart the Router!!!

CentOSRouter Configuration:

Restart the Router!!!

Troubleshooting Steps for CentOS:

Verification from Routers 🙂

Test from Clients 🙂

Make a simple test from Laptop.

Make a simple test from Desktop.

Hope this will help you!

Please Remember me in your prayers!

How to install Webmin on Ubuntu 12.04

Webmin is a web-based interface for system administration for Linux/Unix. You can setup user accounts, Apache, DNS,DHCP, file sharing and much more by using any modern web browser.

First, we need to install the dependencies with the command:

sudo apt-get install perl libnet-ssleay-perl libauthen-pam-perl libpam-runtime 

openssllibio-pty-perl apt-show-versions python

Now, we need to download the Webmin deb package from Sourceforge (I download it  in /tmp directory):

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.580_all.deb

Then just run the command :

sudo dpkg --install webmin_1.580_all.deb

Webmin is installed now and you will be able to access it via a browser using, https://server-ip:10000. In my case it is,https://tendo:10000.

(It will show you the security warning, just accept it)

Enter your Username and Password that you use for login on to your server.

After login, Webmin main page will show you the summary of your server:

Hope this will help you!

Please Remember me in your prayers!

%d bloggers like this: