8/5/2016 - 12:59 PM

From http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/ http://www.unixwiz.net/techtips/ssh-agent-forwarding.html


part1 - command

in .ssh/config:

Host test-1pauth-cassandra
        User ubuntu
        ProxyCommand ssh nilseu.padilha@bastion.test.oneplatform.build -W %h:%p
        ForwardAgent yes


 $ ssh -f -N -L 9042: ubuntu@test-1pauth-cassandra

Host test-bastion
        HostName bastion.test.oneplatform.build
        User nilseu.padilha

Host test-gatling
        User ec2-user
        ProxyCommand  ssh nilseu.padilha@bastion.test.oneplatform.build nc %h %p

Host test-*
        PubkeyAuthentication yes
        ForwardAgent yes

Host *
        ServerAliveInterval 30
        ServerAliveCountMax 120
        PubkeyAuthentication yes
        ForwardAgent no
eval `ssh-agent`
ssh-add ~/.ssh/KP_developer.pem
ssh-add ~/.ssh/KP_infrastructure.pem
ssh-add ~/.ssh/main-access.pem

# ssh -A nilseu.padilha@bastion.dev.oneplatform.build -i /c/dev/keys/tr_key_rsa


ssh-agent -k

source: http://superuser.com/questions/456438/how-do-i-scp-a-file-through-an-intermediate-server

This has already been answered best here.

To summarize: put the following in ~/.ssh/config

Host target.machine
  User          targetuser
  HostName      target.machine
  ProxyCommand  ssh proxyuser@proxy.machine nc %h %p 2> /dev/null

and then simply scp to target.machine any time you want to proxy via proxy.machine!

Also works for ssh, so will save you time ssh-ing to the target machine too.

Credit should go to user24925 who answered this in 2011.

$ ssh -f -N -L 9906: coolio@database.example.com
# -f puts ssh in background
# -N makes it not execute a remote command

# contents of $HOME/.ssh/config
Host tunnel
    HostName database.example.com
    IdentityFile ~/.ssh/coolio.example.key
    LocalForward 9906
    User coolio
$ ssh -f -N tunnel
# contents of $HOME/.ssh/config
Host devHost github-project1
    User git
    HostName github.com
    IdentityFile ~/.ssh/github.project1.key</p>
Host github-org
    User git
    HostName github.com
    IdentityFile ~/.ssh/github.org.key</p>
Host github.com
    User git
    IdentityFile ~/.ssh/github.key
$ git clone git@github-org:orgname/some_repository.git
# contents of $HOME/.ssh/config
Host dev
    HostName dev.example.com
    Port 22000
    User fooey
# private public 
Host dev
    HostName dev.example.com
    Port 22000
    User fooey