我正在尝试连接到 NAT 后面的服务器,以便我可以dev-server
从ssh 进入remote-server
。
我已经设置了从 到 的反向 ssh 隧道,dev-server
如下所示remote-server
,以便搭载连接dev-server->remote-server
:
ssh -R 8022:localhost:22 remote-server
remote-server
指的是以下 .ssh/config 条目dev-server
41 Host remote-server
42 Hostname [some-ip]
43 User [some-user]
44 Port 22
这使得我可以通过 ssh 进入远程服务器,就像ssh remote-server
从 一样dev-server
。
sshd_config 文件remote-server
包含以下行:
31 AllowTcpForwarding yes
32 GatewayPorts yes
我读的是必读内容。
连接建立如下图remote-server
所示:
sudo lsof -i -n | egrep '\<sshd\>' | grep -v ":ssh"
sshd 32724 fxp-trust 9u IPv4 63530 0t0 TCP *:8022 (LISTEN)
sshd 32724 fxp-trust 10u IPv6 63531 0t0 TCP *:8022 (LISTEN)
已安装dev-server
公钥remote-server
。
防火墙remote-server
有以下规则:
sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] OpenSSH ALLOW IN Anywhere
[ 2] Nginx Full ALLOW IN Anywhere
[ 3] 8022 ALLOW IN Anywhere
[ 4] OpenSSH (v6) ALLOW IN Anywhere (v6)
[ 5] Nginx Full (v6) ALLOW IN Anywhere (v6)
[ 6] 8022 (v6) ALLOW IN Anywhere (v6)
为了从 连接remote-server
到 ,dev-server
我做了:
ssh -p8022 localhost
响应如下:
ssh -p8022 localhost -v
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /home/[remote-server]/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to localhost [::1] port 8022.
debug1: Connection established.
debug1: identity file /home/[remote-server]/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/[remote-server]/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
ssh_exchange_identification: read: Connection reset by peer
我不知道为什么。
非常感谢您的帮助。