Friday, September 18, 2009

Beating internet restrictions with ssh

In most of our schools and offices several websites are blocked. Most of these offices and schools are using a proxy server such as squid along with squidguard or danceguardian to achieve access restrictions on users. Most often, the sys admins forget to block internet traffic using other protocols such as ssh , ftp etc. You can beat the web filtering scheme of your network administrator if you can access a machine on internet via ssh. Open ssh server can act as a socks proxy.

So . install open ssh server on your home machine and leave it connected to internet. Note down the ipaddress of your home machine. If it uses DHCP , you can install some thing like dyndns client and keep track of the IP address. From your office/school connect to the home machine as below.

$ ssh -D 2345 ipaddress _of_home_machine

( You can use any other unused port no. instead of 2345. You may not be able to connect to home if the admin has blocked ssh port on the firewall. You can try running ssh server at home on a different port)

Open your firefox browser and select file=>preferences->advanced->network-settings. Fill in 127.0.0.1 against the Socks host column and enter 2345 as port. Click ok to save.
All your webtraffic will now be tunneled to your home machine beating the local proxy. Enjoy unrestricted internet.

Wednesday, September 16, 2009

How to install android sdk 1.6 on Ubuntu 9.04


Google has recently released version android SDK 1.6. This tutorial will teach you how to install it on ubuntu 9.04.

1 Installing Java
Android SDK is built around Java . So, you have to install Sun Java before trying to install Android. Look at this post for details about installation of sun java development kit on ubuntu 9.04.

2) Download android sdk. The current version ( 1.6 R1 ) is available as a tar.gz file from google. Look at this link . You will be prompted to accept android licence and if you accept it, you will be redirected to another link which will permit you to download the sdk. ( It is around 222MB)

3) Unzip the tar.gz file .
I unzipped it to my home folder with the following command

$ tar -xzvf android-sdk-linux_x86-1.6_r1.tgz

All the files were unzipped to a folder named android-sdk-linux_x86-1.6_r1
If you look at the directory now , you will see the following files and folders.

$ ls android-sdk-linux_x86-1.6_r1

add-ons docs documentation.html platforms RELEASE_NOTES.html tools

The tools for android development is under the tools directory.

4) Test drive the android emulator

Since all the android tools are kept under android-sdk-linux_x86-1.6_r1/tools, we must modify the PATH environment variable so that it includes the above directory too.Open a terminal and execute the following.
fermi @Jaunty:~$ PATH=${PATH}:~/android-sdk-linux_x86-1.6_r1/tools
fermi @Jaunty:~$ export PATH
You can also add the above line to your ~/.bash_profile or ~/.bashrc , so that the setting is available always.

My PATH variable looks like this after the above command.

fermi @Jaunty:~$ echo $PATH
/home/fermi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/fermi/android-sdk-linux_x86-1.6_r1/tools

Now you can test fire your set up . It is a good idea to keep all your android related files in a separate folder. I created a new folder named ANDR for experimenting. All the commands below are executed in that folder.

The virtual phones created by android SDK are called AVDs ( android virtual device) .Let us start the experiment with a virtual SDcard and a Virtual Phone.

Let us create a virtual SDcard

$ mksdcard 2048M SDCARD
If you look at the contents of the folder you will see a 2GB file named SDCARD

Next, create an android virtual phone named FERMI_PHONE.

$ android create avd -n FERMI_PHONE -t 2
Android 1.6 is a basic Android platform.
Do you wish to create a custom hardware profile [no]

Press enter to choose no. You will get back the following message.

Created AVD 'FERMI_PHONE' based on Android 1.6, with the following hardware config:
hw.lcd.density=160

Now start up android emulator.
$ emulator @FERMI_PHONE -sdcard SDCARD

Your virtual phone pops up as below. ( Another window which asks you to participate in a survey also pops up, you can close it.)




Wait for a moment , your screen will change to the one shown below.



You can press menu button to unlock the phone.



You can flip the phone with CNTRL+F11



Now let us browse on the android phone.


5 )Starting development with SDK.

