Thursday, August 22, 2013

SSH prompting for password even after generating the RSA keys with empty password

I struggled with this issue almost every time I wanted to login to remote hosts without entering the passwords. In some places, I used this solution because I was lazy and in some places it is a requirement such as, Hadoop setup. Anyways, the key to the solution is permissions and the steps are as under:

{USER}@machine1> rm -rf /home/{USER}/.ssh
{USER}@machine2> rm -rf /home/{USER}/.ssh /tmp/id_rsa.pub
{USER}@machine1> ssh-keygen -t rsa [Enter, Enter, Enter]
{USER}@machine1> scp /home/{USER}/.ssh/id_rsa.pub {USER}@machine2:/tmp
{USER}@machine2> mkdir /home/{USER}/.ssh
{USER}@machine2> cat /tmp/id_rsa.pub >> /home/{USER}/.ssh/authorized_keys
{USER}@machine2> chmod -R 700 /home/{USER}/.ssh
{USER}@machine1> chmod 600 /home/{USER}/.ssh/id_rsa*

{USER}@machine2> rm /tmp/id_rsa.pub
{USER}@machine1> chmod 755 /home/{USER}
{USER}@machine2> chmod 755 /home/{USER}


In above steps, replace the {USER} with your user and machine1 and machine2 with appropriate machine ip addresses.h

Please note, the steps marked in BOLD and they should have exactly the same permissions.

Wednesday, August 21, 2013

Step by Step guide to enable X11 forwarding using Cygwin

I always found a need of X11 forwarding and so writing this step by step guide for reference:

Step 1: Install Cygwin/X: I would like to take you through the minimum required packages for Cygwin/X and here are the detailed steps:

  1. Download the cygwin setup file from http://cygwin.com/install.html
  2. Run the Cygwin setup program and you will see the welcome screen.Click Next to proceed to the next screen.
  3. Choose, Install from Internet, this will still save the package files to your download directory so that you can install Cygwin on any number of machines. Click Next to proceed to the next screen.
  4. The default Install Root is c:\cygwin which should be fine for most installations. Leave Default Text File Type as UNIX. Leave Install For set to All unless you lack local administrative privileges.
  5. Click Next to proceed to the next screen.
  6. Local Package Directory should default to the directory that you ran setup.exe from.Click Next to proceed to the next screen.
  7. Choose your proxy setup, or, just choose Direct Connection if no proxy is needed.Click Next to proceed to the next screen.
  8. Select the first mirror for downloading. Click Next to proceed to the next screen; setup will download a list of available packages as it moves to the next screen.
  9. On the next screen you will select the packages that will be downloaded and installed. A listing of the Cygwin/X packages is given below; a listing of the general Cygwin packages would be beyond the scope of this document.
  10. Cygwin/X packages are located in the X11 category:
    • xorg-server (required, the Cygwin/X X Server)
    • xinit (required, scripts for starting the X server: xinitstartxstartwin (and a shortcut on the Start Menu to run it),startxdmcp.bat )
    • xorg-docs (optional, man pages)
    • You may also select any X client programs you want to use, and any fonts you would like to have available.
    • You may also want to ensure that the openssh package is selected if you wish to use ssh connections to run remote X clients.
    • You may also want to ensure that the inetutils or rsh packages are selected if you wish to use telnet or rsh connections to run remote X clients. (not recommended)
  11. Click Next to begin the download process, you may want to try another mirror if you see a "Connecting" message on this screen for a long period of time.
  12. You have now successfully installed Cygwin/X.
Step 2: On your desktop, start the XWin Server from Start > All Programs > Cygwin-X > XWin Server

Step 3: On the XWin Server window, type the following:
  1. ssh -X -C user@hostname
  2. type xclock and it should throw the xclock display
Step 4: If you need to sudo to a different user and still make the X11 work, you need to do the following (before running the sudo command):
  • xauth list
          hostname/unix:13  MIT-MAGIC-COOKIE-1  ada9344e4a990d3b05d3bf66a9948758

          hostname/unix:10  MIT-MAGIC-COOKIE-1  11b30b1d65d90e64d15d811a97b9fb20
          hostname/unix:11  MIT-MAGIC-COOKIE-1  ddaa0d9fc7da0ee5228aa459ccdf427c
  • sudo su - <>
  • echo $DISPLAY
          localhost:11.0
  • xauth add  hostname/unix:11  MIT-MAGIC-COOKIE-1  ddaa0d9fc7da0ee5228aa459ccdf427c
         11 in the $DISPLAY matches the 11 in the list of the xauth.

Now you should be able to throw the display from the remote machine to your local machine.

Tuesday, June 4, 2013

Takes too long to restart the Weblogic Managed Servers

If your Weblogic server startup takes too long, then you might be running into entropy bug that can be fixed in one of the 3 ways:

  1. Patch /jre/lib/security/java.security by replacing the line "securerandom.source=file:/dev/urandom" with "securerandom.source=file:/dev/./urandom"
  2. Add JVM argument -Djava.security.egd=file:/dev/./urandom to the startup scripts
  3. Create a symlink for /dev/urandom to point to /dev/./urandom

Monday, June 3, 2013

Updating a large table in batches

In order to update million of record using the UPDATE statement can be time-consuming and may lead to timeout errors and other issues. A better approach would be to commit the updates in batches and here is the PL/SQL recipe for doing it:

declare
   cursor c is select rowid id from <TABLE> order by rowid;
   counter NUMBER(10) := 0;
   rowids dbms_sql.urowid_table;  

begin
   dbms_output.enable;
   open c;
   loop  
      fetch c bulk collect into rowids limit 1000;
      forall i in 1..rowids.count
         update <TABLE> set date=SYSDATE
              where rowid = rowids(i);
      commit;
      counter := counter + 1;
      dbms_output.put_line('Updated batch ' || counter );
      exit when c%notfound;
   end loop;
   close c;
end;
/

The above PL/SQL would update the DATE column of the table <TABLE> in batches of 1000 and will be much faster than the traditional UPDATE statement.

Search This Blog