Categories
Linux

Creating a new Debian package using pbuilder: gnujump

Yet another practical packaging session, this ine on how to build a Debian package from scratch. This one too is based on the packaging tutorial and practical sessions of Lucas Nussbaum.

We are going to download the source code of gnujump from upstream, and use the pbuilder tool to package it. The advantages of pbuider is that it creates a minimal chroot jail that helps you track any dependencies you might forgot to specify in debian/control. Also it gives you the opportunity to build Debian packages on Ubuntu and vice-versa. You can also build packages for releases other than your own.

Prerequisites

  • A recent Debian or Ubuntu system.

Preparation of the pbuilder jail

Install pbuilder and relevant packages:

$ sudo apt-get -y install pbuilder debootstrap devscripts packaging-dev debian-keyring ubuntu-archive-keyring

NOTE: use ubuntu-keyring instead of ubuntu-archive-keyring if your build station is Ubuntu

Prepare the target environment. For example for Ubuntu trusty use can use this setup:

$ sudo pbuilder create --debootstrapopts --variant=buildd --mirror http://cy.archive.ubuntu.com/ubuntu --distribution trusty --architecture amd64 --components main --debbuildopts -mJohn Doe <john.doe@example.net>

Prepare the new package

  1. Download the source:
    $ wget https://ftp.gnu.org/gnu/gnujump/gnujump-1.0.8.tar.gz
    
  2. Extract the archive and change into the source tree:
    $ tar xvzf gnujump-1.0.8.tar.gz
    $ cd gnujump-1.0.8/
    

Prepare for debian packaging

  1. We are going to use the dh_make utility to prepare the debian directory and all the necessary files:
    $ DEBFULLNAME="John Doe" DEBEMAIL="john.doe@example.net" dh_make -s -y --createorig
    

    Check if all necessary files are there:

    $ find debian/
    debian/
    debian/compat
     debian/manpage.1.ex
    debian/preinst.ex
    debian/rules
    debian/gnujump.default.ex
    debian/README.Debian
    debian/copyright
    debian/gnujump.cron.d.ex
    debian/gnujump.doc-base.EX
    debian/changelog
    debian/README.source
    debian/control
    debian/menu.ex
    debian/manpage.sgml.ex
    debian/docs
    debian/init.d.ex
    debian/source
    debian/source/format
    debian/watch.ex
    debian/postrm.ex
    debian/prerm.ex
    debian/manpage.xml.ex
    debian/postinst.ex
    

    Now Check the contents of the debian/changelog, debian/rules and debian/control files.

  2. We will need to make some changes in the debian/control file:

    Source: gnujump
    Section: games
    Priority: optional
    Maintainer: John Doe <john .doe@example.net>
    Build-Depends: debhelper (>= 9), autotools-dev, libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev
    Standards-Version: 3.9.5
    Homepage: http://gnujump.es.gnu.org
    ...
    

    The libsdl1.2-dev, libsdl-image1.2-dev and libsdl-mixer1.2-dev have been discovered by repeatedly compiling and failing until you get it right. The you can use the apt-cache search and apt-file search commands to discover the packages corresponding to the missing dependencies.

  3. Edit the debian/rules file to look like this:

    DH_VERBOSE = 1
    
    DPKG_EXPORT_BUILDFLAGS = 1
    include /usr/share/dpkg/default.mk
    
    export DEB_BUILD_MAINT_OPTIONS = hardening=+all
    
    export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
    export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
    
    %:
            dh $@  --with autotools-dev
    
    CFLAGS += -lm
    

  4. Edit the debian/changelog, with dch -e, to look like this:
    gnujump (1.0.8-1) unstable; urgency=low
    
      * Initial release
    
     -- John Doe</john><john .doe@example.net>  Mon, 22 Jun 2015 17:41:22 +0300
    

Build the package

Run this command from the source tree:

$ pdebuild

Give your password when asked. pdebuild will download and install all dependencies in the pbuilder jail and then build the package. Changes will be lost from the jail, the next time you use it but if all goes well, you should see these files under /var/cache/pbuilder/result:

$ ls -la /var/cache/pbuilder/result/
total 5776
drwxr-xr-x 2 root      root         4096 Ιούν 22 17:52 .
drwxr-xr-x 9 root      root         4096 Ιούν 22 11:26 ..
-rw-r--r-- 1 john john    1449 Ιούν 22 17:52 gnujump_1.0.8-1_amd64.changes
-rw-r--r-- 1 john john 1560574 Ιούν 22 17:52 <strong>gnujump_1.0.8-1_amd64.deb</strong>
-rw-rw-r-- 1 john john    9228 Ιούν 22 17:52 gnujump_1.0.8-1.debian.tar.xz
-rw-rw-r-- 1 john john     885 Ιούν 22 17:52 gnujump_1.0.8-1.dsc
-rw-rw-r-- 1 john john 2508641 Ιούλ 24  2012 gnujump_1.0.8.orig.tar.gz
-rw-rw-r-- 1 john john 1814056 Ιούν 22 17:41 gnujump_1.0.8.orig.tar.xz

Checking the result

  1. View the information related to the package file:
    $ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
    new debian package, version 2.0.
    size 1560574 bytes: control archive=5550 bytes.
        419 bytes,    11 lines      control              
      18390 bytes,   233 lines      md5sums              
    Package: gnujump
    Version: 1.0.8-1
    Architecture: amd64
    Maintainer: John Doe </john><john .doe@example.net>
    Installed-Size: 2355
    Depends: libc6 (>= 2.14), libgl1-mesa-glx | libgl1, libsdl-image1.2 (>= 1.2.10), libsdl-mixer1.2, libsdl1.2debian (>= 1.2.11)
    Section: games
    Priority: optional
    Homepage: http://gnujump.es.gnu.org
    Description: <insert up to 60 chars description>
     </insert><insert long description, indented with spaces>
    

As you can see our work is not finished. We need to add a description in debian/control and rebuild it.

  1. Check the contents of the package file:
    $ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
    

Install the package

Now we can install the package:

$ sudo dpkg -i /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb

Now run the gnujump software and check if it works.

This is not the whole story of course. You have to check the package against Lintian to see if it complies with the Debian Policy. And if it’s not compliant, you may need to use Quilt to patch it. You will need to fill debian/watch so you can track updates on the upstream with uscan. The work of a Debian packager never ends.

References

  • https://wiki.ubuntu.com/PbuilderHowto
  • https://www.debian.org/doc/manuals/packaging-tutorial/packaging-tutorial.en.pdf</insert></john>
Categories
Linux

Modifying an existing Debian package: grep

