1

I want to create a script that when I double click runs:

  1. 'ssh -Y server1'
  2. WITHIN server1 run 'ssh -Y server2' (server2 not accessible outside)
  3. I now have the terminal prompt connected to server2 waiting to run commands
2
  • What does "it doesn't work" mean? What happens, what error messages (if any)? Commented Feb 1, 2014 at 9:14
  • It seemed to be stuck in limbo essentially, so no stdin. Commented Feb 1, 2014 at 11:56

2 Answers 2

2

You can use SSH's -W option to achieve this. From the manual:

-W host :port
Requests that standard input and output on the client be forwarded to host on port over the secure channel. Implies -N, -T, ExitOnForward-Failure and ClearAllForwardings. Works with Protocol version 2 only.

You can set this up in your ~/.ssh/config to simplify the process, like so:

Host Server1
  Hostname 200.200.200.1
  Port 2222
  User you
  IdentityFile ~/.ssh/id_rsa

Host Server2
  Hostname 192.168.1.2
  Port 3333
  User you
  IdentityFile ~/.ssh/id_dsa

# Hop to 2
Host Server2
  ProxyCommand ssh -W %h:%p Server1

You then simply ssh Server2 and—provided you have set up your authentication correctly—you will be logged in to Server2.

1
  • Not only does this work, but is a really elegant way to do this. Thank you very much! Commented Feb 1, 2014 at 11:47
2

Furthermore to what Jason said, another less elegant solution where you don't need to change the config and can enter other ssh parameters like -t and -Y:

ssh -tY user@server1 "ssh -tY user@server2; bash -s"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.