Quickly SSH into another box over SSH [duplicate]

Solution 1:

You can configure your .ssh/config to provide a tunnel automatically for the targetmachine. For this to work passwordlessly, you need to set up public key authentication in both hosts and agent forwarding in the gateway, though.

Set it up so a connection to targetmachine is proxied through network_gateway:

Host targetmachine
  HostName targetmachine.company.com
  ProxyCommand ssh network_gateway -W %h:%p

Then you can issue:

$ ssh targetmachine

to connect directly. There's more info in the ssh_config(5) manpage.

Solution 2:

SSH will take a command to be executed on the remote machine. For example, to SSH into server2 via server1:

ssh alice@server1 "ssh bob@server2"

Then you will be able to type commands into server2's prompt.

If you want to get even more fancy, you can nest them:

ssh alice@server1 "ssh bob@server2 \"cd myproject && git pull origin master && make all\""

Solution 3:

You could use a script like ssh-chain to make your life easier.

No idea if it supports sftp transfers, though.