The easiest way to start development on android is via eclipse. The eclipse version shipped with jaunty is some what old. ( Version: 3.2.2-5ubuntu3) . You need a later version for installing the ADT ( android Development tools ) for eclipse. I downloaded Eclipse 3.5 (Galileo) from the eclipse site and installed it . Then completed the following steps.
  1. Start Eclipse, then select Help > Install New Softare.
  2. In the Available Software dialog, click Add....
  3. In the Add Site dialog that appears, enter a name for the remote site (e.g., "Android Plugin") in the "Name" field.

    In the "Location" field, enter this URL:

    https://dl-ssl.google.com/android/eclipse/

    Click OK.

  4. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next.
  5. In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish.
  6. Restart Eclipse.
Now modify your Eclipse preferences to point to the Android SDK directory:

  1. Select Window > Preferences... to open the Preferences panel
  2. Select Android from the left panel.
  3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
  4. Click Apply, then OK.
Now your development environment is ready.

For running a hello world application, read this entry from the developers guide. Here is a screen shot of my hello world application.


Happy Hacking.

Ripping CD Music with cdparanoia


cdparanoia is a command line
audio CD digital audio extraction application. You can use use it for compiling music in a format suitable for your PC or mobile music player. cdrparanoia is available on almost all linux distributiions.
On ubuntu you can install it with

$ sudo apt-get install cdparanoia

For trying out cdpaanoia ,put an audio CD in your cd drive and run the following command from a terminal.


$ cdparanoia -vsQ
...
Checking /dev/cdrom for cdrom...
Checking for SCSI emulation...
Checking for MMC style command set...
Verifying CDDA command set...
...
Table of contents (audio tracks only):
track length begin copy pre ch
===========================================================
1. 18295 [04:03.70] 0 [00:00.00] no no 2
2. 16872 [03:44.72] 18295 [04:03.70] no no 2
...
11. 17908 [03:58.58] 174587 [38:47.62] no no 2
12. 17342 [03:51.17] 192495 [42:46.45] no no 2
TOTAL 209837 [46:37.62] (audio only)

The above output show the capabilities of your CDROM , wheither CDDA is supported, SCSI emulation is used etc. Cdparanoia extracts audio from compact discs directly as data, and writes the data to a file or pipe in WAV, AIFC, AIFC or raw 16 bit linear PCM.

Here are some examples of cdparanoia command lines that I use.

$ cdparanoia -B Rip tracks as WAV files by track name
$ cdparanoia -B -- “3-5” Rip tracks 3-5 into separate files
$ cdparanoia -- “3-7” myrip.wav Rip tracks 3-8 to one file (myrip.wav)
$ cdparanoia -- “1:[40]-”
Rip tracks 1 from 40 secs in to end of the CD
$ cdparanoia -f -- “3”
Rip track 3 and save to AIFF format
$ cdparanoia -a -- “5”
Rip track 5 and save to AIFC format
$ cdparanoia -w -- “1” my.wav
Rip track 1 and name it my.wav


Monday, September 14, 2009

Searching Ubuntu filesystem with (m)locate

Ubuntu keeps a database of all the files in the file system at /var/lib/mlocate/mlocate.db. ( how this database is kept is dictated by /etc/updatedb.conf). The locate command
allows you to search that database. ( On Ubuntu, the locate command is a symbolic link
to mlocate. So you can also use mlocate )
You can use locate command to find out commands, devices, man pages, data files, or anything else identified by a name in the file system.
See the following example

The results come back instantly, since
the database is searched and not the actual file system. Before locate was available,
most Linux users ran the find command to find files in the file system. locate is case sensitive unless you use the –i option. Here’s an example:
$ locate -i cpuinfo
/usr/lib/python2.5/site-packages/numpy/distutils/cpuinfo.py
/usr/lib/python2.5/site-packages/numpy/distutils/cpuinfo.pyc
/usr/lib/python2.6/dist-packages/numpy/distutils/cpuinfo.py
/usr/lib/python2.6/dist-packages/numpy/distutils/cpuinfo.pyc


