Thursday, October 18, 2012

Change default Java version in Linux (Ubuntu)

I have decide to install jdk1.6.0_24 to my Ubuntu server 10.04 LTS and I want to make this as default java in my servere.

Note: if you laready have version you want to make default simple run the step 4 .

  1. Installed above jdk using jdk-6u24-linux-x64.bin in preferred directory
    in my case  : ‘/usr/lib/jvm’
  2. Once you installed I got following directory installed  ‘/usr/lib/jvm/jdk1.6.0_24’
  3. Now run following command :
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_24/jre/bin/java" 1
  4. Now time to select which java version you prefer , simple run and select the version
    sudo update-alternatives --config java
      eg :
       Selection    Path                                      Priority   Status
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.6.0_24/jre/bin/java      1         manual mode

Press enter to keep the current choice[*], or type selection number: 2
That’s it your default java now set to target version.

  5. Same time you can change $JAVA_HOME and path variable to reflect changes . I prefer global change  
       so I edit /etc/profile and append
       export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_24
       export PATH=$PATH:$JAVA_HOME/bin

That’s it your server now refer to preferred java version .

Wednesday, October 17, 2012

Open Port scaning for linux(Ubuntu)

If you want ever want to find the ports that are open in a target server or network you may use
utility call `nmap` .
eg :
 in Ubuntu       1. Install the nmpa using -- > sudo apt-get install nmap
                       2.port scan for target ip  -- >  nmap -v -sT

you may get an output like below . Please use `nmap `Manual page to find more options

Starting Nmap 5.21 ( ) at 2012-10-17 18:45 PGT
Initiating Ping Scan at 18:45
Scanning [2 ports]
Completed Ping Scan at 18:45, 0.01s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 18:45
Completed Parallel DNS resolution of 1 host. at 18:45, 0.06s elapsed
Initiating Connect Scan at 18:45
Scanning [1000 ports]
Discovered open port 80/tcp on
Discovered open port 8080/tcp on
Discovered open port 3306/tcp on
Discovered open port 445/tcp on
Discovered open port 22/tcp on
Discovered open port 21/tcp on
Discovered open port 139/tcp on
Discovered open port 8081/tcp on
Discovered open port 8090/tcp on
Completed Connect Scan at 18:45, 0.02s elapsed (1000 total ports)
Nmap scan report for
Host is up (0.00094s latency).
Not shown: 991 closed ports
21/tcp   open  ftp
22/tcp   open  ssh
80/tcp   open  http
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3306/tcp open  mysql
8080/tcp open  http-proxy
8081/tcp open  blackice-icecap
8090/tcp open  unknown

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

Wednesday, July 4, 2012

Find large files in the system -Linux

Find large files in the system -Linux:

Navigate to ‘/’ then issue the following command

sudo  du -h  | egrep '([0-9]+(\.)*[0-9]*)G(.*)'

    ·         Command will be in effect from the path you execute . ‘sudo’ is optional
    ·         'G' represent gigabyte  . change it depends on scale you want .

Tuesday, March 20, 2012

One line for loop Linux command

Format : for i in {1..N} ; do  <command>;done;
Eg :
for i in {1..100} ;
do  sleep 2;echo `date`;done;

Installing custom init-scripts

Let’s say you want to start a script every time you start
your linux machine (Ubuntu) and stop 
when shutdown sequence initiate.

Create your script eg : ‘myScript’

1. sudo vim /etc/init.d/myScript              or ‘vi’ to write the script.
2. sudo chmod +x /etc/init.d/myScript                    [to adjust the permission]
3. sudo update-rc.d myScript defaults 98 02  [98 and 02 are the start 
                                 and stop sequence numbers respectively]
myScript above accept start and stop as arguments .
Refer your ‘tomcat’ script in /etc/init.d/tomcat if you want to 
know how to accept above arguments (if you dont have stop ,
then it will retry same thing at shutdown). 
my above script eg is for start/stop vpn.
Source reference from:

Wednesday, February 15, 2012

Disable root login in Ubuntu – Avoid unexpected ‘OMG’ problems.

Recently I faced a huge issues in my production environment ,where ppl try to login as root to system which made system more unstable(Yes I know its in mess- super democracy server). As you know Ubuntu came with ‘Sudo’ concept which gives all the privilege’s that you want in systems. There for don not allow root user in your system especially in production. More details can be found in :

 Two steps to block any root logins :
1.      Disable Root user : 
sudo passwd -dl root

2.  Disable root login in ssh config:
vim /etc/ssh/sshd_config
PermitRootLogin no
And restart sshd -- > /etc/init.d/sshd restart

BTWAY: I was able to recover lost root password from a linux machine. Will update on that in future release .

Monday, February 6, 2012

Detect USB Flash Drivers in linux

Following Script Display possible USB devices attached to the system : Tested on Ubantu 10.04 LTS

#author sanjeewaF

for udi in $(/usr/bin/hal-find-by-capability --capability storage)
    device=$(hal-get-property --udi $udi --key block.device)
    vendor=$(hal-get-property --udi $udi --key storage.vendor)
    model=$(hal-get-property --udi $udi --key storage.model)

   if  [ `hal-get-property --udi $udi --key linux.sysfs_path | grep -i usb | wc -l` -gt 0 ]
           echo "Possible USB:"
           parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
           mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
           label=$(hal-get-property --udi $parent_udi --key volume.label)
            media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
           size=$(( media_size/(1000*1000*1000) ))
            printf "$vendor  $model  $device  $mount  $label "${size}GB" \n"