目的: 使用反向隧道(类似 ngrok 的服务)将在本地机器上运行的 Web 应用程序暴露给外界。
我有一个在 Azure 上运行的 Windows 10 Pro VM。我在那里安装了 OpenSSH 服务器,并使用本地端口转发和动态端口转发(袜子代理)对其进行了测试。两者都工作正常。
但我似乎没有让反向隧道工作。
这是我在本地机器上使用的命令:
ssh -R 5002:localhost:5002 xx.xx.xx.xxx
其中,xx.xx.xx.xxx 是 Azure 上 Win10 VM 的公共 IP。5002 是我的 Web 应用程序在本地计算机上运行的端口,我还想为 Azure VM 保留相同的端口。
上面的命令提示我输入密码,输入后在终端上显示如下提示,这可能表示连接成功。
me@VMW10Pro C:\Users\me>
但是当我尝试访问我的本地运行的 Web 应用程序时,如下所示,没有任何反应:
https://xx.xx.xx.xxx:5002/myapp
我也试过了,但没有运气:
http://xx.xx.xx.xxx:5002/myapp
这是sshd_config
Azure VM 上的文件。我所做的唯一更改是设置GatewayPorts
为yes
:
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
#AllowAgentForwarding yes
#AllowTcpForwarding yes
GatewayPorts yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp sftp-server.exe
# Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
sshd_config
我本地机器上的文件也和上面一样,GatewayPorts
设置为yes
.
请注意:我不是网络方面的专家。还有其他教程和操作方法可用于对 Linux VM 执行相同操作。但我只想利用现有的 Windows VM。
任何帮助将非常感激。