The mlocate package includes a cron job that runs the updatedb command once per day to update the locate database of files.
To update the locate database immediately, you can run the updatedb command manually.
$ sudo updatedb

Friday, September 11, 2009

Songbird :The Open Music Player

Songbird is an open source music player from the Mozilla stable. It is under active development and can be run on several platforms. Moreover, songbird offers several integrated services such as integrated music store, several fm and shoutcast station , concert tickets etc.

For trying out songbird you can get source/binary from the songbird website. If you are on ubuntu, ready to use packages are available at getdeb.
For installation , grab the deb corresponding to your version of ubuntu.
On my Jaunty box I did
$ sudo apt-get install songbird_1.2.0-1~getdeb1_i386.deb

Song bird appeared under Application-Sound and Video->Songbird
When I clicked on the menu item it showed me the songbird licence and proceeded to ask some configuration questions. Finally, I got the following screen and I started listening immediately,




You can do anything that you do in rhythmbox. Songbird Rocks !!

Wednesday, September 9, 2009

How to remove a deb package manually

Some times when you install a new deb package, the system will be broken. We may have to remove the package.
For this , you can try the following. ( Assuming aspell is the broken package)

# apt-get remove aspell

#dpkg -P aspell

#dpkg –force-all -r aspell

These methods can also fail some time. Your only way out will be a manual removal of packages, which can be achieved as detailed below.

a) Get a list of files from the package

# # dpkg -L aspell

b) Remove the files one by one.

c) It is also suggested that you run

# apt-get remove aspell

after manual removal.






Friday, August 28, 2009

Deluge: A cross platform bittorrent client

Deluge is a full-featured BitTorrent client for Linux, OS X, Unix and Windows. It has been designed using the client server model with a daemon process that handles all the bittorrent activity. The Deluge daemon is able to run on headless machines with the user-interfaces being able to connect remotely from any platform. Deluge features a rich plugin collection; in fact, most of Deluge's functionality is available in the form of plugins.
Installation on Ubuntu
As already mentioned , Deluge is available on a wide variety of platforms. For Ubuntu,Deluge is available in the universe repository. Cutting edge versions of Deluge is also available as a PPA via launchpad.
For installation from PPA, add the following lines to /etc/apt/sources.list
deb http://ppa.launchpad.net/deluge-team/ppa/ubuntu jaunty main
Import the key from the PPA site.
https://launchpad.net/~deluge-team/+archive/ppa
Install deluge
$ sudo apt-get install deluge

Screen shots.



Tuesday, August 25, 2009

command-not-found in Ubuntu 9.04 and 9.10

command-not-found is a special package in ubuntu that give you some extra information when you type a command that is not installed on the command line. It will look inside the package database and suggest a possible package to install so that the command can be run. command-not-found is installed automatically when you install ubuntu 9.04.

For example , I got this when I typed jed.
$ jed
The program 'jed' is currently not installed. You can install it by typing:
sudo apt-get install jed
bash: jed: command not found

However when I type

$ jid
bash: jid: command not found

The command -not-found hook neatly searches the package database and suggest a possible package for installation. The upcoming release of Ubuntu ( 9.10 aka Karmic Koala) will have spell checking incorporated into the command -not-found feature . It will suggest a list of possible packages even if you make a spelling mistake. See the following screen shot of my Karmic Koala Alpha 3.

Controlling Services from Command line

Before learning how to start, stop, and disable services from the command line, it's important to understand Ubuntu's startup process and how Ubuntu determines which programs to run when it starts.

Ubuntu uses System V style init scripts. The init scripts are located in a special directory named /etc/init.d. Even though there may be several init scripts present in /etc/init.d , not all of them are run at boot time. Ubuntu organizes which scripts to run for different circumstances into runlevels; most Linux systems have seven runlevels, ranging from 0 to 6.

A some of these runlevels are set aside for special states in a Linux system:
Runlevel 0 Halts the system.
Runlevel 1 Sets up single-user mode.
Runlevels 2-5 Set up different multi user modes. Although, typically, only one or two of these are used by a distribution.
Runlevel 6 Reboots the system.

