LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ssh me@host1 'ssh me@host2' (https://www.linuxquestions.org/questions/linux-software-2/ssh-me%40host1-ssh-me%40host2-902249/)

lothario 09-10-2011 02:32 AM

ssh me@host1 'ssh me@host2'
 
If I want to execute the "who" command on the host "monkey" then I can simply do this.
Code:

ssh  bob@monkey  'who'
bob@monkey's password:
bob      pts/0        2011-09-09 21:24 (gorilla)
bob      tty7        2011-08-14 01:15 (:0)

But if I try ssh on to the host "donkey" via the host "monkey" it does not work.
Code:

ssh  bob@monkey  'ssh  bob@donkey'
bob@monkey's password:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).

Can this be done?

My passwords on monkey and donkey are different.
It did not even ask me to enter my password for the host "donkey".

corp769 09-10-2011 02:34 AM

Hello,

Can I ask why you would want to do this?

Cheers,

Josh

lothario 09-10-2011 02:55 AM

Once I am logged on monkey, from there I frequently need to logon to several other hosts like donkey.
So
ssh + password + password + exit
can be faster than
ssh + password + ssh + password + exit + exit
besides, the actual hostnames and options are quite long so a simple script called donkey
donkey + password + password + exit
would be efficient and faster, for me.

corp769 09-10-2011 03:06 AM

Maybe you could write a script that would pass the passwords to the ssh commands, and use arguments for whatever commands that you need to be ran?

druuna 09-10-2011 03:15 AM

Hi,

I do believe that the lack of a (pseudo)terminal is the reason why the initial command doesn't work. Give this a try:
Code:

ssh -t bob@monkey 'ssh bob@donkey'
the -t option forces a (pseudo)terminal.

Hope this helps.

lothario 09-10-2011 03:27 AM

Quote:

Originally Posted by druuna (Post 4467971)
Hi,

I do believe that the lack of a (pseudo)terminal is the reason why the initial command doesn't work. Give this a try:
Code:

ssh -t bob@monkey 'ssh bob@donkey'
the -t option forces a (pseudo)terminal.

Hope this helps.

That was perfect!
Thank you.

druuna 09-10-2011 03:28 AM

You're welcome :)

corp769 09-10-2011 06:01 PM

Ahh, I forgot about that. Thanks for that.... I haven't used linux in a bit because my laptop died....


All times are GMT -5. The time now is 10:28 PM.