I can connect to machine m2 by logging in to m1 first:

[laptop]$ ssh [email protected]
[m1]$ ssh [email protected]
[m2]$ # i'm in!

Both machines use SSH key to log in (not passwords), and it works.

But when I try to automate this with SSH proxying, by using the following config:

Host m1
  ForwardAgent yes
  User ubuntu
  HostName m1.com

Host m2
  ForwardAgent yes
  User ubuntu
  ProxyCommand ssh -q m1 nc m2.com

it fails with:

[laptop]$ ssh m1
[m1]$ # ok, works

[laptop]$ ssh m2
no port[s] to connect to
ssh_exchange_identification: Connection closed by remote host

Why can I connect manually to m2.com, but not in two hops via config? How to fix it?

  • 1
    ProxyCommand ssh -q m1 nc m2.com 22 Sep 2, 2016 at 1:25
  • Oh yes, my stupidity. Please submit as answer so I can accept @FlorinAsăvoaie.
    – user124114
    Sep 2, 2016 at 1:27

1 Answer 1


You forgot to specify the port.

  ProxyCommand ssh -q m1 nc m2.com 22

You must log in to answer this question.

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