Each runlevel has a directory that stores symlinks to certain init scripts in /etc/init.d, which are started when that runlevel is selected and stopped when it is exited. Ubuntu puts these symlinks under /etc/rc.d for example, all runlevel 2 scripts are located in /etc/rc2.d/.

If you look in one of these runlevel directories, you'll notice that many of the symlinks to scripts in /etc/init.d have odd names that begin with an S, K, or D; then a number; and finally the name of the script. Ubuntu defaults to runlevel 2, so here is a partial sample of my /etc/rc2.d directory:

lrwxrwxrwx 1 root root 19 2009-05-13 09:58 S01policykit -> ../init.d/policykit
lrwxrwxrwx 1 root root 15 2009-05-13 09:58 S10acpid -> ../init.d/acpid
lrwxrwxrwx 1 root root 14 2009-05-13 09:58 S10apmd -> ../init.d/apmd
lrwxrwxrwx 1 root root 18 2009-05-13 09:58 S99ondemand -> ../init.d/ondemand
lrwxrwxrwx 1 root root 18 2009-05-13 09:58 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx 1 root root 19 2009-05-13 09:58 S99rmnologin -> ../init.d/rmnologin
lrwxrwxrwx 1 root root 24 2009-05-13 09:58 S99stop-readahead -> ../init.d/stop-readahead

As you can see, this directory is full of symlinks that point to a script in the init.d directory.
The letter at the beginning of each filename tells init when to execute this script. If the script begins with an S, then init starts the script when it goes through the runlevel. If the script begins with a K, then init stops (or kills) the script when it changes to a different runlevel. If the script begins with a D, then that script is disabled for the time being, and init ignores it. init runs the scripts in numerical order, so the numbers in each script let you know in which order they are to be run. This is useful to ensure that dependent services start after the service they are dependent on.
Ubuntu 9.04 uses upstart daemon to manage init scripts. The configuration files for upstart are located in /etc/event.d/ . ( On earlier systems, the start up was managed from /etc/inittab. You will not find this config file in new ubuntu releases.). When ubuntu boots up the default runlevel is determined by a small script in /etc/event.d/rc-default.
Next, upstart loads any system scripts from a special system runlevel directory at /etc/rcS.d. These scripts load daemons and services that are vital to the boot process. Lastly, upstart runs any startup scripts for the default runlevel in alphabetical order. Scripts in /etc/rcS.d are run in runlevels 1 through 5, so you should generally leave them alone unless you know what you are doing. If you accidentally disable a crucial service, you may have to resort to a rescue disc to undo the mistake.

Change the Runlevel

You can change the runlevel yourself on the command line with the init command. To switch to single-user mode from the command line, type:
$ sudo init 1

If you're running X11 when you issue this command, beware, since it will kill X and your desktop environment! This command runs all of the shutdown scripts for your current runlevel and then any start up scripts for single-user mode. To change back to the default multi-user runlevel for Ubuntu, type:

$ sudo init 2

You can also use init to halt or reboot a machine: just change to runlevel 0 and runlevel 6, respectively.

Manually Start and Stop Services

You can start and stop scripts manually by running the script with the start or stop argument. For example, to stop the CUPS service from the command line, type:

$ sudo /etc/init.d/cupsys stop

To start the service back up, type:
$ sudo /etc/init.d/cupsys start

Most scripts also support a restart argument that will run stop, then start for you. Most init scripts are also configured to output the list of arguments they support when you execute them without any options:
~$ sudo /etc/init.d/cups
Password:
Usage: /etc/init.d/cups {start|stop|restart|force-reload|status}

Disable Scripts from Starting

To disable a script, you must know your default runlevel. On Ubuntu, the default runlevel is usually set to 2, but you may want to double-check your default runlevel before you start disabling services.

You can find out your current runlevel with

~$ runlevel
N 2

As you can see, in this example, the default runlevel is in fact 2. Now change to the directory containing all of the scripts for that runlevel (/etc/rc2.d) and find the script you want to disable. To disable a service, just rename its script by changing the S to a D. For example, to disable the cupsys service, type:

