SSH-Reverse-Tunnel hergestellt, aber keine Verbindung möglich

SSH-Reverse-Tunnel hergestellt, aber keine Verbindung möglich

Ich habe zu Hause einen PC ohne öffentliche IP-Adresse. Ich möchte also einen Reverse-Tunnel zu einem anderen Server mit öffentlicher IP-Adresse einrichten und mich dann über den Server mit meinem Heim-PC verbinden. Allerdings kann ich nach dem Einrichten des Reverse-Tunnels keine Verbindung zu meinem PC herstellen. Ich hoffe, jemand kann mir helfen.

Unten ist der Prozess, den ich mit Autossh zum Aufbau eines Reverse-Tunnels zum Server verwendet habe. Ich ändere die öffentliche IP auf 123.456.78.90.

tony@tony-S340MC:~$ autossh -M 6018 -fCNR 0.0.0.0:7020:localhost:22 [email protected]

tony@tony-S340MC:~$ sudo netstat -antp | grep 6018
tcp        0      0 127.0.0.1:6018          0.0.0.0:*               LISTEN      7637/ssh            
tcp6       0      0 ::1:6018                :::*                    LISTEN      7637/ssh    
        
tony@tony-S340MC:~$ netstat -a | grep ssh
tcp        0      0 tony-S340MC:49642       123.456.78.90:ssh      ESTABLISHED

Hier sind der Netzstatus und der öffentliche Portstatus auf dem Server.

[opc@srvagent1 ~]$ sudo netstat -antp | grep 7020
tcp        0      0 0.0.0.0:7020            0.0.0.0:*               LISTEN      24261/sshd: opc     
tcp6       0      0 :::7020                 :::*                    LISTEN      24261/sshd: opc     

[opc@srvagent1 ~]$ sudo firewall-cmd --zone=public --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 6019/tcp 7020/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:                

Das GatewayPortsauf dem Server ist yes.

Nachdem der Reverse-Tunnel eingerichtet war, habe ich mich über einen anderen Computer verbunden. Aber die Verbindung konnte nicht hergestellt werden. Ich habe keine Ahnung, was schiefgelaufen ist.

$ ssh -v -p 7020 [email protected]
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 123.456.78.90 [123.456.78.90] port 7020.
debug1: connect to address 123.456.78.90 port 7020: Connection timed out
ssh: connect to host 123.456.78.90 port 7020: Connection timed out

Edit1: Ich ändere die Verwendung von ssh -vv anstelle von autossh, hier ist die Ausgabe auf meinem PC.

tony@tony-S340MC:~$ ssh -vv -fCNR 0.0.0.0:7020:localhost:22 [email protected]
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname 123.456.78.90 is address
debug2: ssh_connect_direct
debug1: Connecting to 123.456.78.90 [123.456.78.90] port 22.
debug1: Connection established.
debug1: identity file /home/tony/.ssh/id_rsa type 0
debug1: identity file /home/tony/.ssh/id_rsa-cert type -1
debug1: identity file /home/tony/.ssh/id_dsa type -1
debug1: identity file /home/tony/.ssh/id_dsa-cert type -1
debug1: identity file /home/tony/.ssh/id_ecdsa type -1
debug1: identity file /home/tony/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/tony/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/tony/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/tony/.ssh/id_ed25519 type -1
debug1: identity file /home/tony/.ssh/id_ed25519-cert type -1
debug1: identity file /home/tony/.ssh/id_ed25519_sk type -1
debug1: identity file /home/tony/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/tony/.ssh/id_xmss type -1
debug1: identity file /home/tony/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 123.456.78.90:22 as 'opc'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: [email protected],zlib,none
debug2: compression stoc: [email protected],zlib,none
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: [email protected]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: [email protected]
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:XxJkoHSa4aJEXoL9Ir5i0lSDBM0TA6E2tx6J6LQd/BQ
debug1: Host '123.456.78.90' is known and matches the ECDSA host key.
debug1: Found key in /home/tony/.ssh/known_hosts:5
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/tony/.ssh/id_rsa RSA SHA256:IbUI2q2QVZuuRT6rvvdAHciGlzVBRZqPKdCS2EaW3Mc agent
debug1: Will attempt key: /home/tony/.ssh/id_dsa 
debug1: Will attempt key: /home/tony/.ssh/id_ecdsa 
debug1: Will attempt key: /home/tony/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/tony/.ssh/id_ed25519 
debug1: Will attempt key: /home/tony/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/tony/.ssh/id_xmss 
debug2: pubkey_prepare: done
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)


debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)


debug2: we did not send a packet, disable method
debug1: Next authentication method: publickey
debug1: Offering public key: /home/tony/.ssh/id_rsa RSA SHA256:IbUI2q2QVZuuRT6rvvdAHciGlzVBRZqPKdCS2EaW3Mc agent
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: /home/tony/.ssh/id_rsa RSA SHA256:IbUI2q2QVZuuRT6rvvdAHciGlzVBRZqPKdCS2EaW3Mc agent
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to 123.456.78.90 ([123.456.78.90]:22).
debug1: Remote connections from 0.0.0.0:7020 forwarded to local address localhost:22
debug2: fd 3 setting TCP_NODELAY
debug1: Requesting [email protected]
debug1: forking to background
debug1: Entering interactive session.
debug1: pledge: network

tony@tony-S340MC:~$ debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: remote forward success for: listen 0.0.0.0:7020, connect localhost:22
debug1: All remote forwarding requests processed

Antwort1

debug1: Connecting to 123.456.78.90 [123.456.78.90] port 7020.
debug1: connect to address 123.456.78.90 port 7020: Connection timed out
ssh: connect to host 123.456.78.90 port 7020: Connection timed out

Ihre zweite SSH-Instanz kann keine TCP-Verbindung zum Abhörport des Tunnels herstellen. Konkret sshwurde eine TCP-Verbindungsanforderung an den Host 123.456.78.90, Port 7020, gesendet und nie eine Antwort erhalten.

Die einfachste Erklärung ist, dass eine Firewall diese Verbindungsanfragen blockiert. Die Firewall kann sich auf dem Host befinden, auf dem Sie arbeiten ssh, oder auf dem Host 123.456.78.90, oder sie kann sich auf einem Netzwerkgerät wie einem Router zwischen diesen beiden Hosts befinden.

Dies hat wahrscheinlich nichts damit zu tun, dass Host 123.456.78.90 Port 7020 der Abhörport für einen SSH-Tunnel ist. Ich sehe nichts offensichtlich Falsches an der sshInstanz, die den Tunnel erstellt. Es könnte einwandfrei funktionieren, wenn Sie eine Verbindung dazu herstellen könnten.

verwandte Informationen