简体   繁体   English

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

[英]SSH -L connection successful, but localhost port forwarding not working "channel 3: open failed: connect failed: Connection refused"

My lab runs RStudio on a server.我的实验室在服务器上运行 RStudio。 A couple weeks ago, from my cousin's house, I successfully ssh'd into the server and pulled up the server-side RStudio through my local Firefox browser.几个星期前,在我堂兄的家里,我成功地通过 ssh 连接到服务器,并通过我本地的 Firefox 浏览器打开了服务器端的 RStudio。 Now when I try to access the server RStudio from home (via my own router), it doesn't work.现在,当我尝试从家里(通过我自己的路由器)访问服务器 RStudio 时,它不起作用。 I need help troubleshooting, and I'm guessing it's some problem on the router.我需要帮助进行故障排除,我猜这是路由器上的一些问题。 I'm running Mac OSX 10.6.8.我正在运行 Mac OSX 10.6.8。 No idea what the university server's running, but I don't think it's a server-side problem.不知道大学服务器在运行什么,但我认为这不是服务器端问题。

Here's how it worked the first time I did it, at my cousin's house: first, I VPN into the university.network;这是我第一次在我表弟家做的时候的工作方式:首先,我通过 VPN 连接到 university.network; then I call SSH with port forwarding;然后我通过端口转发拨打 SSH; then I open a Firefox browser, connect to my localhost port, and it opens up RStudio on the server side which I can access through my local browser window.然后我打开一个 Firefox 浏览器,连接到我的本地主机端口,它在服务器端打开了 RStudio,我可以通过我的本地浏览器 window 访问它。

Here's the problem I'm having right now when I try to log-in from my home.network:这是我尝试从我的 home.network 登录时遇到的问题:

I can make the VPN connection successfully.我可以成功建立 VPN 连接。 I can also set up SSH successfully with this command: ssh -v -L 8783:localhost:8783 myacct@server.com我还可以使用以下命令成功设置 SSH: ssh -v -L 8783:localhost:8783 myacct@server.com

Here are the last several lines of the verbose output from the successful ssh command:以下是成功的 ssh 命令中冗长的 output 的最后几行:

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

So I think I'm still succeeding at the VPN and SSH stage (though I don't know why it says my last login was Sep 2 when I've logged in a few times since then).所以我认为我仍然在 VPN 和 SSH 阶段取得成功(尽管我不知道为什么它说我最后一次登录是 9 月 2 日,而从那以后我已经登录了几次)。

Next, I open Firefox, and I type localhost:8783, and instead of getting an RStudio server app through my browser window, I get the following errors:接下来,我打开 Firefox,然后键入 localhost:8783,我没有通过浏览器 window 获取 RStudio 服务器应用程序,而是收到以下错误:

In the Firefox browser window, it says: Server not found, Firefox can't find the server at www.localhost.com, Check the address for typing errors etc.在 Firefox 浏览器 window 中显示:找不到服务器,Firefox 在 www.localhost.com 找不到服务器,检查地址是否输入错误等。

In the terminal window, it says:在终端 window 中,它说:

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

I'm not sure what I've got wrong.我不确定我做错了什么。 I haven't changed anything on my laptop since my last successful connection.自上次成功连接以来,我的笔记本电脑上没有任何更改。 I'm on my own router (instead of my cousin's), so maybe I need to mess with the firewall?我在自己的路由器上(而不是我堂兄的),所以也许我需要弄乱防火墙? I already allowed ports 22 and 8783 to come through the firewall to my laptop (I'm not even sure I needed to do that though).我已经允许端口 22 和 8783 通过防火墙到达我的笔记本电脑(尽管我什至不确定是否需要这样做)。 Help?帮助?

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 .当您连接到本地系统上的端口 8783 时,该连接将通过您的 ssh 链接通过隧道连接到server.com上的 ssh 服务器。 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.从那里,ssh 服务器建立到本地主机端口 8783 的 TCP 连接,并在隧道连接和到隧道目标的连接之间中继数据。

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. “连接被拒绝”错误来自 server.com 上的 ssh 服务器,当它尝试与隧道目标建立 TCP 连接时。 "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.拒绝的最简单解释是,在 server.com 上,没有任何东西在侦听本地主机端口 8783 上的连接。换句话说,您试图通过隧道连接到的服务器软件没有运行,或者它正在运行但它正在运行不监听那个端口。

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最终目的地/目标:169.254.76.1,端口ec2-54-162-180-7.compute-1.amazonaws.com通过具有公共 IP 的中间服务器: ec2-54-162-180-7.compute-1.amazonaws.com

SSH local port forwarding command: SSH本地端口转发命令:

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.问题是什么:目标主机的 8890 端口没有绑定服务。 i had forgotten to start the service.我忘了启动服务。

How did i trouble shoot:我是如何解决问题的:

SSH into bastion host and then do curl. SSH 进入堡垒主机,然后执行 curl。

Hope this helps.希望这可以帮助。

