2

I connect to server2 in the following way:

home$ ssh server1
server1$ ssh server2
server2$

I also sometimes need to scp this way, which takes some extra time:

home$ ssh server1
server1$ scp server2:file .
server1$ exit
home$ scp server1:file .

Is there a way to do this in one command from home? I'm using public key authentication, but it would be nice if it worked with passwords too.

4 Answers 4

1

I suggest using MobaXterm: you just have to

  • download it from here: http://mobaxterm.mobatek.net/download-home-edition.html
  • Click on "New session" and choose "ssh"
  • Specify your "server2" computername or IP address in the "Remote hostname" field
  • Specify your "server1" computername or IP address in the "SSH bouncing (connect through a gateway ssh server)" field

This will launch a new SSH command, directly to your "server2" computer. On the left of the window, you will also have access to a graphical SFTP file transfer tool which will be also connected directly to "server2".

3
  • That seems like a nice program. I don't always have an X server running on the original server, though.
    – Tim
    Sep 26, 2012 at 14:03
  • OK, but no X server is required: you can choose to disable it in MobaXterm settings if you want.
    – Didier
    Sep 26, 2012 at 17:11
  • Ok, from the name I just assumed that it wasn't a command-line program. I'll check it out.
    – Tim
    Sep 27, 2012 at 5:47
1

You can use SSH tunneling, this way:

ssh -f server1 -L 8888:server2:22 -N

This opens a socket on your local machine, on port 8888 (assuming that no other process is using that port), which tunnels the connection to server2 (assuming SSH is running on port 22 there) through server1. The -N and -f flags tell SSH to fork to the background (you'll have to kill the process if you want to stop the tunnel).

Now you can scp files from server2 just by doing

scp -P 8888 localhost:file
0

home$ server1 "ssh server2"

but when it involves more servers, escaping the command string will be painful.

0

Use SOCKS5 with a Dynamic Tunnel

Create a dynamic ssh tunnel to the first machine. Then, use first connection as a SOCKS5 proxy to get to the second host on the remote network.

This is easy to setup via putty. You can reuse the proxy as many time as you like. Some programs support SOCKS5 directly. Like putty and ssh.

Under Linux, proxychains can be used to proxify programs that don't support SOCKS5 natively. Under Windows, I like Proxycap. It works well with RDP.

To set this up using Putty:

In the first host settings page, under tunnels:

  • create a dynamic tunnel
  • Set the port to 9050.
  • Leave the destination part blank, as it's dynamic.
  • Save your settings. (Done from the session page.)

Then, in the configuration for the second host, under proxy:

  • Select SOCK55.
  • Change the proxy host name to 127.0.0.1
  • Set the port to 9050
  • Then setup the rest of your session as normal
  • Save your settings

To connect to the second host. You'll first have to connect and login to the first host. Then you should be able to connect to the second host via the proxified ssh connection,

You can also do this from the command line with an ssh_config entry: http://www.undeadly.org/cgi?action=article&sid=20070925181947

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.