This guide is a practical session on how to modify an existing debian package, when the version is not included in the current release. It is based on the excellent packaging tutorial and practical sessions of Lucas Nussbaum.

We are going to download a source deb package, build it without modifications, modify it, patch it, rebuild it and in the end, install it in our system.

Prerequisites

  • A recent Debian or Ubuntu system.

Installation of development packages

$ sudo apt-get -y install build-essential debhelper devscripts packaging-dev debian-keyring

Get the source from the debian repos

$ dget http://cdn.debian.net/debian/pool/main/g/grep/grep_2.21-1.dsc

After that you should see these files under the current directory:

$ ls
grep_2.21-1.debian.tar.bz2  grep_2.21-1.dsc  grep_2.21.orig.tar.xz
  • grep_2.21-1.dsc: Package’s debian source control file.
  • grep_2.21.orig.tar.xz: Original source.
  • grep_2.21-1.debian.tar.bz2: Debian files and patches.

Unpack the source

The dpkg-source file will unpack the original and debian tarballs and apply the debian patches, if available.

$ dpkg-source -x grep_2.21-1.dsc

Download build dependencies

$ sudo apt-get -y build-dep grep

Build the unmodified package

Change into the source tree and run debuild. We are using the -us and -uc flags to suppress warnings about signing.

$ cd grep-2.21/
$ debuild -us -uc

It doesn’t take long before this package is build. In the parent directory you will find three more files:

  • grep_2.21-1_amd64.deb: the newly created deb package file.
  • grep_2.21-1_amd64.build: the build log. You can use this to check for errors or warnings.
  • grep_2.21-1_amd64.changes: Debian applied changes.

Modify the package

I suggest you do not touch the source, unless you fancy spending your day debugging. We will simply make some modifications on the debian/changelog and debian/rules files.

  1. Add the --with-gnu-ld flag in the DEB_CONFIGURE_EXTRA_FLAGS line of the debian/rules file.

    The --with-gnu-ld is a trivial change and shouldn’t break anything during build. Find this line:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex
    

    And change it to this:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex --with-gnu-ld
    
  2. Update the changelog file.

    We are going to use the dch utility which is simply a wrapper around your default editor, with changelog syntax checking. Run the following command in the source tree:

    $ DEBFULLNAME="John Doe" DEBEMAIL="john.doe@example.net" dch -i
    

    Make the following changes (in bold) the debian/changelog file:

    grep (2.21-1ubuntu1) experimental; urgency=low
    
     * Support for GNU ld linker.
    
    -- John Doe <john .doe@example.net>  Fri, 19 Jun 2015 13:01:37 +0300
    

    Note how the name and email of the patcher have been automatically inserted in the changelog entry. That’s because we defined the DEBFULLNAME and DEBEMAIL variables in the shell that runs dch.

Rebuild the modified package

$ debuild -us -uc

You will see the following error:

dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/grep_2.21-1ubuntu1.diff.eYCcPk
dpkg-source: info: you can integrate the local changes with dpkg-source --commit
dpkg-buildpackage: error: dpkg-source -b grep-2.21 gave error exit status 2
debuild: fatal error at line 1376:

The above error happens because the --with-gnu-ld flag makes changes to the upstream source and this is against the Debian policy.

Apply patches for Policy compliance

$ cp /tmp/grep_2.21-1ubuntu1.diff.eYCcPk debian/patches/90-enable-gnu-ld.patch
$ echo 90-enable-gnu-ld.patch >> debian/patches/series

