• CozWeAreFriends Banner. Nice isn't it?
  • CozWeAreFriends Banner. Nice isn't it?
  • Passwordless SSH with public key between 2 servers – troubleshooting /home permission issue

    Posted on May 15th, 2012 by fath

    Hi All,

    Whenever we faced issue during SSH between 2 servers with public key, remember always to run with verbose option (-vvv) to troubleshoot the issue. Below is what I saw in the terminal with -vvv option:

    [XXX@XXXXX .ssh]$ ssh -vvv XXXX@XX.XX.XX.XX
    OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Applying options for *
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to XX.XX.XX.XX [XX.XX.XX.XX] port 22.
    debug1: Connection established.
    debug1: identity file /home/aia/.ssh/identity type 0
    debug3: Not a RSA1 key file /home/aia/.ssh/id_rsa.
    debug2: key_type_from_name: unknown key type ‘—–BEGIN’
    debug3: key_read: missing keytype
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug2: key_type_from_name: unknown key type ‘—–END’
    debug3: key_read: missing keytype
    debug1: identity file /home/aia/.ssh/id_rsa type 1
    debug3: Not a RSA1 key file /home/aia/.ssh/id_dsa.
    debug2: key_type_from_name: unknown key type ‘—–BEGIN’
    debug3: key_read: missing keytype
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug2: key_type_from_name: unknown key type ‘—–END’
    debug3: key_read: missing keytype
    debug1: identity file /home/aia/.ssh/id_dsa type 2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_4.5p1+sftpfilecontrol-v1.1-hpn12v14
    debug1: match: OpenSSH_4.5p1+sftpfilecontrol-v1.1-hpn12v14 pat OpenSSH*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_3.9p1
    debug2: fd 3 setting O_NONBLOCK
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256 cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: none,zlib@openssh.com
    debug2: kex_parse_kexinit: none,zlib@openssh.com
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: mac_init: found hmac-md5
    debug1: kex: server->client aes128-cbc hmac-md5 none
    debug2: mac_init: found hmac-md5
    debug1: kex: client->server aes128-cbc hmac-md5 none
    debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
    debug2: dh_gen_key: priv key bits set: 137/256
    debug2: bits set: 536/1024
    debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
    debug3: check_host_in_hostfile: filename /home/aia/.ssh/known_hosts
    debug3: check_host_in_hostfile: match line 2
    debug1: Host ‘10.14.24.114’ is known and matches the RSA host key.
    debug1: Found key in /home/aia/.ssh/known_hosts:2
    debug2: bits set: 489/1024
    debug1: ssh_rsa_verify: signature correct
    debug2: kex_derive_keys
    debug2: set_newkeys: mode 1
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug2: set_newkeys: mode 0
    debug1: SSH2_MSG_NEWKEYS received
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug2: key: /home/aia/.ssh/id_rsa (0x552ac03c40)
    debug2: key: /home/aia/.ssh/id_dsa (0x552ac04190)
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug3: start over, passed a different list publickey,password,keyboard-interactive
    debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
    debug3: authmethod_lookup publickey
    debug3: remaining preferred: keyboard-interactive,password
    debug3: authmethod_is_enabled publickey
    debug1: Next authentication method: publickey
    debug1: Offering public key: /home/aia/.ssh/id_rsa
    debug3: send_pubkey_test
    debug2: we sent a publickey packet, wait for reply
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Offering public key: /home/aia/.ssh/id_dsa
    debug3: send_pubkey_test
    debug2: we sent a publickey packet, wait for reply
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug2: we did not send a packet, disable method
    debug3: authmethod_lookup keyboard-interactive
    debug3: remaining preferred: password
    debug3: authmethod_is_enabled keyboard-interactive
    debug1: Next authentication method: keyboard-interactive
    debug2: userauth_kbdint
    debug2: we sent a keyboard-interactive packet, wait for reply
    debug2: input_userauth_info_req
    debug2: input_userauth_info_req: num_prompts 1
    Password:

     

    Looks like we’re asked about the password although we’ve concatenate the source public key into target authorized_keys. Hmm.. So, what’s the issue? Permission! From what I saw in the server, authorized_keys, .ssh directory, were set with correct permission. Hm.. what else? Let’s see the server syslog.

    May 15 14:50:43 XXXXXX sshd[12193]: Authentication refused: bad ownership or modes for directory /home/staging

     

    Yeah, now we got a clue.. There’s issue with our home directory permission. Below is the permission set:

    drwxrwxr-x   3 staging    staging       8192 May 15 08:55 staging

    Probably 775 is too much for this directory. Let’s make it 755.
    Now we can SSH successfully without password. 🙂

     

    Rights for non-DOD U.S. Government Departments and Agencies are as set
    forth in FAR 52.227-19(c)(1,2).
    You have mail.
    $



    How to sort process running in HP-UX server by Memory utilization (RSS)

    Posted on April 30th, 2012 by fath

    Hello All,

    Regarding the topic that I posted, run the Glance command. You will see by default, the processes listed in the screen are sorted by CPU usage. You may use this settings if you want to see which program/application is running active at any instance time. But what if the server memory is spiking all the time and you need to know which application is causing that? The investigation can be started by looking into process that consumes the largest memory.

    Once you are in Glance, then hit “o” and you will see the image below right at the bottom of the screen. Press 1.

    After getting into the page below, press “down” arrow until you reach “Sort key” option. Then type in “rss” and hit enter.

    The alert below will show up. Press “y” to save this setting as default.

    You will be redirected to the initial Glance page. Now, the processes are already sorted by the memory utilization.

    Hope this helps. Cheers! 🙂

     



    Siebel Restart WebServer Script When Memory Reaching Threshold

    Posted on April 27th, 2012 by fath

    Hello All,

    There’s this occasion whereby Siebel will somehow crash if the server memory reaching certain level. To encounter/as a workaround for this, I wrote a monitoring script that will check the server utilization and perform Siebel’s WebServer restart whenever only small amount of memory left in the server. Please have a look at the script below 🙂

     

    #!/usr/bin/sh
    # Script to grep Free RAM
    # Perform Web Server restart once the RAM meet threshold
    # Written by Fath

    # THRESHOLD IN ‘K’ bytes UNIT
    THRESHOLD=1400000

    WEB_SERVICE_DIR=/opt/hpws/apache32/bin

    FREE_RAM_OUTPUT=/home/admin/FREE_RAM_OUTPUT.txt
    TOP_OUTPUT=/home/admin/TOP_OUTPUT.txt
    top -d1 -f ${TOP_OUTPUT}

    MEMORY_ALL=`grep “Memory:” ${TOP_OUTPUT}`
    FREE_RAM=`echo ${MEMORY_ALL} | awk ‘{print $8}’`
    FREE_RAM_NO=`echo $FREE_RAM | awk ‘{gsub (/K/,””); print}’`

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    date >> ${FREE_RAM_OUTPUT}

    if [ “$FREE_RAM_NO” -lt “$THRESHOLD” ];then
    echo “Free RAM is less than ${THRESHOLD}K (${FREE_RAM_NO}K). Performing Web Service restart…” >> ${FREE_RAM_OUTPUT}
    echo “httpd processes running in server:” >> ${FREE_RAM_OUTPUT}
    ps -ef | grep httpd | grep apache32 >> ${FREE_RAM_OUTPUT}
    echo “Shutting down.. ” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/stopapa >> ${FREE_RAM_OUTPUT}
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    while [ “$PROC_COUNT” -ne “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “0 httpd process running. Starting up..” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/startapa >> ${FREE_RAM_OUTPUT}
    while [ “$PROC_COUNT” -eq “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “OK! httpd processes are running!” >> ${FREE_RAM_OUTPUT}
    else
    echo “There’s enough free RAM (${FREE_RAM_NO}K).” >> ${FREE_RAM_OUTPUT}
    fi

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    rm ${TOP_OUTPUT}

     



    UNIX – Shell script to create XMLs based on user input data

    Posted on April 26th, 2012 by fath

    Hi All,

    I wrote a simple shell script that can read parameterized XML structure and will generate completed XMLs (with correct values) based on what we specified in the input data. This script was actually meant for my initial phase of Performance Testing data loading in my project.

    To accomplish this, I created 3 files which are the script itself, the parameterized XML template, as well as the data file. Below are the files:

    1) structure.txt (XML template) – here I replaced the value of the field that we need to parameterize with variable, such as ${ACC_NUM}

    <Sbsc xmlns=”http://www.cozwearefriends.com/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.cozwearefriends.com/XMLSchema XXX_Subsc
    ribers.xsd”>
    <ActSbsc id=”${ACC_NUM}”>
    <Act>
    <ActNo>${ACC_NUM}</ActNo>
    <Curr>${LOG}</Curr>
    <CustSegList/>
    <SubSta>A</SubSta>
    <BType>B</Btype>
    <Eff>2011-08-01T01:22:15-07:00</Eff>
    <CrtT>2011-08-01T01:22:15-07:00</CrtT>
    <ANArr elem=1>
    </Act>
    </ActSbsc>
    </Sbsc>

    2) createXML.sh (Shell script)

    # Script to create XML
    # based on user input
    # created by Fath

    STRUCTURE_FILE=structure.txt
    INPUT_FILE=input.txt
    OUTPUT_FILE=output.xml

    LOOP_NUMBER=`cat ${INPUT_FILE} | wc -l`

    i=1
    while [ “$i” -lt “$LOOP_NUMBER+1” ]
    do
    ACC_NUM=`head -${i} ${INPUT_FILE} | tail -1 | cut -f1 -d’;’`
    LOG=`head -${i} ${INPUT_FILE} | tail -1 | cut -f2 -d’;’`
    # Add in more variable here as well as in the command below if you have more than 2 parameters

    cat ${STRUCTURE_FILE} | sed -e s/’${ACC_NUM}’/${ACC_NUM}/g -e s/’${LOG}’/${LOG}/g >> ${OUTPUT_FILE}

    i=$((i+1))
    done

    3) input.txt (data file)

    ACC1;LOG1;
    ACC2;LOG2;
    ACC3;LOG3;

     

    You may change the files above depending on your requirements. Cheers. 🙂

     



    UNIX – Shell script to capture SQL query using Oracle sqlplus

    Posted on April 22nd, 2012 by fath

    Hi All,
    In my project, as part of Performance Testing team, I’ve wrote a number of scripts to help us perform our duty in system tunings. Here. I’d like to share one of my shell script that can help to capture SQL query running in the background.Feel free to modify this script to fit your own requirement.

     

    ###############################
    # CAPTURE SQL – by Fath #
    ###############################
    ################# PARAMETERS #################

    ##############################################
    #SH_LOG=”$location/CAPTURE_SQL.log”

    clear
    echo “*****************************************************************”
    echo “PV SQL CAPTURE SCRIPT”
    echo “*****************************************************************”

    echo “LOADING CAPTURING SQL..”

    echo “”
    pros=`ps -ef | grep ora_pmon | awk ‘{print $9}’ | grep ora_pmon_ | awk ‘{print substr($1,10)}’`

    echo “Database running on Oracle Process = $pros”
    echo “Oracle SID = $ORACLE_SID”
    echo “Proceed? [y/n]”
    read option
    echo “”

    if [ “$option” = “y” ]
    then
    echo “Enter sid and serial#”
    echo “SID:”
    read sid
    echo “Serial #:”
    read serial

    result=`sqlplus -s ‘/as sysdba’ << ENDOFSQL
    begin
    dbms_system.set_ev(‘$sid’,’$serial’,10046,12,”);
    end;
    /

    begin
    DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>’$sid’, serial#=>’$serial’,sql_trace=>TRUE);
    end;
    /
    show parameter user_dump_dest
    exit;
    ENDOFSQL`

    #path=”$result”

    echo “”
    echo “——————————-”
    echo “Remarks:”
    echo “Spooled queries will be generated in:”
    #echo “$path” | grep /app | awk ‘{print $3}’

    path=”/app/oracle/admin/NSBLPVT/udump”
    echo “$path”
    echo “——————————-”
    echo “”

    while true
    do
    echo “Stop capturing? [y/n]”
    read option2
    echo “”

    if [ “$option2” = “y” ]
    then
    result2=`sqlplus -s ‘/as sysdba’ << ENDOFSQL
    begin
    DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>’$sid’, serial#=>’$serial’,sql_trace=>FALSE);
    end;
    /
    exit;
    ENDOFSQL`

    echo “——————————-”
    echo “Results: ”
    echo “SQL captured in: ”
    result3=`ls -lrt $path | tail -n 1 | awk ‘{print $9}’`
    echo “$result3”
    echo “Converting trace file to log…”
    result4=`tkprof $path/$result3 SQL_CAPTURED[$result3].log sys=no waits=yes sort=exeela`
    echo “Converted to SQL_CAPTURED[$result3].log…”
    echo “Completed.”
    echo “——————————-”

    break
    fi
    done
    fi

    echo “”
    echo “SEE YOU AGAIN!!”
    echo “”