SSH-L 连接成功,但本地主机端口转发无效“通道3: 打开失败: 连接失败: 连接被拒绝”

我的实验室在服务器上运行 RStudio。几个星期前,在我表弟家里,我成功地 ssh 进入了服务器,并通过我本地的 Firefox 浏览器调出了服务器端的 RStudio。现在,当我尝试从家里(通过我自己的路由器)访问服务器 RStudio 时,它无法工作。我需要帮忙解决问题,我猜是路由器出了问题。我正在运行 Mac OSX 10.6.8。不知道大学的服务器在运行什么但我觉得不是服务器端的问题。

我第一次这么做的时候是这样的,在我表兄的家里: 首先,我用 VPN 连接大学网络; 然后我用端口转发调用 SSH; 然后我打开一个 Firefox 浏览器,连接到我的本地主机端口,它在服务器端打开 RStudio,我可以通过我的本地浏览器窗口访问它。

当我尝试从我的家庭网络登录的时候,我遇到了一个问题:

我可以成功地建立 VPN 连接,也可以用以下命令成功地建立 SSH: ssh -v -L 8783:localhost:8783 myacct@server.com

下面是成功的 ssh 命令的详细输出的最后几行:

debug1: Authentication succeeded (password).
debug1: Local connections to LOCALHOST:8783 forwarded to remote address localhost:8783
debug1: Local forwarding listening on 127.0.0.1 port 8783.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on ::1 port 8783.
debug1: channel 1: new [port listener]
debug1: channel 2: new [client-session]
debug1: Entering interactive session.
Last login: Mon Sep  2 04:02:40 2013 from vpnipaddress

所以我认为我仍然在 VPN 和 SSH 阶段取得了成功(尽管我不知道为什么它说我最后一次登录是在9月2日,而我在那之后已经登录了几次)。

接下来,我打开 Firefox,输入 localhost: 8783,不是通过浏览器窗口获取 RStudio 服务器应用程序,而是得到以下错误:

在火狐浏览器窗口中,显示: 服务器未找到,火狐找不到 www.localhost.com 服务器,检查地址是否输入错误等。

在终端窗口,它说:

debug1: Connection to port 8783 forwarding to localhost port 8783 requested.
debug1: channel 3: new [direct-tcpip]
channel 3: open failed: connect failed: Connection refused
debug1: channel 3: free: direct-tcpip: listening port 8783 for localhost port 8783, connect from 127.0.0.1 port 50420, nchannels 4

我不知道我哪里搞错了。自从上次成功连接后,我的笔记本电脑上没有任何改动。我使用的是自己的路由器(而不是我表弟的) ,所以也许我需要破坏防火墙?我已经允许端口22和8783通过防火墙进入我的笔记本电脑(我甚至不确定我是否需要这样做)。帮忙?

211179 次浏览
ssh -v -L 8783:localhost:8783 myacct@server.com
...
channel 3: open failed: connect failed: Connection refused

When you connect to port 8783 on your local system, that connection is tunneled through your ssh link to the ssh server on server.com. From there, the ssh server makes TCP connection to localhost port 8783 and relays data between the tunneled connection and the connection to target of the tunnel.

The "connection refused" error is coming from the ssh server on server.com when it tries to make the TCP connection to the target of the tunnel. "Connection refused" means that a connection attempt was rejected. The simplest explanation for the rejection is that, on server.com, there's nothing listening for connections on localhost port 8783. In other words, the server software that you were trying to tunnel to isn't running, or else it is running but it's not listening on that port.

Posting this to help someone.

Symptom:

channel 2: open failed: connect failed: Connection refused
debug1: channel 2: free: direct-tcpip:
listening port 8890 for 169.254.76.1 port 8890,
connect from ::1 port 52337 to ::1 port 8890, nchannels 8

My scenario; i had to use the remote server as a bastion host to connect elsewhere. Final Destination/Target: 169.254.76.1, port 8890. Through intermediary server with public ip: ec2-54-162-180-7.compute-1.amazonaws.com

SSH local port forwarding command:

ssh -i ~/keys/dev.tst -vnNT -L :8890:169.254.76.1:8890
glue@ec2-54-162-180-7.compute-1.amazonaws.com

What the problem was: There was no service bound on port 8890 in the target host. i had forgotten to start the service.

How did i trouble shoot:

SSH into bastion host and then do curl.

Hope this helps.

I used to meet the similar problem because 'localhost' was not available on server when it restarted network service, e.g. 'ifdown -a' but followed by only 'ifup -eo1'. Besides server is not listening to the port, you can also check 'localhost' is available or not.

ps: Post it just hope someone who has the similar problem may benefit.

I had this problem when I wanted to make a vnc connection via a tunnel. But the vncserver was not running. I solved it by opening the channel on the remote machine with vncserver :3.

Note: localhost is the hostname for an address using the local (loopback) network interface, and 127.0.0.1 is its IP in the IPv4 network standard (it's ::1 in IPv6). 0.0.0.0 is the IPv4 standard "current network" IP address.

I experienced this error with a Docker setup. I had a Docker container running on an external server, and I'd (correctly) mapped its ports out as 127.0.0.1:9232:9232. By port-forwarding ssh remote -L 9232:127.0.0.1:9232, I'd expected to be able to communicate with the remote server's port 9232 as if it were my own local port.

It turned out that the Docker container was internally running its process on 127.0.0.1:9232 rather than 0.0.0.0:9232, and so even though I'd specified the container's port-mappings correctly, they weren't on the correct interface for being mapped out.

This means the remote vm is not listening to current port i solved this by adding the port in the vm server

Just replace localhost with 127.0.0.1.

(The answer is based on answers of other people on this page.)

In my case, it worked after running the vncserver on linux.

  1. Entered this on linux command line : sudo ssh -L 5901:localhost:5901 -i <ssh_private_key> <username>@<public-IP-address>
  2. Type there vncserver
  3. Go to VncViewer application and connect using localhost:5901

enter image description here

I had the same error when I was trying to tunnel my mlflow ui over ssh to view remotely. As mentioned in the first answer, the error arises because nothing on the server is listening for the port. This, for me, is because I forgot to start the mlflow app on my remote machine! So in general – make sure the app you're trying to access remotely is running.

In my case, it worked after checking the correct IP address of the user credentials previously I was using the wrong IP of the server

ssh -NfL 127.0.0.1:8084:127.0.0.1:8888 user@ip_address_of_server

after correcting it, works fine.

Encountered with the same error. In my case, I found the problem was in the config file of jupyter.

Let's say there are 3 computers named A, B, and C, and A can access B but can't access C; B can access C.

To access jupyter-notebook service of C from A, first I established ssh tunnel from A to C through B, then I access jupyter-notebook by typing localhost:port_number, then I got the error.

Finally the problem was solved by writing the "c.NotebookApp.ip = '0.0.0.0'" in jupyter-notebook's config file, where '0.0.0.0' allows the access of other IPs.

Hope someone in a similar situation may benefit.