Change the Java (JVM) used by tomcat.

Enterprise systems will have different versions of Java installed in it. A system administrator may have to set up Tomcat to use a particular one out of it. By default Tomcat uses the OS default; ie. the one installed into OS path. So how can we make it run with another version of Java.

This is easily achieved using the below commands(Open a terminal and run the below commands, don’t close it.):

export JAVA_HOME=<path-to-java>

or

export JRE_HOME=<path-to-java>

Run the start-up script from the same terminal and you will see from the logs that Tomcat picked up the Java from the path you set.

Notes:

JRE_HOME is set to JAVA_HOME if not set. So setting any of these variables suffice.

Shared folder for Fedora VM in VirtualBox

Hi,

I found a little hard to setup a shared folder for my VMs. So thought of sharing it..

So, assuming you already have your host machine, VirtualBox installed on it and a VM running Fedora (any linux), there we go..

Highlight your VM in VirtualBox window.

Screen Shot 2015-03-17 at 3.40.41 pmYes, it is powered off. Bring up the settings window for the VM clicking the below icon.

Screen Shot 2015-03-17 at 3.41.02 pmChoose the “Shared Folders” tab and you will see the list of folders shared with VM.Screen Shot 2015-03-17 at 3.41.22 pmClick on the plus sign you see on the left side and you get another window like the one below.

Screen Shot 2015-03-17 at 3.41.44 pmYou may choose the folder of the host machine you want to share and tick the “Auto-mount” option. Click OK.

Screen Shot 2015-03-17 at 4.12.42 pm

The folder you chose to share is now visible and we are done with the VirtualBox settings. Click OK to come out of it.

Screen Shot 2015-03-17 at 4.13.05 pm

Now boot up the VM. We need to install a few packages in Fedora for this. You may use below command to install the same.

Screen Shot 2015-03-17 at 5.11.50 pmThis will install latest gcc and kernel-devel packages. Guest addition may get arrogant, at times and gives error that it can’t find a particular version of kernel-devel. I will explain how to solve that later.

Now we can install “Guest Addition”

Click on the “Devices” menu and select the below highlighted option.Screen Shot 2015-03-17 at 4.15.35 pmSome OS automatically run the autorun script from CD. Otherwise open a file-browser and open the CD contents. You will see “autorun.sh” file there. Drag and drop it to Terminal. It will first authenticate you and start installing “Guest Addition”.

Screen Shot 2015-03-17 at 4.59.33 pmScreen Shot 2015-03-17 at 4.53.26 pm

You will get below output 99% of the times and that means just a reboot and you have a host-folder available in VM.

Screen Shot 2015-03-17 at 5.26.14 pm

The shared folder will be auto-mounted in /media.

Screen Shot 2015-03-17 at 5.30.02 pmThe 1% I left earlier is the case when “Guest Addition” fails to install with an error about the kernel-devel version. You may get below screen in such cases.

Screen Shot 2015-03-17 at 4.54.16 pmIn such cases you get a command from the above output.

yum install kernel-devel-3.17.4-301.fc21.x86_64

Just run the below part out of it and do the “Guest Addition” installation again and you are good to go..

yum install kernel-devel-3.17.4

Now let me take you through another issue you may face. Your folder will get listed in /media. But you may not have permission to open it. In my case, “Shared” is the shared-folder. /media/sf_Shared is the path in VM where it is mounted.

ls /media/sf_Shared

The above command will give an output like this:Screen Shot 2015-03-18 at 9.48.20 pm

This is because of the difference of UID in host and VM machines.

Screen Shot 2015-03-18 at 9.24.30 pm

The easiest way to sort this out is to add the user account to vboxsf.

usermod -a -G vboxsf

I went for a reboot (of VM) after that and things worked well.

May be you want to do this too.

Create a link in your home directory to access the shared directory mounted in /media. Make sure your home directory does not have “Shared” folder already.

ln -s /media/sf_Shared ~/Shared

So now you may use ~/Shared as your window to the host-machine..

Encrypt and Decrypt data using RSA with Openssl

What is RSA?

What is OpenSSL?

Generate private key:

  • openssl genrsa -out privatekey.pem 2048
  • openssl genrsa  // private key is written to stdout

Generate public key from the private key generated above:

  • openssl rsa -pubout -in privatekey.pem -out publickey.pem
  • openssl rsa -pubout  // copy paste the private key from the stdout; public key will be displayed on the screen

You must have your public and private keys in two files to continue. I have my public key in publickey.pem and private key in privatekey.pem and data to be encrypted in data.txt. Lets now encrypt and decrypt to check the correctness.

  • openssl rsautl -in data.txt -out encrypted_data.txt -inkey publickey.pem -encrypt -pubin

You will have encrypted_data.txt file created and you will see some wierd characters if you open it. Don’t worry, that is the exact purpose of encryption: make it not readable unless you decrypt with private key. So now lets use our private key to decrypt. Lets see if we get our original data back.

  • openssl rsautl -in encrypted_data.txt -out decrypted_data.txt  -inkey publickey.pem -encrypt -pubin

Compare data.txt and decrypted_data.txt and see the magic.. 😛