~$ cd /etc/rc2.d
/etc/rc2.d$ sudo mv S50cups D50cups

To enable it again, rename it back by changing the D to an S:
~$ cd /etc/rc2.d
/etc/rc2.d$ sudo mv D50cupsys S50cups

You'll still need to stop the service as shown earlier if you want to shut it down right away, but renaming it will control whether it's started the next time you reboot (or change runlevels).

Alternately, you can use the update-rc.d command to manipulate the starting /stopping of init scripts.

Monday, August 24, 2009

How to Control Startup Services on ubuntu

As Ubuntu boots up , if you press Cntrl+alt+F8, you might notice text scrolling by, detailing all of the different things Ubuntu is doing. See the screen shot below.



Apart from loading the kernel and starting the system, a number of services such as cron , gdm, cups etc are started at this time. If you have installed additional services on your system, such as a web server, they will also be started at boot. Sometimes, you may want to either stop or temporarily disable these services, and Ubuntu provides a number of ways to do this, both graphically and through the command line.
Services Administration Tool
The graphical tool to start/stop services is localted at
System->Administration->Services

You can also start it by typing the following command from a terminal.

$ sudo services-admin



Press unlock and enter your password. The screen will change to the one given below.



To disable a service, just deselect its checkbox and click Close. In Jaunty, this application supports changing only whether a service starts at boot. If you want to manually start, stop, or restart a service at a given point of time during your system usage, you need to refer to the command-line method.




Sunday, August 23, 2009

GeexBox : a 20MB wonder

Today , I was playing with geexbox , a 20MB distro specifically built for converting your PC into a powerful multimedia centre. GeeXBoX is based on Debian, it works very well on any x86 PC. Addional images are available for 64 bit architectures and PowerPC. It recognizes a large number of hardware and supports almost any audio / video or images, as well as we can playback CDs, DVDs etc.

Here are some screen shots .


The start-up screen


There are scripts to remaster the image with your own video/audio embeded with in the cd. I am yet to try them out.

Saturday, August 22, 2009

Reset a forgotten root password with a live CD

If you have forgotten the root password of a system, you can very easily reset it with a live CD
Any live Linux cd from standard Linux distros such a ubuntu , knoppix etc can be used.

Boot the system with the live CD
Open a terminal and use dmesg command to find out the hard disk.
The ide hard disk are generally named as hda, hdb etc. SATA and SCSI disks are named sda sdb etc. My SATA hard disk is detected as below.

[ 3.206832] sda: sda1 sda2 sda3 sda4 <>
[ 3.266679] sd 0:0:0:0: [sda] Attached SCSI disk

The above hard disk has several partitions. sda2 , sda2 ,sda3 are primary partitions , sda4 is divided into several logical partitions. You have to find out where your root partitions is mounted.
You can use cfdisk to find out the partitions.
$sudo cfdisk /dev/sda

I am getting the following screen .





You can examine the screen and find out the Linux partitions . If you have multiple installations , this can be tricky. You can quit from cfdisk and return to terminal. Now, try to mount the desired partition into some directory. ( Assuming that you Linux partition is /dev/sda2 , the following commands are described.)

Aquire root powers on the terminal with ( in the case of ubuntu live cd which I use)

$sudo su
 # mount /dev/sda2  /mnt/  
Now, chroot to /mnt
  #  chroot /mnt
Change the password

# passwd

Next unmount the partition and enjoy .

# umount /mnt

Friday, August 21, 2009

Cracking zip passwords with fcrackzip

Fcrackzip is a small utility that can become a handy tool when you want to look for lost zip password.
Fcracksip i a available in the ubuntu repository and you can install it as
$ sudo apt-get install fcrackzip

To see the available options with fcrackzip , try the following.

$ fcrackzip --help

You can look for a password like this.

$ fcrackzip -c a -p aaaaaa sample.zip

The above cimmand will check the encrypted files in sample.zip for all lowercase 6 character passwords (aaaaaa ... abaaba ... ghfgrg ... zzzzzz).

fcrackzip supports brute force mode as well as dictionary mode. The man page has some more interesting options you can try.