Note: localhost is the hostname for an address using the local (loopback) network interface, and 127.0.0.1 is its IP in theIPv4 network standard (it's ::1 in IPv6).注意: localhost是使用本地(环回)网络接口的地址的主机名, 127.0.0.1是其在IPv4 网络标准中的IP (在 IPv6 中为::1 )。 0.0.0.0 is the IPv4 standard "current network" IP address. 0.0.0.0是 IPv4 标准的“当前网络”IP 地址。

I experienced this error with a Docker setup.我在 Docker 设置中遇到了这个错误。 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 .我在外部服务器上运行了一个 Docker 容器,我(正确地)将其端口映射为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.通过端口转发ssh remote -L 9232:127.0.0.1:9232 ,我希望能够与remote服务器的端口9232通信,就好像它是我自己的本地端口一样。

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.事实证明,Docker 容器在127.0.0.1:9232而不是0.0.0.0:9232上内部运行其进程,因此即使我正确指定了容器的端口映射,它们也没有在正确的接口上被绘制出来。

I used to meet the similar problem because 'localhost' was not available on server when it restarted network service, eg 'ifdown -a' but followed by only 'ifup -eo1'.我曾经遇到过类似的问题,因为当服务器重新启动网络服务时,“localhost”在服务器上不可用,例如“ifdown -a”,但后面只有“ifup -eo1”。 Besides server is not listening to the port, you can also check 'localhost' is available or not.除了服务器没有监听端口,您还可以检查“localhost”是否可用。

ps: Post it just hope someone who has the similar problem may benefit. ps:贴出来只是希望有类似问题的人可以受益。

I had this problem when I wanted to make a vnc connection via a tunnel.当我想通过隧道建立 vnc 连接时,我遇到了这个问题。 But the vncserver was not running.但是 vncserver 没有运行。 I solved it by opening the channel on the remote machine with vncserver :3 .我通过使用vncserver :3打开远程机器上的频道解决了这个问题。

Maybe its too late, but I ran into the same issue, and didn't want to map port by port, so I changed my /etc/ssh/sshd_config file and added: 也许为时已晚,但我遇到了同样的问题,并且不希望逐个端口映射,所以我更改了我的/etc/ssh/sshd_config文件并添加了:

AllowTCPForwarding yes PermitOpen any

Then just restart ssh 然后只需重新启动ssh

Just replace localhost with 127.0.0.1 .只需将localhost替换为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.就我而言,它在 linux 上运行vncserver后工作。

  1. Entered this on linux command line : sudo ssh -L 5901:localhost:5901 -i <ssh_private_key> <username>@<public-IP-address>在 linux 命令行上输入: sudo ssh -L 5901:localhost:5901 -i <ssh_private_key> <username>@<public-IP-address>
  2. Type there vncserver在那里输入vncserver
  3. Go to VncViewer application and connect using localhost:5901转到 VncViewer 应用程序并使用localhost:5901连接

在此处输入图片说明

I had the same error when I was trying to tunnel my mlflow ui over ssh to view remotely.当我尝试通过 ssh 隧道传输我的mlflow ui以远程查看时,我遇到了同样的错误。 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 !对我来说,这是因为我忘记在远程机器上启动 mlflow 应用程序 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在我的情况下,它在检查用户凭据的正确 IP 地址后工作,之前我使用了错误的服务器 IP

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.就我而言,我发现问题出在 jupyter.conf 的配置文件中。

Let's say there are 3 computers named A, B, and C, and A can access B but can't access C;假设有3台电脑A、B、C,A可以访问B但不能访问C; B can access C. B可以访问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.为了从A访问C的jupyter-notebook服务,首先我建立了从A到C通过B的ssh隧道,然后我通过输入localhost:port_number访问jupyter-notebook,然后我得到了错误。

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.最后通过在 jupyter-notebook 的配置文件中写入“c.NotebookApp.ip = '0.0.0.0'”解决了问题,其中 '0.0.0.0' 允许其他 IP 访问。

Hope someone in a similar situation may benefit.希望有类似情况的人可以受益。

这意味着远程虚拟机没有监听当前端口我通过在虚拟机服务器中添加端口解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到服务器:localhost / 127.0.0.1:9000:尝试一次失败。 java.net.ConnectException:连接被拒绝 - Failed to connect to server: localhost/127.0.0.1:9000: try once and fail. java.net.ConnectException: Connection refused 无法连接到 github.com 端口 443:终端 MacBook 中的连接被拒绝 - Failed to connect to github.com port 443: Connection refused in terminal MacBook 运行“远程调试器”时出错:无法打开调试器端口(本地主机:5005):java.net.ConnectException“连接被拒绝(连接被拒绝)” - Error running 'Remote Debugger': Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused (Connection refused)" 连接到本地主机失败 - MacOs 中的 ActiveMQ - Connection to localhost failed - ActiveMQ in MacOs psql:无法连接到服务器:连接被拒绝服务器是否在主机“ localhost”(:: 1)上运行并在端口5432上接受TCP / IP连接? - psql: could not connect to server: Connection refused Is the server running on host “localhost” (::1) and accepting TCP/IP connections on port 5432? Minikube:mount(2) 系统调用失败:连接被拒绝 - Minikube: mount(2) system call failed: Connection refused MacOSX 连接上的 localhost 被拒绝 - localhost on MacOSX connection refused MySQL连接在本地主机上被拒绝 - Mysql connection refused on localhost OSX:Chrome 无法连接到 .localhost-domains。 拒绝连接 - OSX : Chrome cannot connect to .localhost-domains. Connection refused 错误:“通道 3:打开失败:管理禁止:打开失败”在 OS X 屏幕共享上通过 ssh 隧道 - Error: "channel 3: open failed: administratively prohibited: open failed" on OS X Screen Sharing over ssh tunnel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM