リモート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ミニUbuntuで生成された項目は必要ありません。これらのアイテムは安全に削除できます。リモートホスト(ミニUbuntu)のTCPポート8377をローカルホスト(macラップトップ)の8377に転送するには、Macラップトップで次のコマンドを実行します。

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

-fnNTTYなしでバックグラウンドでSSH経由で -Lローカルホストにポート転送することは、user@miniMini Ubuntuのユーザーアカウントとホスト名/ IPアドレスです。

その後、ミニUbuntuでnetcatコマンドを実行できます

$ echo "hello from mini" | nc localhost 8377

PS:SSHサービスにアクセスできる限り、ミニUbuntuではファイアウォールを無効にする必要はありません。これは常に基本的にそうです。

おすすめ記事