Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to connect from my computer to a remote computer using a middle server(u port forwarding). I run this command on remote computer:

ssh -R 9300:localhost:22 user@middleserver

and this one on my system:

ssh remoteuser@middelserver -p 9300

But I get this error on my system:

ssh_exchange_identification: Connection closed by remote host

this is the log of remote computer:

debug1: client_request_forwarded_tcpip: listen localhost port 9309, originator xxx.xxx.xx.xx port 21470
debug2: fd 7 setting O_NONBLOCK
debug1: connect_next: host localhost ([::1]:22) in progress, fd=7
debug2: fd 7 setting TCP_NODELAY
debug3: fd 7 is O_NONBLOCK
debug3: fd 7 is O_NONBLOCK
debug1: channel 1: new [xx.xx.xx.xx]
debug1: confirm forwarded-tcpip
debug3: channel 1: waiting for connection
debug1: channel 1: connection failed: Connection refused
debug2: fd 8 setting O_NONBLOCK
debug1: connect_next: host localhost ([127.0.0.1]:22) in progress, fd=8
debug2: fd 8 setting TCP_NODELAY
debug3: channel 1: waiting for connection
debug1: channel 1: connection failed: Connection refused
connect_to localhost port 22: failed.
debug2: channel 1: zombie
debug2: channel 1: garbage collecting
debug1: channel 1: free: xxx.xxx.xxx.xxx, nchannels 2
debug3: channel 1: status: The following connections are open:
  #0 client-session (t4 r2 i0/0 o0/0 fd 4/5 cc -1)

What's the problem?

share|improve this question

1 Answer

If the sshd on your middle server has not got the GatewayPorts configuration option set to yes (default is no view man 5 sshd_options) then you will have to specify a bind address on your forwarding:

ssh -R *:9300:localhost:22 user@middleserver

(you can specify the IP address of your local machine to make that more restrictive).

Without that only the loopback device is forwarded on middleserver.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.