Run script on remote host

Hi friends,

I have two servers. Server A and B.
I want to run one script on server A by logging in to server B.
Can anyone provide me code for this.? I tried it by using following

ssh username@serverA ./script

Then it prompt me the password. I give correct password of the server A. but it says access denied.

What are other commands to achieve this? Is it required to do some configuration changes on server A and B before doing this?

Does ./script exist on the remote server? If not, would you expect it to be able to find that file?

Try

ssh username@remoteserver exec /bin/sh -s < ./localscriptfile

This command is not working.
Let me tell you in detail
I have script at following path on server A

/user/ns123/script

I login to server A and execute following command directly

sh  /user/ns123/script

Now,
I want to do this without logging in to server A. I am on server B and want to run this on server A

sh  /user/ns123/script

What do you mean 'not logging in'? If you're using ssh you're logging in...

i mean not directly login to server A.
I am expecting "remote access" of server A through server B

In what way would you not directly login? Is there an intermediate host? Your script above is logging in as directly as anything else.

It may have PATH problems however. Try . /etc/profile ; /path/to/script'

What happens if you issue your command with the script's full path

ssh username@serverA /user/ns123/script

?

Ensure that /user/ns123/script is readable and executable.
In case it's not executable you can do

ssh username@serverA sh /user/ns123/script