I think the default timeout for ssh is 30 seconds. Did you wait that long? Maybe add a -o ConnectTimeout=3 to see if there is anything happening after 3 seconds.
Make sure sshd running on machineB, that there is no firewall inbetween etc. If you have nmap, you can also try to do following:
You did not answer that you made sure, that sshd is running on machineB. There is no firewall between them? Can you reach machineB on any other port than ssh? Start with ping for basic network reachability. Then maybe add ftp or whatever daemons you have up and running on machineB.
Your scp was working but ssh not. That is strange but at least shows, that your sshd is up and working since scp does use the same.
Now your ssh works on the command line. Did you supply a password or did you exchange keys? If you exchanged keys and it worked, it should work in a script too without problems. If this is the case, post the script using code tags.
If you supplied a password to ssh on the command line, then you have to create a password-less key pair on machineA, add the public key of those to machineB's .ssh/authorized_keys or .ssh/authorized_keys2 to have this way working to connect via ssh/scp/sftp without being asked to provide a password.
I am not providing any password to ssh. However, not sure how could I as i do not see any option to provide password.
ssh
Usage: ssh [options] host [command]
Options:
-l user Log in using this user name.
-n Redirect input from /dev/null.
-F config Config file (default: ~/.ssh/config).
-A Enable authentication agent forwarding.
-a Disable authentication agent forwarding (default).
-X Enable X11 connection forwarding.
-x Disable X11 connection forwarding (default).
-i file Identity for public key authentication (default: ~/.ssh/identity)
-t Tty; allocate a tty even if command is given.
-T Do not allocate a tty.
-v Verbose; display verbose debugging messages.
Multiple -v increases verbosity.
-V Display version number only.
-q Quiet; don't display any warning messages.
-f Fork into background after authentication.
-e char Set escape character; ``none'' = disable (default: ~).
-c cipher Select encryption algorithm
-m macs Specify MAC algorithms for protocol version 2.
-p port Connect to this port. Server must be on the same port.
-L listen-port:host:port Forward local port to remote address
-R listen-port:host:port Forward remote port to local address
These cause ssh to listen for connections on a port, and
forward them to the other side by connecting to host:port.
-D port Enable dynamic application-level port forwarding.
-C Enable compression.
-N Do not execute a shell or command.
-g Allow remote hosts to connect to forwarded ports.
-1 Force protocol version 1.
-2 Force protocol version 2.
-4 Use IPv4 only.
-6 Use IPv6 only.
-o 'option' Process the option as if it was read from a configuration file.
-s Invoke command (mandatory) as SSH2 subsystem.
-b addr Local IP address.
Can you help me with what option do i use?
Meanwhile, it will be a great help if you could let me know how can i supply the script to be executed on machineB with ssh as I am successful in ssh from machineA to machineB. I will troubleshoot ssh not working other way round post this.
There should be no non-interactive passing of passwords to ssh - that's what keys are for. Passing passwords always means to have them unencrypted in your filesystem. You could do it though with expect. But as already said I guess there could be something wrong with exchanged keys.
If your ssh login works, you can issue the command for the script the same way, if the script is deployed on the target machine: