원격 Ubuntu에 대한 SSH RemoteForward 포트가 작동하지 않습니다.

원격 Ubuntu에 대한 SSH RemoteForward 포트가 작동하지 않습니다.

내 로컬 컴퓨터는 Mac이고 mini라는 원격 Ubuntu 20.04.2 LTS 컴퓨터에 연결하고 있습니다.

다음은 mini의 ~/.ssh/config 부분입니다.

Host mini
    User root
    RemoteForward 8377 localhost:8377

이 명령을 사용하여 미니에 SSH로 연결합니다.

/usr/bin/ssh -v mini

다음 명령을 사용하여 방화벽을 비활성화했습니다.

ufw disable

Mini 내부에서는 다음 명령을 실행합니다.

echo "hello from mini" | nc localhost 8377 

로그에 남을 거야

debug1: channel 1: connected to localhost port 8377

전체 로그는 다음과 같습니다.

➜  ~ /usr/bin/ssh -v mini
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/huangyingw/.ssh/config
debug1: /Users/huangyingw/.ssh/config line 1: Applying options for *
debug1: /Users/huangyingw/.ssh/config line 16: Applying options for mini
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to mini port 22.
debug1: Connection established.
debug1: identity file /Users/huangyingw/.ssh/id_rsa type 0
debug1: identity file /Users/huangyingw/.ssh/id_rsa-cert type -1
debug1: identity file /Users/huangyingw/.ssh/id_dsa type 1
debug1: identity file /Users/huangyingw/.ssh/id_dsa-cert type -1
debug1: identity file /Users/huangyingw/.ssh/id_ecdsa type -1
debug1: identity file /Users/huangyingw/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/huangyingw/.ssh/id_ed25519 type -1
debug1: identity file /Users/huangyingw/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/huangyingw/.ssh/id_xmss type -1
debug1: identity file /Users/huangyingw/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to mini:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:jujpF3v9y4BICKUWUni22IcQ4gfZiSmmyvlgtUpoZrA
Warning: Permanently added 'mini,192.168.31.140' (ECDSA) to the list of known hosts.
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Skipping ssh-dss key /Users/huangyingw/.ssh/id_dsa - not in PubkeyAcceptedKeyTypes
debug1: Will attempt key: /Users/huangyingw/.ssh/id_rsa RSA SHA256:EYHtlJ61GJ+TvioA3aQZqXXqomkcUmGK7W6uJmFaqYo
debug1: Will attempt key: /Users/huangyingw/.ssh/id_ecdsa
debug1: Will attempt key: /Users/huangyingw/.ssh/id_ed25519
debug1: Will attempt key: /Users/huangyingw/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/huangyingw/.ssh/id_rsa RSA SHA256:EYHtlJ61GJ+TvioA3aQZqXXqomkcUmGK7W6uJmFaqYo
debug1: Server accepts key: /Users/huangyingw/.ssh/id_rsa RSA SHA256:EYHtlJ61GJ+TvioA3aQZqXXqomkcUmGK7W6uJmFaqYo
debug1: Authentication succeeded (publickey).
Authenticated to mini ([192.168.31.140]:22).
debug1: Remote connections from LOCALHOST:8377 forwarded to local address localhost:8377
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: remote forward success for: listen 8377, connect localhost:8377
debug1: All remote forwarding requests processed
debug1: Sending environment.
debug1: Sending env LC_TERMINAL_VERSION = 3.4.6
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_TERMINAL = iTerm2
debug1: Sending env LC_ALL = en_US.UTF-8
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-55-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

18 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Fri Jun 11 23:08:36 2021 from 192.168.31.147
➜  ~ echo "hello from mini" | nc localhost 8377
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 3 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 8377, originator 127.0.0.1 port 41210
debug1: connect_next: host localhost ([::1]:8377) in progress, fd=11
debug1: channel 1: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connected to localhost port 8377

답변1

~/.ssh/config미니 우분투에서 생성된 항목은 필요하지 않습니다 . 이러한 항목은 안전하게 삭제할 수 있습니다. 원격 호스트(미니 우분투)의 TCP 포트 8377을 로컬 호스트(mac 랩톱)의 8377로 전달하려면 Mac 랩톱에서 다음 명령을 실행합니다.

$ ssh -fnN -L 8377:localhost:8377 user@mini

-fnNTTY 없이 백그라운드로 SSH를 통해 -L로컬 호스트로 포트 전달하는 것은 user@mini미니 우분투의 사용자 계정과 호스트 이름/IP 주소입니다.

그런 다음 미니 우분투에서 netcat 명령을 실행할 수 있습니다

$ echo "hello from mini" | nc localhost 8377

추신: SSH 서비스에 액세스할 수 있는 한 미니 우분투에서는 방화벽을 비활성화할 필요가 없습니다. 이는 항상 기본적으로 그렇습니다.

관련 정보