Обратный туннель SSH установлен, но подключиться к нему не удалось

Обратный туннель SSH установлен, но подключиться к нему не удалось

У меня дома есть ПК без публичного IP, поэтому я хочу установить обратный туннель на другой сервер с публичным IP, а затем подключиться к домашнему ПК через сервер. Однако я не могу подключиться к своему ПК после установки обратного туннеля, надеюсь, кто-нибудь сможет помочь.

Ниже представлен процесс, который я использовал для установки обратного туннеля к серверу с помощью autossh. Я изменил публичный IP на 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

Далее следует сетевой статус и статус публичного порта на сервере.

[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:                

На GatewayPortsсервере есть yes.

После установки обратного туннеля я подключился с другого компьютера. Но он не смог подключиться. Я понятия не имею, какая часть идет не так.

$ 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

Редактирование 1: Я изменил использование ssh -vv вместо autossh, вот вывод на моем ПК.

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

решение1

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

Ваш второй экземпляр SSH не может установить TCP-подключение к порту прослушивания туннеля. В частности, sshбыл отправлен запрос на TCP-подключение к хосту 123.456.78.90 порт 7020, но он так и не получил ответа.

Самое простое объяснение заключается в том, что есть брандмауэр, блокирующий эти запросы на подключение. Брандмауэр может быть на хосте, на котором вы работаете ssh, или на хосте 123.456.78.90, или на каком-то сетевом устройстве, например маршрутизаторе, между этими двумя хостами.

Это, вероятно, не имеет ничего общего с тем фактом, что порт 7020 хоста 123.456.78.90 является портом прослушивания для туннеля SSH. Я не вижу ничего явно неправильного в экземпляре, sshкоторый создает туннель. Он мог бы работать нормально, если бы вы смогли подключиться к нему.

Связанный контент