views:

346

answers:

4

I frequently need to ssh into a server, but I can't ssh into it directly while I'm connected to our VPN. Thus, I have to ssh into another server and ssh into it from there. Is there any way that I can write a script and/or shell function for this? I've tried this, buit it gave me an error:

% ssh jason@server2 'ssh jason@server1'
jason@server2's password: 
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-with-mic,password).

(and of course the username and server name have been changed)

+1  A: 

From what I see, the problem is ssh on the middle machine cannot get the standard input. I guess it just want to ask for your password. If that is ture, perhaps you should try to set up ssh key so that you can ssh without password. NOTE: If that success, you better create a new user on the middle machine to hold that key as a security measure.

NawaMan
+4  A: 

It can't show you password prompt. I think all will work with public keys (and, for example, forwarded ssh-agent to eliminate need of entering key passphrases).

wRAR
+3  A: 

SSH connection stacking may help you. Assuming the following layout: Client -> Middleman -> Destination

On Client:

ssh user@Middleman -L 1337:Destination:22

This will allow you to directly SSH into Destination from Client in another session:

On Client:

ssh user@localhost -p 1337

The command runs as if you had typed ssh user@Destination. You can pipe stdin to it as if you were directly connected to it.

brownstone
And if this is not acceptable, there are numerous other means to create a tunnel.
wRAR
+1  A: 

Sounds like you want to set up public key authentication between the middle machine and end machines.

Here are a couple of decent guides to get you started. Good luck.

http://hkn.eecs.berkeley.edu/~dhsu/ssh%5Fpublic%5Fkey%5Fhowto.html

http://pkeck.myweb.uga.edu/ssh/

mobrule