It is considered a good practice to edit the patch, add a description and a short summary and fill the headers related to the [Patch Tagging Guidelines](http://dep.debian.net/deps/dep3/ "Patch Tagging Guidelines").

This method is only a workaround. The correct way to deal with patches is [Quilt](https://pkg-perl.alioth.debian.org/howto/quilt.html "Quilt Howto").

Final rebuild of the modified package

$ debuild -us -uc

You will see five additional files in the parent directory:

  • grep_2.21-1ubuntu1_amd64.deb: the new deb package file.
  • grep_2.21-1ubuntu1.debian.tar.bz2: the new debian directory tarball.
  • grep_2.21-1ubuntu1.dsc: the new debian source control file.
  • grep_2.21-1ubuntu1_amd64.build: the build log.
  • grep_2.21-1ubuntu1_amd64.changes: the changes file.

Checking the differences between original and new

The following commands will find the differences in the debian source control and changes files:

$ diff ../*.changes
$ diff ../*dsc

Install the new package

$ sudo debi

Check if grep is the correct version:

$ grep --version
grep (GNU grep) <strong>2.21</strong>
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

All done. If you have reached so far congratulations! You have successfully rebuilt a Debian package.

References:

  • http://www.lucas-nussbaum.net/
  • https://www.debian.org/doc/manuals/packaging-tutorial/packaging-tutorial.en.pdf
  • http://dep.debian.net/deps/dep3/</john>
Categories
Linux

Adding USB boot support on the Utilite nettop

More than a year or so, I have been the proud owner of a first generation Utilite ARM appliance. But the harsh Cyprus summer, hit it hard and the microSD circuit stop working. I could no longer boot alternative systems on microSD cards. All I was left with, was the stock system with an aging Ubuntu 12.04 ARM port.

Enter the U-Boot

Das U-Boot is a boot loader that targets mostly embedded systems. Many ARM appliances, including the Utilite, are using U-Boot to boot their OS.

I entered the U-Boot environment to do some checks about the mmc issue. To do that just press the ‘any‘ key when you see the following message:

Hit any key to stop autoboot:

Then type the following command in your U-boot terminal:

CM-FX6 # mmc info
Card did not respond to voltage select!

That message does not look very healthy! When I tried to insert a microSD card, I got this message repeatedly, in the U-Boot terminal:

EHCI timed out on TD - token=0x80008c80

The keyboard stopped responding and I had no other option than to force restart. I think now we have enough evidence to say that the microSD circuitry went FUBAR. At this point you should probably contact CompuLab for a replacement.

But this is not what I did. The appliance has 3 USB ports available, so why not use them? This will have the added benefit of USB devices being more accessible, than the hard to access microSD slot.

Well, the original U-Boot image that the Utilite was shipped with, did not had USB boot support. This has long changed and the nice folks at CompuLab have built a newer version that supports booting from USB storage devices.

Upgrading U-Boot

First download the most recent U-Boot updater on your Utilite appliance:

$ wget http://utilite-computer.com/download/utilite/u-boot/utilite-updater.tar.bz2

Check the MD5 sum:

$ echo a79e492f3eb626c770c5185cda0edfec ; md5sum utilite-updater.tar.bz2 
a79e492f3eb626c770c5185cda0edfec
a79e492f3eb626c770c5185cda0edfec  utilite-updater.tar.bz2

Extract the archive:

$ tar xvjf utilite-updater.tar.bz2

Run the updater:

$ sudo ./utilite-bootloader-update.sh 

CompuLab CM-FX6 (Utilite) boot loader update utility 2.2 (Feb 8 2015)

>> Checking for utilities... 
>> ...Done 
>> Checking that board is CM-FX6 (Utilite)... 
>> ...Done 
Please input firmware file path (or press ENTER to use "cm-fx6-firmware"): 

Just press ‘Enter’ after the above prompt. Then answer ‘Yes’ (y) to the following questions:

>> Looking for boot loader image file: cm-fx6-firmware 
>> ...Found 
>> Looking for SPI flash: mtd0 
>> ...Found 
>> Current U-Boot version in SPI flash: U-Boot 2014.10-cm-fx6-2.1 (Jan 19 2015 - 11:28:10) 
>> New U-Boot version in file:      U-Boot 2014.10-cm-fx6-2.1 (Jan 19 2015 - 11:28:10) (500K) 
>> Proceed with the update? 
1) Yes
2) No
#? <strong>y</strong>  
** Do not power off or reset your computer!!! 
>> Erasing SPI flash... 
Erasing 4 Kibyte @ bf000 -- 100 % complete 
>> ...Done 
>> Writing boot loader to the SPI flash... 
.........................
>> ...Done 
>> Checking boot loader in the SPI flash... 
.
>> ...Done 
>> Boot loader update succeeded!

** Resetting U-Boot environment will override any changes made to the environment! 
>> Reset U-Boot environment (recommended)? 
1) Yes
2) No
#? y
>> U-boot environment will be reset on restart. 
>> Done!

Then reboot the appliance:

$ sudo reboot

It is a good idea to keep a backup of the original U-Boot configuration for future reference:

$ sudo fw_printenv > utilite.uboot.orig

Enhancing the USB boot setup

If you study the above U-Boot setup you will find that the USB config works only if you have an option boot.scr script under the first partition of your USB. This excludes USB drives with only the uImage file. That means that you cannot even boot the Utilite SSD installer if you burn it on USB, since it does not have a boot.scr script.

I’ve been playing around with the U-Boot environment and I came out to this configuration:

setenv bootcmd run setupmmcboot;mmc dev ${storagedev};if mmc rescan; then run trybootsrz;fi;run setupusbboot;if usb start; then if run loadscript; then run bootscript;else run usbbootargs;if run loadkernel; then run doboot;else setenv bootargs;fi;fi;fi; run setupsataboot;if sata init; then run trybootsmz;fi;run setupnandboot;run nandboot;
setenv usbroot /dev/sdb2
setenv usbrootdelay=1
setenv usbbootargs=setenv bootargs root=${usbroot} rootdelay=${usbrootdelay}

If you don’t want to configure the above commands manually, you can download my custom U-boot environment updater and the patch I prepared:

Download the U-Boot environment update shell script:

$ wget https://raw.githubusercontent.com/theodotos/arena/master/u-boot/u-boot-update-env.sh
$ chmox +x u-boot-update-env.sh

Download the U-boot custom configuration:

$ wget https://raw.githubusercontent.com/theodotos/arena/master/u-boot/setup-usb-boot-utilite.uboot

Now load the custom configuration into the U-Boot environment:

$ sudo ./u-boot-update-env.sh setup-usb-boot-utilite.uboot

If something goes wrong you can restore your original configuration using the original configuration we saved earlier:

$ sudo ./u-boot-update-env.sh utilite.uboot.orig

The U-Boot environment updater will also create a backup file, with the current U-Boot environment configuration, just before the update:

$ ls *.bak
u-boot_env-3366.bak

Test with the Utilite SSD installer

Now it is time to test our new configuration.

First download the SSD installer:

$ wget http://utilite-computer.com/download/utilite/installer/cl-installer_utilite-2_kernel-6.3_2014-12-17.img.xz

Check the MD5 sum:

$ echo 82eeb54c4d5245c60fd82c3e983d10e9 ; md5sum cl-installer_utilite-2_kernel-6.3_2014-12-17.img.xz
82eeb54c4d5245c60fd82c3e983d10e9
82eeb54c4d5245c60fd82c3e983d10e9  cl-installer_utilite-2_kernel-6.3_2014-12-17.img.xz

Extract it:

$ unxz cl-installer_utilite-2_kernel-6.3_2014-12-17.img.xz

This will extract a cl-installer_utilite-2_kernel-6.3_2014-12-17.img image file in the working directory.

Now comes the tricky part. We will load the image in a USB device. Make sure you choose the correct device! The dd tool we are using below, is a heartless beast that will chew the data out of every device you select in its of= flag. If by mistake you give your internal disk instead of the USB, you will lose your partitions and data! You have been warned!

So after you select a USB (one that does not have any data you need) insert it in your Linux workstation. Then try the following check to find out the device name of the USB drive:

$ dmesg | tail -n20
[61425.197050] mce: [Hardware Error]: Machine check events logged
[71124.693498] compiz[1853]: segfault at 80000000 ip 0000000080000000 sp 00007ffc438c50a8 error 14
[73897.971544] usb 1-2: new high-speed USB device number 10 using xhci_hcd
[73898.105247] usb 1-2: New USB device found, idVendor=0951, idProduct=1665
[73898.105254] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[73898.105257] usb 1-2: Product: DataTraveler 2.0
[73898.105260] usb 1-2: Manufacturer: Kingston
[73898.105262] usb 1-2: SerialNumber: 50E54951351BBE70A9455C5B
[73898.106083] usb-storage 1-2:1.0: USB Mass Storage device detected
[73898.106370] scsi host8: usb-storage 1-2:1.0
[73899.187591] scsi 8:0:0:0: Direct-Access     Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 6
[73899.187848] sd 8:0:0:0: Attached scsi generic sg2 type 0
[73900.521857] sd 8:0:0:0: [sdb] 15335424 512-byte logical blocks: (7.85 GB/7.31 GiB)
[73900.522528] sd 8:0:0:0: [sdb] Write Protect is off
[73900.522531] sd 8:0:0:0: [sdb] Mode Sense: 23 00 00 00
[73900.523124] sd 8:0:0:0: [sdb] No Caching mode page found
[73900.523126] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[73900.562834]  sdb: sdb1 sdb2
[73900.565248] sd 8:0:0:0: [sdb] Attached SCSI removable disk
[73903.203134] EXT4-fs (sdb2): mounted filesystem with ordered data mode. Opts: (null)

So the device name is sdb and it has two partitions: sda1 and sda2. Check if these partitions have been mounted automatically:

$ mount | grep sdb
/dev/sdb2 on /media/theodotos/rootfs type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks2)
/dev/sdb1 on /media/theodotos/boot type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

They are mounted. We need to unmount them before dumping the image on the device:

$ sudo umount /dev/sdb1 /dev/sdb2

Now we are ready to run dd (device dump) against the USB drive:

$ sudo dd if=~/Downloads/cl-installer_utilite-2_kernel-6.3_2014-12-17.img of=/dev/sdb bs=1M

You are not going to see any progress bar during the device dump. Just be patient and let the utility take its time.

After dd finishes and returns back to the shell, safely remove the USB drive and try it on Utilite. If you reboot the appliance you should see the LXDE desktop of the Utilite installer. Unplug it and you are back to your Ubuntu, on the internal drive.

References

  • http://www.compulab.co.il/utilite-computer/web/utilite-overview
  • http://www.compulab.co.il/utilite-computer/wiki/index.php/Utilite_U-Boot
Categories
Linux

How to Join An Ubuntu Desktop Into An Active Directory Domain

As a Free Software activist I wish I didn’t had to use, touch, see, hear, smell or taste Microsoft technologies. But until that happens, I need to know how to join a Linux machine in an Active Directory Domain.

This is an article I recently submitted to the excellent Unixmen.com website:

How to Join An Ubuntu Desktop Into An Active Directory Domain

Categories
Linux

Introduction to the KVM Hypervisor (for Ubuntu)

The KVM hypervisor is a virtualization system included with the Linux kernel. Along with XEN is one of the most attractive virtualization platforms based on Linux.

KVM offers several advantages over the more user-friendly, VirtualBox. Since it is integrated into the mainstream Linux kernel, it boasts significant performance benefits [1]. Furthermore it is better suited as a virtualization platform solution while VirtualBox is better suited for short-term tests and casual, user owned, VMs. KVM supports many guest operating systems so you can use Linux, Unix, Windows or something more exotic.

Install KVM on your system

  1. Make sure your system supports KVM.

    KVM is only supported on systems with Hardware-Assisted Virtualization. If your system does not support HAV you can revert to QEMU, a system which KVM is based on.

  • First install CPU checker:

    $ sudo apt-get -y install cpu-checker
    

  • Check if KVM is supported:
    $ kvm-ok
    INFO: /dev/kvm exists
    KVM acceleration can be used
    

    Looks OK. Still you may need to check your BIOS/EFI whether this feature is enabled.

  1. Install KVM:

    $ sudo apt-get -y install qemu-kvm
    

KVM Basic Usage

You can use KVM directly. This method is suitable for testing or troubleshooting but not appropriate for production VMs.

  1. Create a disk image:
    $ qemu-img create -f qcow2 testvm.qcow2 20G
    Formatting 'testvm.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off
    

    The qcow2 format grows dynamically so it does not really occupy 20GB:

    $ ls -lh testvm.qcow2 
    -rw-r--r-- 1 theo theo   193K Μάι  14 18:43 testvm.qcow2
    
  2. Start a VM instance, to setup your system:
    $ kvm -m 1024 -hda testvm.qcow2 -cdrom ~/Downloads/ubuntu-15.04-desktop-amd64.iso -boot d -smp 2
    

    The options are explained below:

    • -m: memory in MB
    • -hda: first disk image to use
    • -cdrom: you can use an .iso file (ubuntu-15.04-desktop-amd64.iso) or a physical CD-ROM (/dev/sr0).
    • -boot: choose where to boot from. A parameter of d tells KVM to use the cdrom for booting.
    • -smp: Stands for Symmetric Multiprocessing. 2 is the number of CPUs available to the VM.

    After you run the command above you will get a window with your VM running in it:

    KVM VM

    This window will capture your mouse and keyboard when you work in it. If you want to return to your host OS just press Ctrl-Alt together and they will both be released.

  3. Run your VM.

    After the installation is finished you can run your VM from the disk image.

    • First let’s check the size of your disk:
      $ ls -lh testvm.qcow2
      -rw-r--r-- 1 theodotos theodotos 5,9G Μάι  14 19:33 testvm.qcow2
      

    So after the installation of Ubuntu Desktop 15.04 (Vivid Vervet) the disk image has grown to 5.9GB.

    • Run the VM from the disk image:
      $ kvm -m 1024 -hda testvm.qcow2 -smp 2
      

    A new window will pop up with the freshly installed OS.

Running KVM under libvirt

The libvirt system, is a platform for running VMs under many different hypervisors using a common API and toolset. It supports KVM, XEN, QEMU, VirtualBox and many others. This is the preferred method of using KVM because the VMs are globally available to privileged (local and remote) users, it facilitates VM management and you can configure autostart and many other features.

  1. Setting up libvirt:
    $ sudo apt-get -y install libvirt-bin
    
  2. Give appropriate permissions to the users expected to manage your VMs:
    $ sudo usermod -a -G libvirtd theo
    

    The theo user will be added as a member in the libvirtd group. After that you will need to log-out, for the permission to be activated.

Creating a libvirt ready VM

There are many tools to create VMs for libvirt. In this section we are going to examine two of them: virt-install and uvtool.

  1. Using virt-install.

    The advantage of virt-install is being distro agnostic. That means you can use it to install Debian, Ubuntu, RHEL, CentOS, Fedora, SUSE and many other distros as well.

    • Install virt-install:
      $ sudo apt-get -y install virtinst
      
    • Create a machine:
      $ sudo virt-install -n testvm -r 512 --disk path=/var/lib/libvirt/images/testvm.img,bus=virtio,size=4 -c ~/Downloads/ubuntu-14.04.2-server-amd64.iso --network network=default,model=virtio --graphics vnc,listen=127.0.0.1 --noautoconsole -v
      
      Starting install...
      Allocating 'testvm.img'                     | 4.0 GB     00:00     
      Creating domain...                          |    0 B     00:01     
      Domain installation still in progress.  You can reconnect to 
      the console to complete the installation process.
      
      • -n: VM name
      • -r: RAM in MB
      • –disk: Path for the virtual disk.
      • -c: defive the .iso file or CDROM device to use for the OS installation.
      • –network: Select your preferred networking mode.
      • –graphics: Select the graphics protocol. We are using VNC here that allows connections only from localhost. You can use the 0.0.0.0 (any) instead if 127.0.0.1 IP to allow connections from elsewhere.
      • –noautoconsole: do not run the guest console.
  • Connect to the VM and setup the guest OS:
    $ xtightvncviewer 127.0.0.1
    

    The VNC client will connect to the default VNC port which is 5900. You can append ::<port> to the hostname or IP address if you want to use a different port, e.g. xtightvncviewer 127.0.0.1::5901

    NOTE: If xtightvncviewer is not installed you can install it with sudo apt-get install xtightvncviewer. You can also use a graphical VNC client like Remmina.

  • Verify that the machine is created:

     $ virsh list --all
      Id    Name                           State
       ----------------------------------------------------
       -     testvm                         shut off
    

    The machine will appear as shut off after the OS setup finishes.

  • Start the VM:

    $ virsh start testvm
      Domain testvm started
    

  • Verify that the VM is started:
    $ virsh list
    Id    Name                         State
    ----------------------------------------
    3     testvm                     running
    
    1. Install a VM using uvtool:

      The uvtool is a tool to create minimal VMs. Unlike virt-install you can create only Ubuntu VMs but the overall setup is taken care by uvtool.

      • Install uvtool:
        $ sudo apt-get -y install uvtool uvtool-libvirt
        
      • Create a local repository of ubuntu-cloud images:
        $ uvt-simplestreams-libvirt sync release=trusty arch=amd64
        

      This command will download the trusty (14.04) release locally.

      • Query for local repository
        $ uvt-simplestreams-libvirt query
        release=trusty arch=amd64 label=release (20150506)
        
      • Generate an ssh key pair (unless you already have one):
        $ ssh-keygen -b 4096
        
      • Create a uvt based VM:
        $ uvt-kvm create --cpu 2 --memory=1024 --disk=10 testuvt
        

      This will create a trusty VM with 2 CPUs, 1GB RAM and 10 GB disk.

    • Verify the machine creation:

      $ virsh list
       Id    Name                           State
        ----------------------------------------------------
         5     testuvt                        running
      

    • Connect to your VM:

      $ uvt-kvm ssh testuvt --insecure

      You can get root access, on the VM, with sudo -i.

    Managing libvirt using the graphical Virtual Machine Manager

    Virtual Machine Manager is a front-end to libvirt. It help system administrators managing their VMs using a convenient graphical interface.

    1. Installing Virtual Machine Manager:
      $ sudo apt-get -y install virt-manager
      
    2. Running Virtual Machine Manager:
    • You can find it in the application menu or run virt-manager from the command line.
      virt-manager-1.png

      As you can see the two VMs we created earlier, are already there.

    1. Creating a new machine.

      • Press the Create a new machine icon:
        virt-manager-2.png
    2. New VM options.
    • Select one of the following option to continue:
      virt-manager-3.png
      Each option provides different steps. You may need to read the documentation for all the details. The first option is the most straight forward.

    Managing your VMs with virsh

    1. Listing machines.
    • List only running machines:

      $ virsh list
       Id    Name                           State
        ----------------------------------------------------
         5     testuvt                        running
      

    • List all machines:
      $ virsh list --all
       Id    Name                           State
        ----------------------------------------------------
         5     testuvt                        running
         -     testvm                         shut off
      
    1. Starting machines:
      $ virsh start testvm
      Domain testvm started
      
    2. Shutdown machines:
      $ virsh shutdown testvm
      Domain testvm is being shutdown
      
    3. Restart machines:
      $ virsh reboot testuvt
      Domain testuvt is being rebooted
      
    4. Set machines to autostart:
      • Enable autostart:
        $ virsh autostart testuvt
        Domain testuvt marked as autostarted
        
      • Disable autostart
        $ virsh autostart --disable testuvt
        Domain testuvt unmarked as autostarted
        
    5. Other useful virsh commands:
      • console: get console access to a VM.
      • destroy: destroy (delete) a machine.
      • dominfo: get the machine details.
      • migrate: migrate a machine to another libvirt host.
      • save: save the machine state.
      • snapshot-create: create a snapshot of the machine.

      To see all the supported commands you can run virsh --help.

    Learning to use libvirt is of great value to a Linux sysadmin because the same commands apply for KVM, XEN, VirtualBox, even container systems like OpenVZ and LXC.

    References

    • [1] http://www.phoronix.com/scan.php?page=article&item=ubuntu_1404_kvmbox&num=5
    • [2] https://help.ubuntu.com/14.04/serverguide/virtualization.html
    • [3] https://help.ubuntu.com/community/KVM</port>
    Categories
    Linux

    Installing Cisco Packet Tracer on Ubuntu

    Cisco Packet Tracer is network simulation program for students in the Cisco Networking Academy. There is an Ubuntu version for it and we are going to show you how to install it and configure it.

    This is tested on Ubuntu 15.10 (Vivid Vervet) but it should work on earlier versions. A requirement for this guide is to have root access on the target machine or sudo admin rights.

    Download Cisco Packet Tracer

    If you have an account on the Cisco Networking Academy you can download Packet Tracer from Student Resources. Ask your instructor if you can’t find it.

    After you download it, it should be in your Downloads folder:

    $ ls -l ~/Downloads/
    total 183928
    -rw-r-----  1 theo theo 188328996 Jan  31 03:34 Cisco Packet Tracer 6.2 for Linux - Ubuntu installation - Instructor version.tar.gz
    

    Students can download the student version instead.

    Unpack the package

    1. Change into the Downloads directory:
      $ cd ~/Downloads/
      
    2. Unpack the downloaded file:
      $ tar xvzf Cisco\ Packet\ Tracer\ 6.2\ for\ Linux\ -\ Ubuntu\ installation\ -\ Instructor\ version.tar.gz
      
    3. Verify the unpacked files:
      $ ls -l
      total 183932
      -rw-r-----  1 theo theo 188328996 Ιαν  31 03:34 Cisco Packet Tracer 6.2 for Linux - Ubuntu installation - Instructor version.tar.gz
      drwxr-xr-x 12 theo theo      4096 Ιαν  30 01:00 <strong>PacketTracer62</strong>
      

      The installation files are under the PacketTracer62 directory.

    Install Packet Tracer

    1. Change into the PacketTracer62 directory:

      $ cd PacketTracer62
      

    2. Run the installer:
      $ sudo ./install
      
      • Press the ‘Enter‘key to accept the EULA.
      • Press ‘Space‘ repeatedly to reach 100%.
      • Type ‘y‘ (yes) to accept the EULA.
      • Type the location where you want the package installed. If you just press ‘Enter‘ it will choose the default (/opt/pt).
      • When asked to create a symbolic link "packettracer" in /usr/local/bin type y (yes).
    3. Setup the Packet Tracer Desktop Link:

      While you are in the PacketTraser62 directory, copy the PT Desktop link to your Desktop and assign executable permissions on it:

      $ cp bin/Cisco-PacketTracer.desktop ~/Desktop/
      $ chmod +x ~/Desktop/Cisco-PacketTracer.desktop
      

      Unfortunately the links to the program and its icon are wrong. Edit the Exec and Icon directives in the Cisco-PacketTracer.desktop file as follows:

      # Exec=/usr/local/PacketTracer6/packettracer
      # Icon=/usr/local/PacketTracer6/art/app.png
      Exec=/opt/pt/bin/PacketTracer6
      Icon=/opt/pt/art/app.png
      

      Alternatively you can just type the packetracer command from your terminal.

    Although Packet Tracer is based on several Free Software libraries, it is not Free Software itself. I hope its Cisco developers see the light and release this great learning tool as Free Software. Only good things can come from such decision.

    Categories
    Linux

    Defending against Internet attacks for your Ubuntu Server (14.04 LTS)

    The Ubuntu Server Edition LTS is a highly reliable server system and comes with reasonable security defaults. Still there are additional steps to take if we want to enhance its security.

    Note
    These steps will only help make your server more secure but they will not make it bulletproof! Security is an evergoing process and you should always be alert for new security issues.

    Prerequisites

    1. Install a fresh Ubuntu Server 14.04 (Preferable 64 bit).
    2. Use the following command to install SSH, if not already installed:

      $ sudo apt-get -y install openssh-server
      

    3. Make sure you have a sudo enabled user:
      $ id | grep sudo
      uid=1000(theoadm) gid=1000(theoadm) groups=1000(theoadm),4(adm),24(cdrom),27(<strong>sudo</strong>),30(dip),46(plugdev),116(lpadmin),117(sambashare),1006(gitusers)
      

      If the above is not true, you will have to login as root with su – and execute all the commands as the root user.

    Secure SSH

    1. Block remote logins as root. Set the value of the PermitRootLogin keyword, in /etc/ssh/sshd_config, to without-password or no. This will disable password based authentication for the user root and only allow Public Key Authentication.
    • First check what is the value of the PermitRootLogin keyword:

      $  grep PermitRootLogin /etc/ssh/sshd_config
      PermitRootLogin without-password
      

    • If the value is yes, it is considered a very bad practice, especially on a public server. Use your favorite editor or the following command to change it:
      $ sudo sed -i 's/^\(PermitRootLogin\s\)[yY][eE][sS]/\1without-password/' /etc/ssh/sshd_config
      
    • Don’t forget to restart SSH:
      $ sudo service ssh restart
      
    1. Change the SSH listening port from 22 to something else. This is not the ultimate security measure but, since most ssh attack bots target the default port, it will largely minimize the attacks.
    • First select a port not used by a well known service. Let’s assume that we decided to use port 4547:
      $  grep 4547 /etc/services ; echo $?
        1
      

      A return value of 1 indicates that no well known service is using that port.

    • Then change the value of the Port keyword to 4547. Use your favorite editor or the following sed command to do so:

        $  sudo sed -i 's/^\(Port\s\)22/\14547/' /etc/ssh/sshd_config
      

    • Restart your SSH server:
      $ sudo service ssh restart
      
    • Verify that the port has been changed:
      $ sudo netstat -lnpt | grep ssh
        tcp     0    0 0.0.0.0:4547   0.0.0.0:*   LISTEN   11979/sshd
        tcp6    0    0 :::<strong>4547</strong>        :::*        LISTEN   11979/sshd
      

    Enable Filtering

    1. Enable the firewall functionality. We will be using the pre-installed Uncomplicated Firewall (ufw) which is just a front-end to the, more complicated, iptables.
    • First allow port 4547. Make sure you type the correct port or you will be locked out of your server! Use the following command to allow traffic to our chosen port:
      $ sudo ufw allow 4547/tcp
      
    • Then enable the firewall:
      $ sudo ufw enable
      
    • Verify that is working:
      $ sudo ufw status
      Status: active
      
      To                         Action      From
      --                         ------      ----
      4547/tcp                   ALLOW       Anywhere
      4547/tcp (v6)              ALLOW       Anywhere (v6)
      
    1. Setup the Fail2ban intrusion prevention software. [Fail2ban](http://www.fail2ban.org/wiki/index.php/Main_Page "Fail2ban") is an excellent tool to block attacks against SSH and many other services.
    • Install fail2ban:
      $ sudo apt-get -y install fail2ban
      
    • SSH protection is enabled by default but we need to reconfigure the ssh port to 4547. In the file /etc/fail2ban/jail.conf change the port = ssh value to 4547:
      [ssh]
      
      enabled  = true
      port     = <strong>4547</strong>
      filter   = sshd
      logpath  = /var/log/auth.log
      maxretry = 6
      
    • Enable protections against distributed attacks. Edit the [ssh-ddos] section in /etc/fail2ban/jail.conf:
      [ssh-ddos]
      
      enabled  = yes
      port     = 4547
      filter   = sshd-ddos
      logpath  = /var/log/auth.log
      maxretry = 6
      

    Unattended upgrades

    Enabling unattended upgrades may not be a very good idea on mission critical servers. On such scenarios you may want to test the upgrades on a test server before you apply them on the production. Nevertheless it may be a good practice to enable this functionality on machines that are expected to run unattended for long periods of time. This will help to automatically patch vulnerabilities of your machine. Note, however, that patches do not automatically apply on the Linux kernel or the glibc library, because a restart is needed in these cases. So even on mostly unattended scenarios, you still need to check occasionally whether your machine needs a restart.

    1. Make sure that the unattended-upgrades package is installed. It is usually pre-installed but if not, you can use the following command to install it:
      $ sudo apt-get -y install unattended-upgrades
      
    2. Then we must configure automatic upgrades. Answer Yes when asked in the following command:
      $ sudo dpkg-reconfigure updates unattended-upgrades
      

      Alternatively you can edit the /etc/apt/apt.conf.d/20auto-upgrades configuration file as follows:

      APT::Periodic::Update-Package-Lists "1";
      APT::Periodic::Unattended-Upgrade "1";
      

    Further Reading

    As we said earlier, security is an ongoing process. Some further info to make your site more secure:

    • Hardening Ubuntu:
      http://hardenubuntu.com/
    • Applied Crypto Hardening: Don’t forget to read the OpenSSH section of the [Better Crypto](https://bettercrypto.org/ "bettercrypto.org") draft paper: https://bettercrypto.org/static/applied-crypto-hardening.pdf
    • Block port scanning: The article below explains how to use Fail2ban to block port scanning.
      http://www.irrexpr.com/2013/06/using-iptables-logging-and-fail2ban-to.html
    • [4] Port knocking: Port knocking is another interesting technique where you can open your SSH ports, or ports for other services, on demand. Strictly for paranoids!
    Categories
    Linux

    How to set up your own LAMP server on Ubuntu 14.04 (aka Trusty Tahr)

    You sail with no lights in the midnight dark.

    Afraid of betrayal by lights from the land,

    alone and thoughtful, you walk the deck,

    clutching Aladdin’s lamp in your hand.

    ~ Nikos Kavvadias ~

    In this guide we are setting up an Ubuntu/Linux based webserver with a database backend and using the PHP scripting language. The term LAMP is not related to lighting, nor Middle Eastern tales but refers to the combination of Linux, Apache, MySQL MariaDB and PHP.

    Traditionally we have been using MySQL for this task but since Ubuntu 14.04, MariaDB is available from the stock Ubuntu repos. It is recommended to  use MariaDB over the beloved MySQL, because the future of the latter is not so promising after the purchase from Oracle.

    We will also be using VirtualBox to install Ubuntu Server on a virtual machine but you can follow this guide on an actual computer or on your cloud/hosting provider.

    To complete this guide you will need to download a copy of the latest Ubuntu Server ISO image (current version 14.04.2)

    Setting up the Virtual Machine

    1. Install VirtualBox:
      Make sure you have VirtualBox installed. If not, you can download it from your package manager or from command line (works for Ubuntu and Debian based systems):

      $ sudo apt-get -y install virtualbox

      If you are using a Windows PC you will need to go to the
      VirtualBox website and download it.

    2. Start VirtualBox:VBox-1
      Click on the New icon to create a new virtual machine.
    3. Setup the VM name:
      VBox-2
      Type Ubuntu-server in the Name and click ‘Next’.
    4. Setup the memory size.
      VBox-3
      The default 512 MB is enough but you may use 1024 if you have memory to spare.
    5. Setup the Virtual Hard Drive:
      • Create the Virtual Hard Drive:
        VBox-4
      • Select the format of the Hard Drive:
        VBox-5
        VDI is the default for VirtualBox.
      • Select the type of the Hard Drive:
        VBox-6
        Fixed size is supposedly better for performance but it will occupy space equal to its size on your disk. For testing purposes choose Dynamically allocated.
      • Select the size of your disk:
        VBox-7
        If you have chosen Dynamically allocated before, then your Hard Drive can be as large as 2,00 TB without actually occupying that much space on the physical  disk. 40,00 GB is more than enough.
    6. Setup Networking:
      The default network mode for newly created VirtualBox machines is NAT.  This mode is not very convinient if you want to access your VM from the physical host so we are changing that to Bridged Adapter.
      Warning: in some enterprise environments this could trigger the security defences of your network and lock you out! Please consult with you network administrator before enabling this at work!

      You can find more information about the VirtualBox networking modes here:
      VirtualBox Networking Modes

      • To setup Bridged Networking press the Settings icon:VBox-Net-1
      • The default mode in the Attached to: field is NAT:
        VBox-Net-2
      • Change NAT to Bridged Adapter:
        VBox-Net-3
        If you have more than one ethernet interfaces you will need to choose the correct one in the Name field. Usually the correct value is eth0 but this is not always the case. Press OK and you are done with networking.
    7. Start your VM:
      • Press the Start icon:
        VBox-8
      • Boot the Ubuntu ISO:
        VBox-9
        Click on the little folder icon on the right side.
      • Select the Ubuntu ISO file you downloaded earlier:
        VBox-10
      • Press Start to begin the installation:
        VBox-11

    The above procedure is for those that do not have a spare computer for testing. Building a VM is the safest way to experiment with all kind of setups without breaking your working computer.

    Now if you do have a spare computer you can skip the steps above and go straight to the steps below. On a physical computer you will need to burn the ISO file on a CD/DVD or write it on a USB stick, using the usb-creator on Ubuntu or UNetbootin  for other systems. You will need to setup your BIOS/UEFI to boot from the CD or USB first. On Windows 8 systems you may need to disable the abomination called Secure Boot.

    Setting up Ubuntu Server 14.04 (Trusty Tahr)

    Now prepare your pain-killers as this will take some time.

    1. Select the Language for the setup process:
      Ubuntu-Server-1
      This is the language during the installation. Choose English or whatever language you feel comfortable with. If you haven’t figured it out already, the mouse will not work here. Use the arrow keys to select the language and press ‘Enter’ to go to the next step. In case Virtualbox captures your mouse you can press the right Ctrl button to release it.
    2. Start the installation:
      Ubuntu-Server-2

      Select Install Ubuntu Server and press ‘Enter’.
    3. Select the system Language:
      Ubuntu-Server-3 Again select whatever language you need. This is the language for the system, after the installation is finished.
    4. Select your location:
      Ubuntu-Server-4
      If your location is not listed here choose Other and press ‘Enter’.
    5. Select your location now:
      Ubuntu-Server-5
    6. Select your country:
      Ubuntu-Server-6
    7. Select your Locale:
      Ubuntu-Server-7
      If you selected English before you will get a list of English speaking countries to choose from.
    8. Detect keyboard layout:
      Ubuntu-Server-8
      Select Yes if you are unsure of your keyboard layout. No is usually safe unless you have a weird keyboard.
    9. Choose the basic keyboard layout:
      Ubuntu-Server-9
    10. Select specific keyboard layout:
      Ubuntu-Server-10
      Select the first if you are unsure.

      • Wait for the setup to load all necessary components for the installation. If you are not connected to a DHCP enabled network, you will be prompted to give your network settings. Ask your network administrator for assistance.
    11. Select the hostname of your server:
      Ubuntu-Server-11
      Press ‘Tab’, select Continue and then ‘Enter’.
    12. Enter your name:
      Ubuntu-Server-12
      Nobody forces you to enter your actual name :).
    13. Enter your username:
      Ubuntu-Server-13
    14. Select your password:
      Ubuntu-Server-14
      This is a privileged account (using the sudo command) so you better choose a hard to guess password.
    15. Verify your password again:
      Ubuntu-Server-15
    16. Encrypt your home directory:
      Ubuntu-Server-16
      This will protect your personal files if you are paranoid. For testing it’s OK to choose No.
    17. Confirm your timezone:
      Ubuntu-Server-17
      If the time zone is correct select Yes otherwise No.
    18. Select the partitioning method:
      Ubuntu-Server-18The first option is simpler and probably OK for testing. But on a production server you may need to resize the partitions, create new ones and add more disks, so the LVM method is the recommended.
    19. Select the hard drive for the installation:
      Ubuntu-Server-19
    20. Confirm if you want to write to this hard drive:
      Ubuntu-Server-20
      Select Yes and press ‘Enter’. Make sure you don’t have any data you need on this drive!
    21. Select Disk Size for the system:
      Ubuntu-Server-21
      It’s OK to give all available disk size on a test machine.
    22. Write changes to disk:
      Ubuntu-Server-22
      Select Yes and press ‘Enter’.

      • Wait for the Base system installation to complete
    23. Setup your proxy server:
      Ubuntu-Server-23
      If you do not use a proxy server leave this field blank.
    24. Method to manage upgrades:
      Ubuntu-Server-24
      This is a tricky dilemma. If you choose No automatic updates you may forgot to apply updates and render your system vulnerable to attacks. If you choose Install security features automatically your system could break after an update. Choose wisely!
    25. Choose additional software to install:
      Ubuntu-Server-25
      It is a good idea to enable the OpenSSH server so you can access your machine remotely. There is also a LAMP option here but this will install the MySQL server  instead of MariaDB and you may wish to avoid that.

      • Wait for the additional software to be installed.
    26. Install the boot loader:
      Ubuntu-Server-26
      Select Yes here.
    27. Restart your machine:
      Ubuntu-Server-27
      Press Continue to restart the system.
    28. Welcome to your newly created Ubuntu server:
      Ubuntu-Server-28
      Congratulations if you have reached so far! You have just installed a fresh Ubuntu server ready to rock!

    Installing the LAMP stack

    Installing a LAMP environment is easy.  We will need to install the Apache webserver, the MariaDB relational database, PHP and the Apache PHP module.

    1.  Before we proceed with the LAMP stack installation it is a good idea to update/upgrade our system.The command below will download the lists containing the most fresh version of available packages.
      $ sudo apt-get update
      

      The following command will download the packages to be upgraded, remove obsolete packages and download new ones:

      $ sudo apt-get -y dist-upgrade
      
    2. Installing necessary packages:
      $ sudo apt-get -y install apache2 libapache2-mod-php5 mariadb-server php5-mysql 
      
    3. Set the root password for MariaDB:
      MariaDB-1
    4. Verify root password:
      MariaDB-2
    5. Accept the warning:
      MariaDB-3

    After the packages installation is finished we should be ready to go!

    Testing your web server

    Before testing we need to determine the IP address of the server. Run this command on the terminal of your webserver:

    $ ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
     valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host 
     valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 08:00:27:5a:6e:a9 brd ff:ff:ff:ff:ff:ff
     inet 192.168.56.101/24 brd 192.168.56.255 scope global eth0
     valid_lft forever preferred_lft forever
     inet6 fe80::a00:27ff:fe5a:6ea9/64 scope link 
     valid_lft forever preferred_lft forever

    The IP of your server is 192.168.56.101

    1. Testing your ssh connection:
      First lets check if ssh works on your server. Type the following command from the terminal of your PC:

      me@PC:~$ ssh user@192.168.56.101
      The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
      ECDSA key fingerprint is e4:e7:ac:6c:68:ea:71:90:29:03:bc:92:8e:23:f7:0e.
      Are you sure you want to continue connecting (yes/no)? yes
      Warning: Permanently added '192.168.56.101' (ECDSA) to the list of known hosts.
      user@192.168.56.101's password: 
      Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-35-generic x86_64)
      
       * Documentation: https://help.ubuntu.com/
      
       System information as of Mon Sep 15 11:36:04 EEST 2014
      
       System load: 0.09 Processes: 84
       Usage of /: 4.5% of 38.02GB Users logged in: 0
       Memory usage: 13% IP address for eth0: 192.168.56.101
       Swap usage: 0%
      
       Graph this data and manage this system at:
       https://landscape.canonical.com/
      
      Last login: Mon Sep 15 11:36:04 2014
      user@webserver:~$

      The first time you connect to any ssh system you get the warning that The authenticity of host ‘<myhost(myip)>’ can’t be established. This happens only the first time and it is a safe-guard against MITM attacks. Type yes (not y!) here.

      Then it will ask for your password. You will see nothing as you type it! That’s normal.

      If you password is correct you will be greeted by the system information in the command prompt.

    2. Testing your Apache webserver:
      Fire up your browser and type this URL in the address bar:
      http://192.168.56.101
      Test-Apache
      If you can see the above page in your browser, it means that your Apache webserver is up and running.
    3. Testing PHP:
      You need to create the following file under the Apache
      DocumentRoot (/var/www/html):
      Type the following commands on your server terminal:

      $ sudo -i
      [sudo] password for user:
      # cat > /var/www/html/phpinfo.php << EOF
      > <?php phpinfo(); ?>
      > EOF
      # exit
      $

      The command sudo -i will give you access as the super-privileged root user. Notice how the prompt changes frpm $ to #.

      The command cat … will create a new file /var/www/html/phpinfo.php with the content <?php phpinfo(): ?>. This is a nice way to test your PHP setup and get some basic information about your LAMP setup.

      The command exit will take you back to your normal user account. It is not considered a good practice to be logged in as root for too long.

      Finally direct your browser to http://192.168.56.101/phpinfo.php and expect to see something like this:
      Test-php-1
      If you scroll further down you will see that mysql is enabled too:
      Test-php-2
      For security reasons it may be a good idea to delete the
      phpinfo.php file afterwards:

      $ sudo rm /var/www/html/phpinfo.php
    4. Install phpMyAdmin (optional):
      $ sudo apt-get -y install phpmyadmin
    5. Let the package management system handle phpMyAdmin configuration:
      phpMyAdmin-1
    6. Type the MariaDB root password:
      phpMyAdmin-2
    7. Set the phpMyAdmin database password:
      phpMyAdmin-3
    8. Verify the password:
      phpMyAdmin-4
    9. Choose the correct webserver (apache2):
      phpMyAdmin-5
    10. Visit the phpMyAdmin URL:
      (http://192.168.56.101/phpmyadmin):
      phpMyAdmin-6
      Use the username root and the MariaDB root password to login.
    11. Now you can manage MariaDB through phpMyAdmin:
      phpMyAdmin-7

    This was the final test that ensures everything works as expected. Now you can start developing your PHP website or install a PHP application like WordPress or ownCloud.