[Linux][自分用メモ] 「packet_write_wait: Connection to <IP address> port 22: Broken pipe」の対応方法

AIX、UNIX、Linux

ARMなSingle Board Computerを弄っていると、そのボードの非力さから時々以下のようなエラーになることがあります。

packet_write_wait: Connection to <IP Address> port 22: Broken pipe

SSH接続をしながら色々と作業していると、CPUが非力ゆえにsshdが接続を維持できなくて上記のようなエラーで接続断が発生します。

というわけで対応するための設定をしておきます。

Webの情報

ちなみにこの手の記事は多くみられます。

SSHサーバ側

SSHサーバ側は以下のパラメータが有効のようです。

ClientAliveInterval 30
ClientAliveCountMax 5

上記の場合は、接続クライアントに対して30秒間隔で5回まで応答確認を行います。これを超えたときに接続タイムアウトになります。

あと、sshdサービスの再起動をしておきましょう。

ClientAliveCountMax
Sets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from TCPKeepAlive. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive. The default value is 3. If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds

ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.

https://man.openbsd.org/sshd_config

SSHクライアント側

クライアント側は以下の設定パラメータがあります。

ServerAliveInterval 15
ServerAliveCountMax 10

15秒ごとに10回応答確認をサーバに送り、 それを超えた場合にタイムアウトになります。


ServerAliveCountMax
Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive. The default value is 3. If, for example, ServerAliveInterval (see below) is set to 15 and ServerAliveCountMax is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 seconds

ServerAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.

https://man.openbsd.org/ssh_config

SSHはほぼ必須な手順ですが、設定についてはあんまり分かっていませんでした。他にもKeepAliveとかも良く使われますが、もうちょっとパラメータについて勉強しておいた方が良いかな、と改めて思いました。

この記事を書いた人

kometchtech

うつ病を患いながら、IT業界の末席にいるおっさんエンジニア。科学計算をしたことがないのに、HPC分野にお邪魔している。興味のある分野で学習したことをblogにまとめつつ、うつ病の経過症状のメモも置いておく日々。じつはRouterboard User Group JPの中の人でもある。 Amazon欲しいものリスト / Arm板を恵んでくれる人募集中

kometchtechをフォローする
いつか、そのとき、あの場所で。rev.2
タイトルとURLをコピーしました