Friday, October 28, 2011

ssh from Windows to Linux without password using putty

Putty is used heavily to ssh from Windows to Linux systems. It is irritating to keep entering username and password to some of the systems esp test machines which are frequently used and whose security is not of lot of concern or at the most you are ready to use a single passphrase for the same. In my case I wanted to login to my Linux system without using password. This is how I went about doing this.

1. Use puttygen to create public/private key pair. To do this run puttygen and click on "Generate"

2. Now click on "Save public key" and "Save private Key" to save it in a folder of your choice.

3. In a box above you will see something such as :-

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBbarb4KbbSZnttu0F5OqGX
+Vo+TDvNbF3bINcywZamoZrTW4YwAHR6yUaqJX4gv3bFM0pbMlUuYYCkHC
f1xp5ps2NiTrJnm+GnKHdBKRNT4AdlUYDgzEkMgoa0Rz120UO+JkgdVAxcNfDbE
Dlqjk+i6+rIg12/2M1xCc+yjTGBgw== rsa-key-20111028

4. Copy paste this into a file in your Linux system. The file is /home//.ssh/authorized_keys

5. Now open putty and the enter your Linux host details. If it is already present, load it.

6. Goto Connection -> Data on your right hand side menu tree.

7. Enter the username in Auto-Login Username textbox.

8. Goto SSH -> Auth. Browse and choose the private key file under 'Private Key file for authentication'
9. Save it

Now try login and it should take you in directly.

Friday, May 6, 2011

Compare two arrays in Ruby

Today I had a need to compare 2 arrays in Ruby and if they are the same, then do something else something. I googled and found this solution

Let us say a1 and a2 are the arrays then

diff=a1-a2
if diff.empty ? then
puts "arrays are the same"
else
puts "arrays are different"
end

Tuesday, April 19, 2011

To add two integers in Shell Script

Adding two numbers are not as easy as i=$i+1 in shell script. It is done using different ways. Here is one example :-

#!/bin/sh
i=1
while [ $i -lt 3 ]
do
echo "test"
i=$(($i+1))
echo $i
done

Thursday, November 18, 2010

Specifying firefox path in selenium

Selenium sometimes throw the error saying it cannot open firefox and asks the user to set the path.
Please add the directory containing ''firefox.exe'' to your PATH environment
variable
, or explicitly specify a path to Firefox 3 like this:
*firefox3c:\blah\firefox.exe
I tried setting the path of firefox in the environment variable PATH but somehow it didn't work. So here is how to explictly specify it

@selenium = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
:url => "http://abc.com"

This solved the issue and opened firefox.

There was another issue of firefox opening in a small window during a test run and I wanted it to open a maximized size. In ruby this is how I solved this :-

In setup section after opening browser session, say window_maximize

@selenium.start_new_browser_session
@selenium.window_maximize

Tuesday, September 7, 2010

Change domain name in mail command for Unix

I was using mail command to send mail from the command line. However, my from address was coming as username@hostname and my mail server was not accepting this mail. I searched google for solutions but none worked for me. So atlast this is what I did.

1. Installed sendmail using "sudo apt-get install sendmail"
2. Install mailutils - "sudo apt-get install mailutils"
2. sudo vim /etc/mail/sendmail.mc
3. Changed the parameter "MASQUERADE_AS"

MASQUERADE_AS(`mydomain.com')dnl

4. Run "sudo sendmailconfig"
5. Now sent mail using
echo "this is mail body" | mail -s "this is test " sabu@mydomain.com

My last few lines of sendmail.c looks like :-

include(`/etc/mail/m4/dialup.m4')dnl
include(`/etc/mail/m4/provider.m4')dnl
dnl #
dnl # Default Mailer setup
dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`mydomain.com')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
MAILER_DEFINITIONS
MAILER(`local')dnl
MAILER(`smtp')dnl

Sendmail installation issue

While installing sendmail, I was thrown the following error :-

*** ERROR: FEATURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`always_add_domain')*** ERROR: FEA TURE() should be before MAILER()
*** MAILER(`local') must appear after FEATURE(`allmasquerade')*** ERROR: FEATURE () should be before MAILER()
NONE:0: m4: ERROR: EOF in string

I searched google only to find people suggesting to install postfix instead of sendmail. Now thats not what I want to do. I want to fix the above issue. Here is how I did it :-
sudo vim /etc/mail/sendmail.mc
Search and move the following lines to end of the file :-

MAILER_DEFINITIONS
MAILER(`local')dnl
MAILER(`smtp')dnl

And now it works.

Friday, August 27, 2010

On to Python

I am now on to Python, after tcl, after Ruby, after Perl. My progress is quick since I know Perl and Ruby. It doesn't matter if you don't know the syntax if you have experience in say Ruby or Perl.