6

I can only get to hostB from hostA, and I want to run commands on hostB.

ssh -t $hostA ssh -t $hostB "

   echo 'Hello World!'

   echo 'Test!'

"

At the moment, this will connect to hostA then hostB and the script will pause. As soon as i type exit (from hostB) I return to hostA, the 2 echo commands are printed and then automatically exits from hostA.

How can I run commands on hostB?

2 Answers 2

3

Changing code as using here document and sshpass can do the trick

ssh -T user@$hostA <<EOA
sshpass -p password ssh  -T user@$hostB <<EOB
echo hello 
EOB
EOA
Sign up to request clarification or add additional context in comments.

9 Comments

Before hostA prompts for password I get Pseudo-terminal will not be allocated because stdin is not a terminal. And then I type in password for hostA... Then no password prompt is given for hostB and I immediately get Pseudo-terminal will not be allocated because stdin is not a terminal. Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
@j.con get rid of the -t option. i am not sure but it may work
-t removed on both ssh lines... same effect
@j.con sorry but isnt it -T instead of -t??
@j.con, ...but having a password prompt at all is silly when you could use agent authentication and present the same authentication token to both servers.
|
3

Use the -J option.

ssh $hostB -J $hostA "..."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.