SSH転送ポートにアクセスできません。

SSH転送ポートにアクセスできません。

2台のサーバーがあります。サーバーAにはパブリックIPアドレス(43.24.24.29)があります。サーバーBにはプライベートIPアドレス(10.10.10.1)があります。

サーバーAはパブリックIPアドレス(一部の固定パスを使用)を介してサーバーBに接続できるため、サーバーAはサーバーBに接続できます。

別のPCを使ってサーバーBに接続したいsshので、サーバーAにSSHポートを追加しました。

[ldl@ServerA ~]$ sudo ssh -N -f -L 222:43.24.24.29:22 [email protected]

これでサーバーから起動します。

[ldl@ ServerA ~]$ ps -ef | grep ssh
root      10228      1  0 4th mon 13 ?       00:03:19 /usr/sbin/sshd -D
root      91304  10228  0 04:46 ?        00:00:01 sshd: ldl [priv]
ldl       91308  91304  0 04:46 ?        00:00:00 sshd: ldl@pts/0
root     100491      1  0 10:57 ?        00:00:00 ssh -N -f -L 222:43.24.24.29:22 [email protected]
root     100501  10228  1 10:57 ?        00:00:00 sshd: root [priv]
sshd     100502 100501  0 10:57 ?        00:00:00 sshd: root [net]
ldl      100505  91309  0 10:57 pts/0    00:00:00 grep --color=auto ssh
[ldl@ServerA ~]$ netstat -tlnp | grep 222
(No info could be read for "-p": geteuid()=1000 but you should be root.)
tcp        0      0 127.0.0.1:222           0.0.0.0:*               LISTEN      -                   
tcp6       0      0 ::1:222                 :::*                    LISTEN      -                   

しかし、私のローカルPCからサーバーAのポート222にSSHを試みると、次の「接続が拒否されました」エラーが発生します。

aircrafts-MBP:~ ldl$ ssh [email protected] -p 222 -vvv
OpenSSH_7.7p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: resolve_canonicalize: hostname 43.24.24.29 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 43.24.24.29 [43.24.24.29] port 222.
debug1: connect to address 43.24.24.29 port 222: Connection refused
ssh: connect to host 43.24.24.29 port 222: Connection refused

これが43.24.24.29私のデモIPアドレスです。


編集-01

私は次のコマンドを試しました。

ssh -N -f -L 2222:localhost:22 [email protected]

接続すると、次のエラーが発生しますssh_exchange_identification: read: Connection reset by peer。詳しく説明してください:

aircrafts-MBP:~ ldl$ ssh 43.24.24.29 -p2222  -vvv
OpenSSH_7.7p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: resolve_canonicalize: hostname 43.24.24.29 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 43.24.24.29 [43.24.24.29] port 2222.
debug1: Connection established.
debug1: identity file /Users/ldl/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/ldl/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
ssh_exchange_identification: read: Connection reset by peer

ベストアンサー1

リモートホストに転送する場合は、リモートポート転送に次のコマンドを使用する必要があります。-アル字型-Lの代わりに引数を使用すると、トンネルはローカル(localhost)に設定されます。それ以外の場合は、作成するすべてのトンネルがlocalhostに設定されます。また、GatewayPorts yesファイル/etc/sshd_configにパラメータを設定したことを確認する必要があります。10.10.10.1それ以外の場合は渡されません。

これを試す前に、GatewayPortsパラメーターがyesであることを確認してください。

ssh -N -f [email protected] -R 222:43.24.24.29:22

その後(編集):

ssh [email protected] -p 222

おすすめ記事