1

I am using ssh tunneling to login to system behind gateway. Problem is that I have ssh_alias defined in ~/.ssh/config on gateway server. Where I have key and ip setup. But those alias don't work with nc command. Is there a way to use alias with nc command and use keys setting done on gateway server? So I don't need to download key on local server. Example: GatewayServer

~/.ssh/config
Host test
HostName 192.168.1.10
IdentityFile ~/keys/test
User test

LocalServer ~/.ssh/config

  Host test
  ProxyCommand ssh gateway nc %h %p

Following configuration fails as nc don't know about test.

1 Answer 1

3

What you asking is almost the same as this.

If you don't want to copy key from gateway to local box, the work around is use Method 1 (bash alias) in that post(and below). ssh_config cannot do what you want. I have detail explanation there about the difference between alias and tunnel method, which include ssh_config ProxyCommand.

Method 1

In ~/.bashrc, add following line

alias ssh-test='ssh -t gateway ssh test@test'

In command prompt, just type following

ssh-test

What ssh -t gateway ssh test@test do is almost the same as follow

local# ssh gateway
gateway# ssh test@test

Other than combining the two step in one, it skip opening a shell(csh, bash, etc) on gateway, instead starting a ssh session to test right after authentication.

You don't need ~/.ssh/config on local box BUT keep the one gateway for the test (for key usage).

Adding ForwardAgent yes to gatway .ssh/config

Host test
    HostName 192.168.1.10
    ForwardAgent yes
    IdentityFile ~/keys/test
    User test

Method 2

If you don't want to copy gateway key to local box, but permitted to install your local ssh key into test@test. Then you can use following

local ~/.ssh/config

Host gateway
    User <gateway user>
    HostName <gateway/IP>

Host test
    User test
    Hostname 192.168.1.10
    Port 22
    ProxyCommand ssh gateway nc %h %p
12
  • One more problem. With method one ssh-agent don't work. Every time I need to give password. Is there a solution for that
    – Vivek Goel
    Jan 6, 2013 at 6:47
  • I am not 100%, but try this alias ssh-test='ssh -t -A gateway ssh -A test@test'. If it works I will update the answer too.
    – John Siu
    Jan 6, 2013 at 6:50
  • No that does not work. I have already tried that solution.
    – Vivek Goel
    Jan 6, 2013 at 6:51
  • See if adding ForwardAgent yes to gateway config works. I updated the answer too.
    – John Siu
    Jan 6, 2013 at 6:58
  • that think -A option will do right?
    – Vivek Goel
    Jan 6, 2013 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .