Execute script located on a remote machine

Please see if the below helps.

I tried this...

C:\Program Files\PuTTY>plink -v -ssh ms104u@144.160.112.17 ssh ms104u@132.201.72.229
Looking up host "144.160.112.17"
Connecting to 144.160.112.17 port 22
Server version: SSH-2.0-OpenSSH_4.3
We claim version: SSH-2.0-PuTTY_Release_0.60
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1024 07:ce:4c:e5:dd:57:49:d7:a7:c2:b7:0b:be:f7:0d:f4
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "ms104u".
Using keyboard-interactive authentication.
Password:
Access granted
Opened channel for session
Started a shell/command
Pseudo-terminal will not be allocated because stdin is not a terminal.
This system is restricted solely to authorized users for legitimate
business purposes only. The actual or attempted unauthorized access, use, or
modification of this system is strictly prohibited by . Unauthorized
users are subject to Company disciplinary proceedings and/or criminal and
civil penalties under state, federal, or other applicable domestic and
foreign laws. The use of this system may be monitored and recorded for
administrative and security reasons. Anyone accessing this system expressly
consents to such monitoring and is advised that if monitoring reveals
possible evidence of criminal activity, may provide the evidence of
such activity to law enforcement officials. All users must comply with AT&T
company policies regarding the protection of information assets.
IMPORTANT NOTICE: See here for authentication requirements to be enforced:
Permission denied, please try again.
Server sent command exit status 255
Disconnected: All channels closed
Permission denied, please try again.
Received disconnect from 132.201.72.229: 2: Too many authentication failures for
ms104u

where ms104u=user1, 144.160.112.17=ServerA and 132.201.72.229
=ServerB

Can you clarify how you connect through PuTTY though? Do you use a saved session with additional default commands executed on ServerA on login?

---------- Post updated at 04:22 PM ---------- Previous update was at 12:22 PM ----------

Also, can you confirm if you can use key-based authentication for either server, and whether you can log into ServerA without passing straight through to ServerB?

We use putty.exe and feed in the host-name of ServerA. Upon login it propts for the credentials of serverA. As soon as you provide them it automatically takes the same user1 as the login and prompts us for the password for ServerB. So we have to authenticate credentials on both the servers explicitly.

I dont know what are saved sessions. If it is something on ServerA or ServerB then I would need yr help figure it out. If it is something on our windows terminal then I can assure you that there is nothing saved as such.

Ok, that sounds very much like there is a saved session there.Do you not use the PuTTY GUI at all?

I suspect that instead of running

putty.exe <serverA>

you ran

plink <serverA> "hostname"

you would get the hostname of serverB returned after being prompted for the password twice, same as when using putty.

If that is the case, you need to get key based authentication enabled/configured to allow any script the chance to work without a human in attendance.

I never ran this in my life.

 
putty.exe <serverA>
 

I use putty GUI only.

I did not get what did you mean when you said to use plink.

See my output below.

C:\Program Files\PuTTY>plink -v -ssh user1@ServerA hostname

gives me the hostname of serverA and not serverB.

Am i missing something ?

Hi Guys,

I have some good inputs as i made a little progress on this.

Sorry for bieng away for some concerns.

Anyways, below is the progress...

plink user1@ServerA -m local_script.sh -v
 
id
uid=3800(user1) gid=74(sshd) groups=74(sshd)
pwd
/home/ServerA/user1
cat .profile
echo "Connecting to: serverB"
exec /usr/local/bin/serverB
                exit
ls -ltra /usr/local/bin/serverB
-r-xr-xr-x 1 root root 2406 Feb  8 15:37 /usr/local/bin/serverBplink user1@ServerA -m local_script.sh -v

So, now we know how is it switching from ServerA to ServerB automatically.

However, this switch happens when I use putty GUI and does not happen when using plink.

Regardless, I wish to execute a script on ServerB. Can you now help me what needs to be done on ServerA or ServerB to get my teask accomplished ?