私は2つのシステムを持っています:インターネット上のUbuntu 20.04サーバーとローカルLAN(NATルーターの背後)のRaspberry Pi 2B(Ubuntu 18.04)です。次のようにRaspberry Piからサーバーへのリバーストンネルを開きます。
ssh -f -N -R 13333:127.0.0.1:22 server
構成ファイルは次のとおりです。
Host server
Hostname <public IP>
User serveruser
IdentityFile /home/piuser/.ssh/serverkey
次に、サーバーで次のコマンドを実行します。
ssh -p13333 -i ~/.ssh/pikey [email protected]
パイキーの場合は、Raspberryでコマンドを実行します(authorized_keysファイルに設定)。
昨日もこの設定を数回試しましたが、今日(約24時間後)トンネルをもう使用できなくなりました。ss
開いているポートが表示され、サーバーでコマンドを実行できますが、応答がありません。コマンドは「停止」されます。
その後、トンネルをシャットダウンし、問題なくリセットしました。問題をさらに解決するために、サーバーから送信されたコマンドに-vvvを追加しました。
ssh -vvv -p13333 -i ~/.ssh/pikey [email protected]
これは、次の時点で接続が中断されたことを示しています。
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020
debug1: Reading configuration data /home/serveruser/.ssh/config
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 127.0.0.1 is address
debug2: ssh_connect_direct
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 13333.
debug1: Connection established.
debug1: identity file /home/serveruser/.ssh/pikey type 0
debug1: identity file /home/serveruser/.ssh/pikey-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
今回はRaspberry Piのウェブサイトで以下を見ました。
$ Warning: remote port forwarding failed for listen port
だから最後の試みはラズベリーを再起動することでした。
最後に、私の質問は:何が間違っているかをどうやって知ることができますか?私は海外にいるときにこの接続に依存しているので、何が間違っていてどのように修正できるかを調べる必要があります
。最初は接続を確立できましたが、いくつかのマイナーな問題のために奇妙な状態になりました。
詳細情報が必要な場合はお知らせください:)
ベストアンサー1
Keepalive機能を有効にする必要があるかもしれません。 .ssh/config では、次の内容が機能する場合があります。
Host *
ServerAliveInterval 300
ServerAliveCountMax 2