Ssh tunnelling via intermediate host

I recently needed to copy files using scp, while not able to copy directly to the target host.  I had to use an intermediate firewall host.  There is a few ways to get this done and most requires netcat (nc) on the intermediate host for copying.

Keep in mind using -t for just a ssh shell connection will work:

$ ssh -t ssh admin@

If needing scp below is a way to get this done when netcat is not a possibility.

In a new terminal do this (command won't return a prompt and leave the terminal open):

$ ssh -L 2000: -N

In a new terminal ssh as follow:

$ ssh -p 2000 admin@localhost

Scp as follow:

$ scp -P 2000 testfile admin@localhost:/tmp

Sftp also possible:

$ sftp -P 2000 admin@localhost

Update 1:  Above will work fine but you can also consider the following to make things more transparent.

$ vi .ssh/config
Host *
 ServerAliveCountMax 4
 #Note default is 3
 ServerAliveInterval 15
 #Note default is 0
host work-tunnel
 port 22

 # SSH Server
 LocalForward localhost:2000
 user rrosso

# Aliases as follow
 hostname localhost
 port 2000
 user admin

Then run the tunnel connect first (use ssh -v while still troubleshooting):

$ ssh work-tunnel

Leave above terminal open to leave tunnel going. And now you can run commands in new terminals with syntax as if no tunnel required.

$ scp testfile
$ ssh

That should do it for a ssh shells.

Example for other ports:

Note you can do a lot of other ports also in similar fashion.  Here is an example you could play with.

Host workTunnel
    Port 5001
    # SMTP Server
    LocalForward localhost:2525
    # Corporate Wiki.  Using IP address to show that you can.
    LocalForward localhost:8080
    # IMAP Mail Server
    LocalForward locahost:1430
    # Subversion Server
    LocalForward locahost:2222
    # NFS Server
    LocalForward locahost:2049
    # SMB/CIFS Server
    LocalForward locahost:3020
    # SSH Server
    LocalForward locahost:2220
    # VNC Server
    LocalForward locahost:5900

### Hostname aliases ###
### These allow you to mimic hostnames as they appear at work.
### Note that you don't need to use a FQDN; you can use a short name.
    HostName localhost
    Port 2525
    HostName localhost
    Port 8080
    HostName localhost
    Port 1430
    HostName localhost
    Port 2222
    HostName localhost
    Port 2049
    HostName localhost
    Port 3020
    HostName localhost
    Port 2220
    HostName localhost
    Port 5900


Bio Info for Riaan